//SCRIPT FOR THE ROTATING IMAGES PART/////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////

//an array of the top relative position of the div in order to display the correct picture
var positions = new Array();
positions[0] = 0;
positions[1] = 0;
positions[2] = -320;
positions[3] = -640;

var dater = new Date();
var numImages = 3; // the number of images to be displayed
var scrollAmount = 0;  // a number that will be used to determine the distance between two slides
var toScroll = 0;  // a number that will determine the amount of scroll for each iteration through the function
var timer;
var counter=setTimeout("autoScroll()",8000);
var thePastButton;
var thePresentButton;

var theImage = 1;

var theLocation = positions[theImage];  // the location top relative position of the div
var imageOn = theImage;  // the image displayed, starts on the 1st image


function setUpImage(){
	document.getElementById('thePics').style.top = theLocation + 'px';
	thePresentButton = "button" + imageOn;
	var theSrc = 'images/rotatorButtons/' +thePresentButton+'Down.gif';
	document.getElementById(thePresentButton).src = theSrc;
}


function autoScroll(){
	counter=setTimeout("autoScroll()",8000);
	if(imageOn <= numImages - 1){
		calculateScroll(imageOn + 1);
	}else{
		calculateScroll(1);
	}	
}


function calculateScroll(theOne){
	clearTimeout(counter);
	thePastButton = "button" + imageOn;
	thePresentButton = "button" + theOne;
	var theSrc = 'images/rotatorButtons/' +thePastButton+'Up.gif';
	document.getElementById(thePastButton).src = theSrc;
	document.getElementById(thePastButton).style.background = "#017ac3";
	var theSrc = 'images/rotatorButtons/' +thePresentButton+'Down.gif';
	document.getElementById(thePresentButton).src = theSrc;
	scrollAmount = (theLocation - positions[theOne]);
	clearTimeout(timer);
	scroller();
	imageOn = theOne;
}


function scroller(){
	toScroll = scrollAmount/5;
	theLocation -= toScroll;
	scrollAmount -= toScroll;
	document.getElementById('thePics').style.top = theLocation + 'px';
	timer = setTimeout("scroller()",50);
	if(scrollAmount <= .5 && scrollAmount >= -.5){
		counter=setTimeout("autoScroll()",8000);
		clearTimeout(timer);
		theLocation = positions[imageOn];
		document.getElementById('thePics').style.top = theLocation + 'px';
	}
}

//function for button mouseOver
function swapImages(theOne){
	document.getElementById(theOne).style.background = '#017ac3';
}
//function for button mouseOut
function swapBack(theOne){
	if(theOne != thePresentButton){
		document.getElementById(theOne).style.background = '#017ac3';
	}
}


//////////////////////////////////////////END ROTATING IMAGE SCRIPT
///////////////////////////////////////////////////////////////////