first
$("#rightPanel ul li.selectedBgColor")
.toggleClass("selectedBgColor")
.toggleClass("defaultBgColor");
then:
if($(this).parent().hasClass("selectedBgColor")){
}
else if($(this).parent().hasClass("defaultBgColor")){
$(this).parent().toggleClass("defaultBgColor");
$(this).parent().toggleClass("selectedBgColor");
var elementID = $(this).attr("value");
var pos = $("#"+elementID).offset().top;
$("html, body").animate({scrollTop:pos-100},500);
return false;
}