// controls the highlights scroller on the homepage.
var j = jQuery.noConflict();

j(document).ready(function(){
	var isHoveredFlag1 = "no";
	var isFading = "no";
	j("#highlights li").hide();
	j("#highlights li").first().addClass("first").addClass("visible").show();
	j("#highlights li").last().addClass("last");
	
	
	
	  var total = j("#highlights li").length;
      var count = 1;
	  var index = 10;
	

		  
	  	j("#highlights").hover(function(){
									   isHoveredFlag1 = "yes";
	
									   },function(){
									   isHoveredFlag1 = "no";
									   if(isFading == "no")
									   	{ //make sure animations dont repeat
										fade();
										}
									   } //end hoverOut
									   ); //end hightlights hover
		
	
		function loop(){
			j("#highlights").delay(3000).queue(function(next){
				isFading = "no";
				if (isHoveredFlag1 == "no"){
					fade();
				};
				next();
});
	
		}; //end loop carosel
		
		
		function fade(){
					isFading = "yes";
					j("#highlights li:nth-child("+count+") h2").animate({left: "-490px" }, 1000 );
			        if (count == total) {count = 1;}
					else
						{
						count++;	
						};
					index++;
					
					j("#highlights li:nth-child("+count+") h2").css('left', "480px").animate({left: "-70px" }, 1000 );

        			j("#highlights li:nth-child("+count+")").css('z-index',index).fadeIn(1500, function () {
					
					j("li.visible").hide().removeClass("visible");
					j("#highlights li:nth-child("+count+")").addClass("visible");
           			loop();
         			});//fadeIn Complete
			
		};
		
	loop();
}); //end document ready
