function isIE(){
	if (navigator.appName == "Microsoft Internet Explorer") {
		return true;
	} else {
		return false;
	}
}


// ajax display of photo text

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,slidID) {
	var s = new StringBuilder();
	for (var i=1; i<photoSet.length + 1; i++) {
		s.append('<li><a href="javascript:void(0);" onclick="onPageLoad2(\''+(i - 1)+'\', \''+varDiaporama+'\');"><img src="http://www.msf.fr/imageslide.php?i=' + (i - 1) + '&slide='+slidID+'" /></a></li>');
	}
	document.getElementById("phControls").innerHTML = s;
	jQuery('#phControls').jcarousel();
}


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 (navigator.appName == "Microsoft Internet Explorer") {
				photoObj.credit = node.firstChild.data;
			} else {
				photoObj.credit = node.childNodes[1].data;
			}
		}
		if (name == "text") {
			if (navigator.appName == "Microsoft Internet Explorer") {
				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 = photo.fileName;
		new Effect.Appear("currentPhoto");
		
		var photoTitle = document.getElementById("phPhotoTitle");
		if (photoTitle) photoTitle.innerHTML = photo.title;
	
		var photoText = document.getElementById("phPhotoText");
		if (photoText) photoText.innerHTML = photo.text;
		
		var photoCredit = document.getElementById("phPhotoCredit");
		if (photoCredit) photoCredit.innerHTML = photo.credit;
		
		var nextPhoto = getNextPhotoID(photo.id);
		var prevPhoto = getPrevPhotoID(photo.id);
		
		var nextLink = fileName + "&ids=" + nextPhoto;
		var prevLink = fileName + "&ids=" + prevPhoto;

}

function gotoNextPhoto(fileName,currentPhoto) {
	carregarSlideshow(getNextPhotoID(currentPhoto), varDiaporama);
}
function gotoPrevPhoto(fileName,currentPhoto) {
	carregarSlideshow(getPrevPhotoID(currentPhoto), varDiaporama);
}

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;
}