// JavaScript Document
nTimer = nDelay * 1000;
nCurrentPic = -1;

var bDisableNext = false;
var bDisablePrev = false;

function initAnimation() {
	document.getElementById("diaporama").style.display = "inline";
	document.getElementById("diaporama").style.visibility = "visible";
	if(!bAuto) {
		document.getElementById("prev").onclick = PreviousPic;
		document.getElementById("prev").onmouseover = Handler;
		document.getElementById("prev").onmouseout = Handler;
		document.getElementById("next").onclick = NextPic;
		document.getElementById("next").onmouseover = Handler;
		document.getElementById("next").onmouseout = Handler;
		Status("prev","disable");
	}
	if(bDoPopup) {
		document.getElementById("diaporama").style.cursor = "pointer";
		document.getElementById("diaporama").onclick = ShowImage;
	}
	NextPic();
}

function ShowImage() {
	window.open("popup.php?file="+strPhotoFolder+arrImages[nCurrentPic],"popup","toolbar=no, scrollbars=no");
}

function Handler(e) {
	if(navigator.appName == "Microsoft Internet Explorer") {
		//alert("IE" + event.srcElement.id);
		strSourceID = event.srcElement.id;
		strEventType = event.type;
	} else {
		//alert("DA" + e.target.id);
		strSourceID = e.target.id;
		strEventType = e.type;
	}
	if(strEventType == "mouseover") {
		if(strSourceID == "prev") {
				document.getElementById("prev").className = strPrevOverClass;
		} else if (strSourceID == "next") {
				document.getElementById("next").className = strNextOverClass;
		}
	} else if(strEventType == "mouseout") {
		//alert(e.target.id + "-"+e.type);
		if(strSourceID == "prev") {
				document.getElementById("prev").className = strPrevClass;
		} else if (strSourceID == "next") {
				document.getElementById("next").className = strNextClass;
		}
	}
	
}

function NextPic() {
	nCurrentPic++;
	if(!bContinuous && (nCurrentPic+1 >= arrImages.length)) {
		Status("next","disable");
	}
	if(nCurrentPic >= arrImages.length) {
			nCurrentPic = arrImages.length-1;
		if(bContinuous) {
			nCurrentPic = 0;
			DisplayPic(nCurrentPic);
		}
	} else {
		if(!bContinuous && (nCurrentPic-1 >= 0)) {
			Status("prev","enable");
		}
		DisplayPic(nCurrentPic);
	}
	
	if(bAuto && (nCurrentPic < arrImages.length-1 || bContinuous)) {
		setTimeout("NextPic()",nTimer);
	}
}

function PreviousPic() {
	nCurrentPic--;
	if(!bContinuous && (nCurrentPic-1 <0)) {
		Status("prev","disable");
	}
	if(nCurrentPic < 0) {
		nCurrentPic = 0;
		if(bContinuous) {
			nCurrentPic = arrImages.length - 1;
			DisplayPic(nCurrentPic);
		}
	} else {
		if(!bContinuous && (nCurrentPic+1 < arrImages.length)) {
			Status("next","enable");
		}
		DisplayPic(nCurrentPic);
	}
}

function DisplayPic(nb) {
		strImg = arrImages[nb];
		document.getElementById("diaporama").src=strPhotoFolder + strImg.replace(/.jpg/g,"_thumb.jpg");
		if(bShowName) {
			document.getElementById("text").innerHTML = strPhotoFolder + arrImages[nb];
		}
}

function Status(strID, strStatus) {
if(!bAuto) {
	if(strStatus == "disable") {
		document.getElementById(strID).className = strDisabledClass;
		document.getElementById(strID).onclick = vid;
		document.getElementById(strID).onmouseover = vid;
		document.getElementById(strID).onmouseout = vid;
	} else if(strStatus == "enable") {
		if(strID == "prev") {
				document.getElementById(strID).className = "strPrevClass";
				document.getElementById(strID).onclick = PreviousPic;
		} else {
				document.getElementById(strID).className = "strNextClass";
				document.getElementById(strID).onclick = NextPic;
		}
		document.getElementById(strID).onmouseover = Handler
		document.getElementById(strID).onmouseout = Handler;
	}
}
}

function vid() {
	
}

document.write("<div align='center' class='"+strMainClass+"'><img src='' id='diaporama' class='"+strImageClass+"' style='visibility:hidden; display:none'>");
if(bShowName) {
	document.write("<br><div id='text'></div>");
}
if(!bAuto) {
	document.write("<br><div id='prev' class='"+strPrevClass+"' style='float:left;cursor:pointer;' align='left'>"+strPrev+"</div><div id='next' class='"+strNextClass+"' style='float:right;cursor:pointer;' align='right'>"+strNext+"</div>");
}
document.write("</div>");

window.onload = initAnimation;
