/*
tijdens het (pre)loaden zou je evt een gifje tussen menubar en foto kunnen tonen (of in het menu ergens)
bij het afsluiten van de div kun je de foto vervangen door een defaultplaatje, dat je sowieso eerst preload.
*/
var t=0, j=-1, i=-1; y=0;
// custom om alleen door geslecteerde groep heen te gaan terwijl alle foto's in javascript staan.
// dus je moet een begin nr en een eind nr hebben bij het openen van de foto's en deze vervangen j==0 en j==(p-1)
function openPhoto(parPhotoGroupID, parPhotoID){ // onClick 'thumb'
	setPhotoGroup(parPhotoGroupID);
	resizeFadeDiv();
	y = document.body.scrollTop;
	document.body.scrollTop = 0;
	resetPhotos();
	showPhoto(parPhotoID);
	document.getElementById("photoPopup").style.visibility  = "visible";
	document.getElementById("photoMenu").style.visibility   = "visible";
	document.getElementById("divFadeBody").style.visibility = "visible";

}
function closePhoto() { // onClick 'x' and outside
	document.getElementById("divFadeBody").style.visibility = "hidden";
	document.getElementById("photoPopup").style.visibility  = "hidden";
	document.getElementById("photoMenu").style.visibility   = "hidden";
	document.body.scrollTop = y;
	resetPhotos();
}
function resizeFadeDiv(){
  if ( document.getElementById("divFadeBody") != undefined && document.getElementById("photoPopup") != undefined ) {
    document.getElementById("divFadeBody").style.width  = document.body.scrollWidth;
    document.getElementById("divFadeBody").style.height = document.body.scrollHeight;
    document.getElementById("photoPopup").style.width   = document.body.scrollWidth;
    document.getElementById("photoPopup").style.height  = document.body.scrollHeight;
  }
  if ( document.getElementById("divFadeBody") != undefined && document.getElementById("flashPopup") != undefined ) {
    document.getElementById("divFadeBody").style.width  = document.body.scrollWidth;
    document.getElementById("divFadeBody").style.height = document.body.scrollHeight;
    document.getElementById("flashPopup").style.width   = document.body.scrollWidth;
    document.getElementById("flashPopup").style.height  = document.body.scrollHeight;
  }
}
function enablePrev() {
	document.getElementById("btnPrevDis").style.display = "none";
	document.getElementById("btnPrev").style.display    = "inline";
}
function disablePrev() {
	document.getElementById("btnPrev").style.display    = "none";
	document.getElementById("btnPrevDis").style.display = "inline";
}
function enableNext() {
	document.getElementById("btnNextDis").style.display = "none";
	document.getElementById("btnNext").style.display    = "inline";
}
function disableNext() {
	document.getElementById("btnNext").style.display    = "none";
	document.getElementById("btnNextDis").style.display = "inline";
}
function enablePlay() {
	document.getElementById("btnPlayDis").style.display = "none";
	document.getElementById("btnPause").style.display   = "none";
	document.getElementById("btnPlay").style.display    = "inline";
}
function enablePause() {
	document.getElementById("btnPlayDis").style.display = "none";
	document.getElementById("btnPlay").style.display   = "none";
	document.getElementById("btnPause").style.display   = "inline";
}
function disablePlay() {
	document.getElementById("btnPlay").style.display    = "none";
	document.getElementById("btnPause").style.display   = "none";
	document.getElementById("btnPlayDis").style.display = "inline";
}
function checkButtons() {
	(j==firstPhoto)? disablePrev() : enablePrev();
	(j==lastPhoto )? disableNext() : enableNext();
/*
 	(j==0)?     disablePrev() : enablePrev();
	(j==(p-1))? disableNext() : enableNext();
*/
}
function startLoading() {
}
function stopLoading() {
}
function waitTillImageIsLoaded() {
	(preLoad[j].complete)? stopLoading(): setTimeout('waitTillImageIsLoaded()',100);
}
function preLoadImage(parPhotoNr) {
	if (preLoad[parPhotoNr].src != photoSrc[parPhotoNr]) {
		preLoad[parPhotoNr].src = photoSrc[parPhotoNr];
		startLoading();
		waitTillImageIsLoaded();
	}
}
function switchPhoto(){
	document.images.photoLargeImage.src    = preLoad[j].src;
	checkButtons();
}
function runPhotos(){
	if (blnPlay) {
 		(i==firstPhoto-1)? i=j : j=i;
		switchPhoto(j);
		(i>lastPhoto-1)? i=firstPhoto : i+=1;
		preLoadImage(i);
		t = setTimeout('runPhotos();', photoImageDuration)
/*
 		(i==-1)? i=j : j=i;
		switchPhoto(j);
		(i>p-2)? i=0 : i+=1;
		preLoadImage(i);
		t = setTimeout('runPhotos();', photoImageDuration)
*/
	}
}
function showPhoto(parPhotoNr) {
	(parPhotoNr==undefined)? j=firstPhoto : j=parPhotoNr;
	preLoadImage(j);
	switchPhoto();
}
function playPhotos() { // onClick '|>'
	blnPlay = true;
	enablePause();
	runPhotos();
}
function pausePhotos() { // onClick '||'
	clearTimeout(t);
	blnPlay = false;
	i=firstPhoto-1;
/*
 	i=-1;
*/
		enablePlay();
}
function previousPhoto() { // onClick '<'
	pausePhotos();
	disablePrev(); // disable during switch
	j -= 1;
	preLoadImage(j);
	switchPhoto();
}
function nextPhoto() { // onClick '>'
	pausePhotos()
	disableNext(); // disable during switch
	j += 1;
	preLoadImage(j);
	switchPhoto();
}
function resetPhotos() { // intialise/reset buttons etc.
	pausePhotos();
//	if (p<2) { // only 1 photo
	if (firstPhoto==lastPhoto) { // only 1 photo
		disablePrev();
		disableNext();
		disablePlay();
	} else {
		enablePrev();
		enableNext();
		enablePlay();
	}
}
