/*-------------------------------------------*\



                 DYNAMIC LEADS



\*-------------------------------------------*/



var currentTab=1;		//Keeps track of the current tab for rotating.



var dlRotate;			//Stores the interval for tab switching so it can be stopped.



var dlRunning = false;	//Keeps track of whether or not the auto scroll is running.



var dlNumTabs;			//Counts the number of tabs once the DOM is ready.



var firstLoad = true;	//Modifies the Toggle function on the first page load.



var dlFade = false;	//Keeps track of fading well it is occuring.







function dlToggle() { //Starts/stops the auto switching



	if(dlRunning) {



		$("a#dlToggle").css("background-position","-26px 0");



		clearInterval(dlRotate);



		dlRunning = false;



	} else {



		$("a#dlToggle").css("background-position","-13px 0");



		firstLoad?firstLoad=false:dlCycle("next");



		dlRotate = setInterval('dlCycle("'+'next'+'")', 28000); 
		//BA- October 27, 2010 - default 7000, this is the miliseconds before the auto rotating tabs, change active tab. 14000 requested, this wll double the current time.
		//BA- April 14, 2011 - Changed rotation speed from 14000 to 28000, to halve the rotation speed.


		dlRunning = true;



	}



}







function dlCycle(direction) { //Goes to next or previous tab



	if(direction == "next") {



		dlSwitch(currentTab>=dlNumTabs?1:currentTab+1);



	} else {



		dlSwitch(currentTab==1?dlNumTabs:currentTab-1);



	}



}







function dlSwitch(tabNum) { //Goes to the requested tab



	if(!dlFade) {



		dlFade = true;



		$("#dlTabs .activeTab").removeClass("activeTab");



		$("#dlTabs li").eq(tabNum-1).addClass("activeTab");



		$(".dlTab").eq(currentTab-1).fadeOut(200,function(){



			$(".dlTab").eq(tabNum-1).fadeIn(200,function(){dlFade = false;});



		});



		currentTab=parseInt(tabNum);



	}



}







var isCTRL = false;



var isFocus = false;



function arrowSwitch(Event) {



	if(Event==null) Event=event; //IE doesn't pass the event!



	if(Event.keyCode == 37 && isCTRL) { //left 37



		if(dlRunning) dlToggle();



		dlCycle("previous");



	} else if(Event.keyCode == 39 && isCTRL) { //right 39



		if(dlRunning) dlToggle();



		dlCycle("next");



	} else if(Event.keyCode == 17) {



		isCTRL = true;



	}



	



	if(Event.keyCode == 9 && !isFocus) { //outlines are turned off for firefox until the user hits tab



		$("a").addClass("withFocus");



		isFocus = true;



	}



	



}







function arrowCancel(Event) {



	if(Event==null) Event=event; //IE doesn't pass the event!



	if(Event.keyCode == 17) {



		isCTRL = false;



	}	



}







/*-------------------------------------------*\



                 TAB SWITCH



\*-------------------------------------------*/



var tabFade = false;	//Keeps track of fading well it is occuring.



function tabSwitch(container,newTab) { //Goes to the requested tab



	if(!tabFade && !$("#"+container+" .activeTab").is("#"+newTab+"Tab")) {



		tabFade = true;



		var oldTab = $("#"+newTab+"List").siblings();



		$("#"+container+" .activeTab").removeClass("activeTab");



		$("#"+newTab+"Tab").addClass("activeTab");



		oldTab.fadeOut(200,function(){



			$("#"+newTab+"List").fadeIn(200,function(){tabFade = false;});



		});



	}



}




