var thisPic = new Array;//1
var preloadPic = new Array;//0
var imgCt = new Array; //slideshowFiles.length - 1;

function chgSlide(ssId, direction) 
{
	thisPic[ssId] = thisPic[ssId] + direction;
	if (thisPic[ssId] > imgCt[ssId]) {
		thisPic[ssId] = 0;
	}
	if (thisPic[ssId] < 0) {
		thisPic[ssId] = imgCt[ssId];
	}
	
	document.getElementById("slide" + ssId).innerHTML = "<a href=\"javascript:chgSlide(" + ssId + ",1);javascript:imagePreload(" + ssId + ")\" onFocus=\"this.blur()\"><img src=\"" + ssArray[ssId]['slideshowFiles'][thisPic[ssId]] + "\" width=\"" + ssArray[ssId]['widths'][thisPic[ssId]] + "\" height=\"" + ssArray[ssId]['heights'][thisPic[ssId]] + "\" border=\"0\" alt=\"\" /><\/a>";//<p class=\"slideshowPhotocredit\">" + ssArray[ssId]['imagePhotographers'][thisPic] + "<\/p>";
	document.getElementById("slide" + ssId).style.width = (parseInt(ssArray[ssId]['widths'][thisPic[ssId]]) + 14) + "px";
	if (ssArray[ssId]['imageCaptions'][thisPic[ssId]] != "") {
		document.getElementById("caption" + ssId).innerHTML = "<p class=\"slideshowCaption\">" + ssArray[ssId]['imageCaptions'][thisPic[ssId]] + "<\/p>";
	}
	else
	{
		document.getElementById("caption" + ssId).innerHTML = "";
	}
}

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

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


function initSlideshows()
{
	for (var i=0; i < ssArray.length; i++ )
	{
		thisPic[i] = 1;
		preloadPic[i] = 1;
		imgCt[i] = ssArray[i]['slideshowFiles'].length - 1;
		
		chgSlide(i, -1);
		imagePreload(i);
	}
}

window.onload = initSlideshows();