
// ajax display of photo text

var textDisplayed = false;
	
function toggleText(valDelay) {
	
	var textDiv = document.getElementById("photoText");
	if (textDiv.style.display == "none" && !textDisplayed ) {
		new Effect.BlindDown("photoText",{delay: valDelay});
		new Effect.BlindUp("viewText");
		textDisplayed = true;
	}
}

function hideTextNow() {
	new Effect.BlindUp("photoText");
	new Effect.BlindDown("viewText");
	textDisplayed = false;
}

// xml functions

function getUrlVariable(url,varname) { 

	var qparts = url.split("?");
	if (qparts.length == 1)
		return "";
	var query = qparts[1];
	var vars = query.split("&");
	var value = "";

	for (i=0;i<vars.length;i++) {
		var parts = vars[i].split("=");
		if (parts[0] == varname)
		{
			value = parts[1];
			break;
		}
	}
	value = unescape(value);
	value.replace(/\+/g," ");
	return value;
}


function getPhoto(photoSet,photoID) {

	if (photoID == "") photoID = 0;
	
	var photo = new Object();
	photo = setPhoto(photo, photoSet[photoID]);
	photo.id = parseInt(photoID);
	return photo;

}

function setPhotoControls(photoSet,currentPhotoID) {
	var s = new StringBuilder();
	for (var i=1; i<photoSet.length + 1; i++) {
	 	if (i == currentPhotoID + 1)
			s.append("<a class='on' href='" + fileName + "?id=" + (i - 1) + "'>" + i + "</a>");
		else
			s.append("<a href='" + fileName + "?id=" + (i - 1) + "'>" + i + "</a>");
	}
	document.getElementById("phControls").innerHTML = s;
}


function setPhoto(photoObj, photoElement) {
	
	for (var node=photoElement.firstChild; node != null;	node=node.nextSibling) {
		var name = node.nodeName;
		if (name == "title") photoObj.title = node.firstChild.data;
		if (name == "fileName")	photoObj.fileName = node.firstChild.data;
		if (name == "credit") {
			if(isIE()) photoObj.credit = node.firstChild.data;
			else photoObj.credit = node.childNodes[1].data;
		}
		if (name == "text") {
			if(isIE()) photoObj.text = node.firstChild.data;
			else photoObj.text = node.childNodes[1].data;
		}
	}	
	return photoObj;
}

function setPhotoOnPage(photo,totalPhotos) { 
			
	var photoFileName = document.getElementById("currentPhoto");
	photoFileName.src = "images/" + photo.fileName;
	new Effect.Appear("currentPhoto");
	
	var photoTitle = document.getElementById("phPhotoTitle");
	photoTitle.innerHTML = photo.title;

	var photoText = document.getElementById("phPhotoText");
	photoText.innerHTML = photo.text;
	
	var photoCredit = document.getElementById("phPhotoCredit");
	
	photoCredit.innerHTML = photo.credit;
	
	var nextPhoto = getNextPhotoID(photo.id);
	var prevPhoto = getPrevPhotoID(photo.id);
	
	var nextLink = fileName + "?id=" + nextPhoto;
	var prevLink = fileName + "?id=" + prevPhoto;
}

function gotoNextPhoto(fileName,currentPhoto) {
	window.location = fileName + "?id=" + getNextPhotoID(currentPhoto);
}
function gotoPrevPhoto(fileName,currentPhoto) {
	window.location = fileName + "?id=" + getPrevPhotoID(currentPhoto);
}

function getNextPhotoID(currentPhoto) {
	var nextPhoto = currentPhoto + 1;
	if (currentPhoto == totalPhotos - 1) nextPhoto = 0;
	return nextPhoto;
}

function getPrevPhotoID(currentPhoto) {
	var prevPhoto = currentPhoto - 1;
	if (currentPhoto == 0) prevPhoto = totalPhotos - 1;
	return prevPhoto;
}