var photoArray = new Array();

var photoListHandler = function(t) {
	var photoHtml = '';
	var photoList = t.responseText;
	photoArray = photoList.split("\n");
	for (var i=0; i<photoArray.length; i++) {
		if (photoArray[i].length > 0) {
			var lidId = 'lid_' + i;
			photoHtml += "<div id=\"";
			photoHtml += lidId;
			if (i == 0) {
 				photoHtml += "\" style=\"display:block;position:absolute;top:190;right:45\">";
			} else {
 				photoHtml += "\" style=\"display:none;position:absolute;top:190;right:45\">";
			}
			photoHtml += "<img src='photos/";
			photoHtml += photoArray[i];
			photoHtml += ".page.jpg' align='center'></div>";
		} else {
			photoArray.splice(i,1);
		}
	}
	$('slideshow').innerHTML = photoHtml;
}

var photoListFailure = function(t) {
	alert("Error getting photo list.  Error type:" + t.status + ": " + t.statusText);
}

function nextPhoto() {
	Effect.Fade($('lid_' + photoIndex));
	photoIndex++;
	if (photoIndex >= photoArray.length) {
		photoIndex = 0;
	}
	var lidId = 'lid_' + photoIndex;
	Effect.Appear($(lidId));
}

function prevPhoto() {
	Effect.Fade($('lid_' + photoIndex));
	photoIndex--;
	if (photoIndex < 0) {
		photoIndex = photoArray.length - 1;
	}
	Effect.Appear($('lid_' + photoIndex));
}


var photoIndex = 0;
new Ajax.Request('/circus2006/photos/photos.xml',{ onSuccess:photoListHandler, onFailure:photoListFailure });
//$('lid_0').style.visibility = 'visible';
//$('lid_0').style.display = 'block';
