//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;
var activeGalleryID = null;

function displayPhoto(galleryID, photoNum, isInit)
{
	var allPhotosArray = eval('allPhotosArray' + galleryID);
	
	if (allPhotosArray.length > 0)
	{
		var arrayIndex;
		
		if (photoNum > allPhotosArray.length / 3)
			photoNum = 1;
		else if (photoNum < 1)
			photoNum = allPhotosArray.length / 3;
		
		activeGalleryID = galleryID;
		currPhoto = photoNum;
		arrayIndex = (photoNum - 1) * 3;
		
		document.getElementById("photo" + galleryID).src = "../galleries/" + eval('photoFolder' + galleryID) + "/" + allPhotosArray[arrayIndex];
		document.getElementById("credit" + galleryID).childNodes[0].nodeValue = allPhotosArray[arrayIndex + 1];
		document.getElementById("caption" + galleryID).childNodes[0].nodeValue = allPhotosArray[arrayIndex + 2];
		
		if (! (isInit && document.getElementById("photoDisplay" + galleryID).style.display == "none"))
			document.getElementById("photoDisplay" + galleryID).style.display = "";
	}
}

function NextPhoto()
{
	if (activeGalleryID != null)
	{
		currPhoto++;
		displayPhoto(activeGalleryID, currPhoto);
	}
}
function PreviousPhoto()
{
	if (activeGalleryID != null)
	{
		currPhoto--;
		displayPhoto(activeGalleryID, currPhoto);
	}
}

function ChangePhotoByArrow(evt)
{
	if (activeGalleryID != null)
	{
		var charCode = (evt.which) ? evt.which : event.keyCode;
		if (charCode == 37)		//left
			PreviousPhoto();
		else if (charCode == 39)	//right
			NextPhoto();
	}
}

function InitPhotos(galleryID)
{
	if (eval('allPhotosArray' + galleryID).length > 0)
	{
		displayPhoto(galleryID, 1, true);
		BuildPhotoNav(galleryID);
	}
}

function BuildPhotoNav(galleryID)
{
	var ne;
	var arrayIndex;
	var allPhotosArray = eval('allPhotosArray' + galleryID);
	
	for (var i = 1; i <= allPhotosArray.length / 3; i++)
	{
		arrayIndex = (i - 1) * 3;
		ne = document.createElement("img");
		ne.setAttribute("src", "../galleries/" + eval('photoFolder' + galleryID) + "/tn/" + allPhotosArray[arrayIndex]);
		ne.setAttribute("alt", allPhotosArray[arrayIndex + 2]);
		ne.onclick = new Function("displayPhoto(" + galleryID + "," + i + ")");
		document.getElementById("photoNav" + galleryID).appendChild(ne);
	}
}
