var g_strPhotoDir = "";
var g_nPhotoIndex = 0;
var g_nPhotoIndexCurrent = 0;
var g_nPhotoCount = 0;
var g_nPhotoThumbsFlag = 0;
var g_aryCaptions = null;

function GetElement(id)
{
	return	document.all? document.all.item(id): 
			document.getElementById? document.getElementById(id): 
			document.layers? document.layers[id]: null;
}

function Photo_Initialize(path, count, thumbs, captions)
{
	g_strPhotoDir = path;
	g_nPhotoCount = count;

	var id, obj;
	if(obj = GetElement("thumbs"))
	{
		var temp = "";
		for(var i=0; i<g_nPhotoCount; i++)
		{
			id = ((i < 9)? "0": "") + (i+1);
			temp += '<div class="item">';
			temp += '<a id="thumb' + i + '"';
			temp += ' href="javascript:Photo_Display(' + i + ');">'
			if(thumbs)
				temp += '<img src="' + g_strPhotoDir + '/' + id + '.jpg">';
			else
				temp += '&nbsp;';
			temp += '</a>';
			temp += '</div>';
		}

		obj.innerHTML = temp;
	}

	if(captions)
		g_aryCaptions = captions.split(",");

	Photo_Display(0);
}

function Photo_Prev()
{
	g_nPhotoIndex = (g_nPhotoIndex + g_nPhotoCount - 1) % g_nPhotoCount;
	Photo_Display(g_nPhotoIndex);
}

function Photo_Next()
{
	g_nPhotoIndex = (g_nPhotoIndex + 1) % g_nPhotoCount;
	Photo_Display(g_nPhotoIndex);
}

function Photo_Display(index)
{
	var id, obj;

	id = ((index < 9)? "0": "") + (index+1);
	if(obj = GetElement("photo"))
		obj.innerHTML = '<img src="' + g_strPhotoDir + '/' + id + '.jpg">';

	if(obj = GetElement("thumb" + g_nPhotoIndexCurrent))
		obj.className = "";

	if(obj = GetElement("thumb" + index))
		obj.className = "current";

	if((obj = GetElement("caption")) && g_aryCaptions)
		obj.innerHTML = (g_aryCaptions[index]? g_aryCaptions[index]: "");

	g_nPhotoIndexCurrent = index;
}


