// JavaScript to play a slide show with
// option for sequential or random order
//
// For this script to work, you need an image in the source HTML page
// with the name="SlideShow" attribute.
//=====================
// First the Globals...

// Set slideShowSpeed (milliseconds)
	var slideTimer = 3000;

	var fadeTimer = 2;	// Duration of crossfade (seconds)
	var imageDir="";	// Location of images

	var slideList;		// A string of image files
	var picArray;		// Array converted from slideList using split()
	var tID;
	var cnt = 0;
	var max;
	var preLoad;

// ===================
// Slide Show Function 

function slideShow(showRandom) {
// alert("slideShow...");
	if (showRandom) {
		cnt = randNum(0, max);
	}
	else {
		if ((cnt) == max) {
			cnt=0;
		}
	}
// This next line is the one that actually swaps the image
	document.images.SlideShow.src = preLoad[cnt].src;
	cnt+=1;
//	alert("swapping image "+cnt+": "+preLoad[cnt].src);
	tID = setTimeout('slideShow(false)', slideTimer);
}

//	Random number routine

function randNum(x, y) {
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}


// Slideshow Setup
function slideSetup() {
//  alert("slideSetup...");
	var i;
	clearTimeout(tID);
	picArray=slideList.split(" ");
	max = picArray.length;

	preLoad = new Array();
	for (i = 0; i < max; i++){
	   preLoad[i] = new Image();
	   preLoad[i].src = imageDir+picArray[i];
//	   alert("preloading "+preLoad[i].src);
	}
}

function cycleImage() {
	if ((cnt+=1) == max) {
		cnt=0;
	}
	document.images.SlideShow.src = preLoad[cnt].src;
}

