var thisPic = 1;
var preloadPic = 0;

var imgCt = slideshowFiles.length - 1;


function chgSlide(direction) {
	thisPic = thisPic + direction;
	if (thisPic > imgCt) {
		thisPic = 0;
	}
	if (thisPic < 0) {
		thisPic = imgCt;
	}
	
	selectSlide(thisPic);
}


function directSelectSlide(picNumber) {
	thisPic = picNumber;
	
	selectSlide(thisPic);
}


function selectSlide(thisPic) {
	document.getElementById("slide").innerHTML = '';
	document.getElementById("slide").style.width = imageWidths[thisPic] + "px";
	
	setTimeout('setNewImage(' + thisPic + ')', 1); // to prevent sliding of new image
}


function setNewImage(thisPic) {
	document.getElementById("slide").innerHTML = "<a href=\"javascript:chgSlide(1);javascript:imagePreload()\" onFocus=\"this.blur()\"><img src=\"" + slideshowFiles[thisPic] + "\" width=\"" + imageWidths[thisPic] + "\" height=\"" + imageHeights[thisPic] + "\" border=\"0\" alt=\"\" /><\/a>";
	/*if (imageCaptions[thisPic] != "") {
		document.getElementById("caption").innerHTML = "<p class=\"slideshowCaption\">" + imageCaptions[thisPic] + "<\/p>";
	}
	else
	{
		document.getElementById("caption").innerHTML = "";
	}*/
}



/* This function preloads the two images for the next button pair */

function imagePreload() {
	if (imgCt > 0)
	{
		preloadPic = preloadPic + 1
		if (preloadPic > imgCt) {
			preloadPic = 0;
		} 
		if (preloadPic < 0) {
			preloadPic = imgCt;
		}
		preloadImagename = slideshowFiles[preloadPic];
		thePreload  = new Image();
		thePreload.src = preloadImagename;
	}
}
