// JavaScript Document

// initalize
var panelcount = 0;		// Which panl is being displayed
var lastPanel = 3;		// How may panels are thre in total
var backToButton = 0;	// Which feature button to go back to after rollover
var featureTimer;		// Timer id

$(document).ready(function(){
	/* CONFIG */
	$(".feature:first").css( {"display":"block"} );
	featureTimer = setTimeout ( "nextpanel()", 6000 );
	$("#fButton_0").css( {"background": "url(wp-content/plugins/cpfeatures/images/btn0over.png) no-repeat"  } );
	/* CONFIG */
	
	// Carousel Button rollover
	$(".featureB").mouseover(function() {
		
		featureLength = $(".featureB").length;
		for (x=0;x<featureLength;x++) {
			imgNum = "url(wp-content/plugins/cpfeatures/images/btn"+x+"over.png) no-repeat";
			idNum = whichId = "#" + "fButton_" + x;
			$(idNum).css( {"background": imgNum } );
		}
		
		whichId = parseInt( $(this).attr("id").substring( $(this).attr("id").lastIndexOf("_")+1 , $(this).attr("id").length) );
		whichImg = "url(wp-content/plugins/cpfeatures/images/btn"+whichId+"over.png) no-repeat";
		$(this).css( {"background": whichImg } );
		
		panelcount = whichId;
		$( ".feature" ).css( {"display":"none"} );
		$(".feature:eq("+panelcount+")").fadeIn();
		
		clearTimeout ( featureTimer );
		
		}).mouseout(function() {	
			featureTimer = setTimeout ( "nextpanel()", 6000 );
			});

});

function nextpanel() {
	$( ".feature" ).css( {"display":"none"} );
	
	if (panelcount == lastPanel) {
		lastPanel = panelcount;
		panelcount = 0;
	} else {
		panelcount = panelcount + 1;
	}
	$(".feature:eq("+panelcount+")").fadeIn();
	
	featureLength = $(".featureB").length;
	for (x=0;x<featureLength;x++) {
		imgNum = "url(wp-content/plugins/cpfeatures/images/btn"+x+".png) no-repeat";
		idNum = whichId = "#" + "fButton_" + x;
		$(idNum).css( {"background": imgNum } );
	}
	
	whichImg = "url(wp-content/plugins/cpfeatures/images/btn"+panelcount+"over.png) no-repeat";
	whichId = "#" + "fButton_" + panelcount;
	$(whichId).css( {"background": whichImg } );
	
	featureTimer = setTimeout ( "nextpanel()", 6000 );

	}
