//pre-load images --These locations are relative to the page this will be displayed on. In our case, we call it from the index page, and all of these images are in the rotate folder.
var aImg = new Image();
aImg.src = 'rotate/sirsi.jpg';
var bImg = new Image();
 bImg.src = 'rotate/techsurvey.jpg';
 var dImg = new Image();
dImg.src = 'rotate/vincennes2-10.jpg';





//Function for displaying the "news" items. This part goes unchanged.
function makeNews(c,l,i){
	this.copy = c;
	this.link = l;
	this.img = i;
	this.write = writeNews;
}

//Function for formatting the various pieces of the news item into HTML. This part goes unchanged unless you want to change the image border.
function writeNews(){
	var str = '';
	str += '<a href="' + this.link + '">';
	str += '<img border="0" src="' + this.img.src + '"></a><br>';
	str += '<span class="rotatelink">' + this.copy + '</span>';
    
	return str;
}

//Array for holding news items. Each line is a separate item, containing three parts. Each part is separated by commas. The first part is if you want text displayed underneath the item. We leave this blank because we put enough text in the graphic and in the links below. The second part is where you want the news item to link to. This link will be attached to the image. The third part is the image, which is defined at the beginning of the script. You can add as many images as you want simply by copying one of the lines below, increasing the number after newsArray by one, and then changing the rest of the info according to your news item. If something is not working, make sure that all newsArrays have a unique, sequential number and all images are called correctly at the beginning of the script.
var newsArray = new Array();



newsArray[0] = new makeNews("",'http://survey.constantcontact.com/survey/a07e2sf6744g6m60uqo/start',bImg).write();

newsArray[1] = new makeNews("",'http://www.hcplibrary.org/about/sirsi.htm',aImg).write();

newsArray[2] = new makeNews("",'http://www.hcplibrary.org/vincennes.htm',dImg).write(); 






//variables affecting how the script functions. Pretty much the only thing you need to change here is the info in timerID. Right now it is set to 7 seconds before it starts changing (in the rotateNews function) and 7 seconds between each subsequent rotation (in the playNews function). The pauseNews function makes it stop changing whenever the mouse is hovering over the picture.

var nIndex = 0;
var timerID = null;
function rotateNews(){
	var len = newsArray.length;
	if(nIndex >= len)
		nIndex = 0;
	document.getElementById('stories').innerHTML = newsArray[nIndex];
	nIndex++;
	timerID = setTimeout('rotateNews()',7000);
}
function pauseNews() {
	if (timerID != null) {
		clearTimeout(timerID);
		timerID = null;
	}
}

function playNews() {
	if (timerID == null) {
		timerID = setTimeout('rotateNews()', 7000);
	}
}
