var imageIndex = 0;  //keeps up with the index of the currently displayed image.
var imgFlipSched;   //holds the autoimage flip timer.

//****************************************************
//Function:  changeImage
//Description:  Used to change the image in a specified div
//Parameter List:
//		divName - name of the div that the image should be applied to
//		imagePath - the path to the image to be applied
//		changeType - imgTag or background
//****************************************************
function changeImage(divName, imageNumber, changeType)
{
	clearTimeout(imgFlipSched);   //resets the timer on the image change
	imageIndex = imageNumber + 1;  //set our index to show the next image in the list after the selected image
	changeLinkLook(imageNumber);
	var imagePath = imagePathArray[imageNumber];
	divEl = document.getElementById(divName);   //get the div element to update
	if (changeType == 'imgTag')
	{
		//write an image tag in the specified div
		var linkText = "<a href='" + linkArray[imageNumber] + "'";
		if (linkDestination[imageNumber] == 'new')
		{
			linkText = linkText + " target='_blank' "
		}
		linkText = linkText + ">"
		
		divEl.innerHTML = linkText + "<img src='" + imagePath + "' width='" + imageWidth + "px' border='0'></img></a>";
		
	}
	else
	{
		//sets the background of the div to be the image that is passed in
		divEl.style.backgroundImage = "url(" + imagePath + ")";
	}
	imgFlipSched = setTimeout('autoFlipImage()', timeToWait * 1000);  //reset the timer for the image flip
}

//****************************************************
//Function:  autoFlipImage
//Description:  Used to automatically change the image.  It should be called initially at the
//		bottom of the web page where it will be used to begin the timer process.
//****************************************************
function autoFlipImage()
{
	if (imageIndex >= imagePathArray.length)  //If we've reached the end of the list, start over
	{
		imageIndex = 0;
	}
	changeImage(autoFlipDivName, imageIndex, autoFlipChangeType) //Change to the next image.
	imgFlipSched = setTimeout('autoFlipImage()', timeToWait * 1000);  //Kick off next timer to flip the image
}

//****************************************************
//Function:  changeLinkLook
//Description:  Changes the link color back to white for all the links, then changes the appropriate one to
//		the correct highlight color;
//Parameter List:
//		imageNumber - the current image/link combination we are processing
//****************************************************
function changeLinkLook(imageNumber)
{
	var linkDiv;
	   //color the link text should change to when its image is displayed
	
	for(var i=0; i < imagePathArray.length; i++)   //reset the color back to white for all links
	{
		linkDiv = document.getElementById('Link' + i);
		linkDiv.style.color = linkOriginalColor;
	}
	linkDiv = document.getElementById('Link' + imageNumber);  //get the appropriate link attached to the image that is changing.
	linkDiv.style.color = linkHighlightColor;  //change the color to the HIGHLIGHT_COLOR
}

