var imageBase = "";
var spaceNumber = 1;

function swapTrigger() {
// This code actually changes the image.  We move through the locations sequentially and then randomly pick an
// image.

	//var spaceNumber = Math.round(Math.random()*4) + 1;
	if(spaceNumber < 5) {
		spaceNumber++;
	}
	else {
		spaceNumber = 1;
	}
	var imageNumber = Math.round(Math.random()*(maxImage - 1)) + 1
	if(imageNumber < 10) {
		imageNumber = "0" + imageNumber;
        }
	document.getElementById("header"+spaceNumber).src = "images/" + imageBase + "_" + imageNumber + ".jpg";
	setTimeout("swapTrigger()",swapInterval);
}

function swapImage() {
// Because we call this code from various pages, we need to check the prefix on the image subset that we'll use.
// We do this by reading the source image for the first image place-holder and extracting the first prefix.  If
// this is successful, then we go ahead and allow the images to change periodically.  Otherwise we silently fail.

	imageString = document.getElementById("header1").src;
	var endCharPos = 0;
	for(g = imageString.length; g > 0; g--) {
		if(imageString.substring(g,g+1) == "/") {
			if(endCharPos == 0) {
				endCharPos = g;
			}
		}
	}
	imageBase = imageString.substring((endCharPos+1),imageString.length);
	if(imageBase.length > 0) {
		imageBase = imageBase.substring(0,2);
		swapTrigger();
	}	
}
