/**********************************************************************
Include this file on any page that needs to loop through a series
of images. This file takes care of *almost* everything you need,
but in the parent file you need to include:
   <body onload="startClock('(opt)YourImgIdHere')">
as the body tag, 

You also need to include a script tag, below this included 
script, with
	slideShowPath="";	// your path to images, with trailing slash
	slideShowImgId="(optYourImgIdHere)"; // if you prefer to set 
										// a variable instead of passing
										// an ID string.

   newim("yourImageFile.jpg");
	newim("yourNextImageFile.jpg");
	...

You can also override the timer, which defaults to 4 seconds, by
including
	slideShowTimer = 5000; // number of milliseconds
in your script

**********************************************************************/

/* EXAMPLE OF USE: 
var ss1 = new slideShowObj("imgId","images/");
ss1.newim("aboutHSR_Beecr_img.jpg");
ss1.newim("aboutHSR_Bluede_img.jpg");
ss1.newim("aboutHSR_Drjean_img.jpg");
function calledOnLoad() {
	ss1.startClock();
}
*/


function slideShowObj (slideShowImgId, slideShowAId, path, timeseconds) {
	// additional optional third parameter is slideShowTimer override
	this.imarray = new Array();
	this.linkarray = new Array();
	this.imnum = 0;
	this.timeoutSlides = 2;
	this.slideShowPath = path;
	this.imgId = slideShowImgId;
	this.aId = slideShowAId;
	this.slideShowTimer = (timeseconds * 1000);
	if (slideShowObj.arguments.length > 4) {
		this.slideShowTimer = slideShowObj.arguments[2];
	}
	
	this.newim = newim;
	this.cancelTimer = cancelTimer;
	this.startClock = startClock;
}


function newim(file, vLink) {
	var newnum = this.imarray.length
	this.imarray[newnum]=this.slideShowPath+file;
	this.linkarray[newnum]=vLink;
}

/*
function nextPic() {
	// change the image
	// including the HREF
	// then set the timer again
	alert ("DEBUG: " + this.imgId)
	ourimg = document.getElementById(this.imgId);
	this.imnum++;
	if (this.imnum >= this.imarray.length) { this.imnum=0 }
	ourimg.src = this.imarray[this.imnum];
	this.startClock()
}

*/
function cancelTimer () {
	clearTimeout (this.timeoutSlides);
}

function startClock () {
	// set the timer
	// then start preloading the next image
	// this.timeoutSlides = setTimeout("this.nextPic()",this.slideShowTimer);
	var arrString = this.imarray.join("','");
	var arrLinkString = this.linkarray.join("','");
	arrString = "'" + arrString + "'";
	arrLinkString = "'" + arrLinkString + "'";
	// alert ("DEBUG: " + "nextPics('"+this.imgId+"',new Array("+arrString+"),'"+this.aId+"',new Array("+arrLinkString+"))");
	this.timeoutSlides = setInterval("nextPics('"+this.imgId+"',new Array("+arrString+"),'"+this.aId+"',new Array("+arrLinkString+"))",this.slideShowTimer);
}

// nextPics("myimage",4,"new array('','','')")

// make any number of counters
var imnum = new Array();

function nextPics (imgId, imarray, aId, linkarray) {
	// use the same counters for arrays of the same length
	// if counter hasn't been set, make it zero
	// otherwise, increment it
	if (isNaN(imnum[imarray.length])) {
		imnum[imarray.length]=0 
	}
	ourimg = document.getElementById(imgId);
	ourimg.src = imarray[imnum[imarray.length]];
	oura = document.getElementById(aId);
	//oura.href = linkarray[imnum[imarray.length]];
	
	imnum[imarray.length]++;
	if (imnum[imarray.length] >= imarray.length) { imnum[imarray.length]=0 }
	nextim=new Image();
	nextim.src=imarray[imnum[imarray.length]];
}