var currentDiv = 0;  //starting div
var numberDivs = 5;  //how many divs are there
var timer;
rotate(false); //starts the initial image rotation


function setDivs(newDiv){
	currentDiv=newDiv;//sets current div to what user selected
	showHideDivs(true);
}


/***
rotates through all featured divs and hides all not matching thisdiv's name.
***/
function showHideDivs(user){
	for(var i=1; i<=numberDivs;i++){
		var divName = document.getElementById("featured"+i);
		var linkName = document.getElementById("flink"+i);
		if(i==currentDiv){
			divName.style.display="block";
			linkName.style.backgroundColor="#102F5D";
			linkName.style.color="#ffffff";
			if (user){
				clearTimeout(timer);  //stop timer
			}
		}else{
			divName.style.display="none";
			linkName.style.backgroundColor="";
			linkName.style.color="#102F5D";
		}
	}

}

function rotate(){
	timer = setTimeout('rotate()',6*700); /***timer = setTimeout('rotate()',10*1000)***/
	processNext(false);
}

function processNext(user){
	currentDiv++;  //move to the next div
	if(currentDiv>numberDivs){  //do we need to wrap around to the first div
		currentDiv=1;
	}
	showHideDivs(user);  //call the function, passing in the auto rotate trigger
	return false;
}

function processPrevious(){
	if(currentDiv==1){  //if current div is the first one
		currentDiv=5;  //set to last div
	}else{
		currentDiv--; //go back 1
	}
	showHideDivs(true);  //call the function, passing in the auto rotate trigger
	return false;
}
