bAuto = false;
iCount = 0;
iIndex = -1;
iIDs = new Array();
iAutoDelay = 10000;
sCaptions = new Array();
iTimeout = 0;


function getElement(sName) {

	if (document.getElementById) {
		return document.getElementById(sName);
	} else if (document.all) {
		return document.all[sName];
	}
}


function NextPhoto() {

	if (++iIndex >= iCount) {
		iIndex = 0;
	}

	ShowPhoto();
}


function OnPhotoLoad() {

	if (bAuto) {
		iTimeout = window.setTimeout('OnTimeout()', iAutoDelay);
	}
}


function OnTimeout() {

	iTimeout = 0;

	if (bAuto) {
		NextPhoto();
	}
}


function PrevPhoto() {

	if (--iIndex < 0) {
		iIndex = iCount - 1;
	}

	ShowPhoto();
}


function ShowPhoto() {

	if (iTimeout) {
		window.clearTimeout(iTimeout);
		iTimeout = 0;
	}

	if (iCount > 0) {
		getElement('imgPhoto').src = 'images/' + sDir + iIDs[iIndex] + '.jpg';
		getElement('pCaption').innerHTML = sCaptions[iIndex];
		getElement('sIndex').innerHTML = iIndex + 1;
	} else {
		getElement('imgPhoto').style.visibility = 'hidden';
		getElement('pCaption').innerHTML = 'No photos currently available';
		getElement('sIndex').innerHTML = 0;
	}
	getElement('sCount').innerHTML = iCount;
}


function ToggleAuto() {

	bAuto = !bAuto;

	//getElement('btnPrev').disabled = bAuto;
	//getElement('btnNext').disabled = bAuto;

	if (bAuto) {
		getElement('btnPlay').value = 'Pause';
		NextPhoto();
	} else {
		getElement('btnPlay').value = ' Play ';
	}
}
