//disjointed rollover function starting point
var currentfeat= 1;
var playStatus= true;
function overLi(color,object){
	//make a variable and assign the hovered id to it
	var elid = $(object).attr('id');
	var featnum= parseInt(elid.substr(8,1));
	currentfeat= featnum;
	var next= featnum+1;
	var prev= featnum-1;
	var total= $("#featureClick li").length;
	if(next > total) next= 1;
	if(prev < 1) prev= total;
	
	//$("#feature-prev").html("<a href=\"javascript:overLi('#576B8A',$('#feature-"+prev+"'));\">&lt; </a>");
	//$("#feature-next").html("<a href=\"javascript:overLi('#576B8A',$('#feature-"+next+"'));\"> &gt;</a>");
	//$(object).prev("li").css({'border-bottom':'1px dotted ' + color });
	
	//if it's not currently on the selected list item, then switch
	if($("#" + elid + " a").attr("class") != "cur"){
		autoTransition();
		$("#featureClick a").removeClass("cur");
		$("#" + elid + " a").addClass("cur");
		//hide the image currently there
		for(var i= 0;i<=total;i++){
			//alert(i+" "+total);
			if(i==total){
				//fade in the image with the same id as the selected button
				$("#" + elid + "a").stop().css({'display':'block','opacity':'0'}).animate({'opacity' : '1'},'slow');
				$("#" + elid + "b").stop().css({'display':'block','opacity':'0'}).animate({'opacity' : '1'},'slow');
			}else{
				$("#feature-"+(i+1)+"a").stop().hide();
				$("#feature-"+(i+1)+"b").stop().hide();
			}
		}
	}		
}

function offLi(color, object,curSelected){
	var elid = $(object).attr('id');
	
	if(curSelected != ''){
		$("#"+curSelected + " a").addClass("cur");
	}
	
//	if(elid != curSelected){
//		$("#" + elid + " a").removeClass("cur");
//	}
	
	//$(object).prev("li").css({'border-bottom':'1px dotted ' + color });
	
	/*if(elid != "featureHor-5" && elid != "featureVer-5"){
		$(object).css({'border-bottom':'1px dotted ' + color });
	}*/
}
		
var t;
function autoTransition(){
	//playStatus= false; //comment out if using autoTransitioning
	//$("#feature_options_loader").stop().css({'width':'0%'});
	clearTimeout(t);
	if(playStatus){
		t= setTimeout("feature_go()",4000);  //4 seconds= 4000 milliseconds
		// $("#feature_options_loader").animate({
		// 	'width': '99%'
		// },3000,function(){
		// 	feature_go();			
		// });
	}
}
function pause(){
	if(playStatus){
		playStatus = false;
		$('#play_pause img').attr('src','/themes/cc_main/images/rotating_features/play.gif');
	}else{
		playStatus = true;
		$('#play_pause img').attr('src','/themes/cc_main/images/rotating_features/pause.gif');
	}	
	autoTransition();
}
function feature_go(){
	var next= currentfeat+1;
	var total= $("div#featureClick li").length;
	if(next > total) next= 1;
	//alert(next+'/'+total);
	var nextobj= $("#feature-"+next);
	overLi("#576B8A", nextobj);

	//autoTransition();
}