//in HTML document:  var allPhotos = 'photo01.gif|PHOTORUN|This is somebody running|photo02.gif|Kirby Lee|This is somebody in the HJ';
var allPhotosArray = null;
var currPhoto = 0;

function displayPhoto(photoNum, isInit)
{
	if (allPhotosArray != null)
	{
		var arrayIndex;
		
		if (photoNum > allPhotosArray.length / 3)
			photoNum = 1;
		else if (photoNum < 1)
			photoNum = allPhotosArray.length / 3;
		
		currPhoto = photoNum;
		arrayIndex = (photoNum - 1) * 3;
		
		document.getElementById("photo").src = "../galleries/" + photoFolder + "/" + allPhotosArray[arrayIndex];
		document.getElementById("credit").childNodes[0].nodeValue = allPhotosArray[arrayIndex + 1];
		document.getElementById("caption").childNodes[0].nodeValue = allPhotosArray[arrayIndex + 2];
		
		if (! (isInit && document.getElementById("photoDisplay").style.display == "none"))
			document.getElementById("photoDisplay").style.display = "";
	}
}

function NextPhoto()
{
	currPhoto++;
	displayPhoto(currPhoto);
}
function PreviousPhoto()
{
	currPhoto--;
	displayPhoto(currPhoto);
}

function ChangePhotoByArrow(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode == 37)		//left
		PreviousPhoto();
	else if (charCode == 39)	//right
		NextPhoto();
}

function InitPhotos()
{
	if (allPhotos != '')
	{
		allPhotosArray = allPhotos.split("|");
		displayPhoto(1, true);
		BuildPhotoNav();
	}
}

function BuildPhotoNav()
{
	var ne;
	var arrayIndex;
	
	for (var i = 1; i <= allPhotosArray.length / 3; i++)
	{
		arrayIndex = (i - 1) * 3;
		ne = document.createElement("img");
		ne.setAttribute("src", "../galleries/" + photoFolder + "/tn/" + allPhotosArray[arrayIndex]);
		ne.setAttribute("alt", allPhotosArray[arrayIndex + 2]);
		ne.onclick = new Function("displayPhoto(" + i + ")");
		document.getElementById("photoNav").appendChild(ne);
	}
}
