/*
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;
var firstPhoto = 0; lastPhoto = 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)
var flashMovie;
function openPhoto(parPhotoID, parPhotoGroupID){ // onClick 'thumb'
  if ( parPhotoGroupID!=undefined ) {
    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 openFlashLightBox(parFileName){ // onClick 'thumb'
  resizeFadeDiv();
  y = document.body.scrollTop;
  document.body.scrollTop = 0;
  document.getElementById("flvFlashPlayer").innerHTML = getLightboxObject("/cmdata/videos/flv_player.swf?fileName="+parFileName, 360, 240, 9);
  document.getElementById("flashPopup").style.visibility  = "visible";
  document.getElementById("divFadeBody").style.visibility = "visible";
}
function closePhoto() { // onClick 'x' and outside
  closeLightBox();
}
function closeLightBox() { // onClick 'x' and outside
  document.getElementById("divFadeBody").style.visibility = "hidden";
  if ( document.getElementById("photoPopup") != undefined ) {
    document.getElementById("photoPopup").style.visibility  = "hidden";
    document.getElementById("photoMenu").style.visibility   = "hidden";
    resetPhotos();
  }
  if ( document.getElementById("flashPopup") != undefined ) {
    document.getElementById("divFadeBody").style.visibility = "hidden";
    document.getElementById("flashPopup").style.visibility  = "hidden";
    document.body.scrollTop = y;
    document.getElementById("flvFlashPlayer").innerHTML = "";
  }
  document.body.scrollTop = y;
}
function closeFlashLightBox() { // onClick 'x' and outside
  closeLightBox();
}
function resizeFadeDiv(){
  var blnResize = false;
  if ( document.getElementById("photoPopup") != undefined ) {
    blnResize = true;
    document.getElementById("photoPopup").style.width   = document.body.scrollWidth;
    document.getElementById("photoPopup").style.height  = document.body.scrollHeight;
  }
  if ( document.getElementById("flashPopup") != undefined ) {
    blnResize = true;
    document.getElementById("flashPopup").style.width   = document.body.scrollWidth;
    document.getElementById("flashPopup").style.height  = document.body.scrollHeight;
  }
  if ( blnResize ) {
    document.getElementById("divFadeBody").style.width  = document.body.scrollWidth;
    document.getElementById("divFadeBody").style.height = document.body.scrollHeight;
  }
}
function getLightboxObject(parName, parWidth, parHeight, parVersion) {
  var x
  if ( parHeight==0 ) {
    parHeight = parWidth*3/4+30;
  }
  if ( parWidth==0 ) {
    parWidth = parHeight*4/3;
  }
  x = '<object id="myFlashMovie" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+parVersion+',0,0,0" width="'+parWidth+'" height="'+parHeight+'" align="middle">';
  x += '<param name="allowScriptAccess" value="sameDomain"/>';
  x += '<param name="movie" value="'+parName+'" />';
  x += '<param name="quality" value="high" />';
  x += '<param name="wmode" value="transparent" />';
  x += '<param name="swliveconnect" value="true" />';
  x += '<embed swliveconnect="true" wmode="transparent" name="myFlashMovie" src="'+parName+'" quality="high" width="'+parWidth+'" height="'+parHeight+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"  play="true" wmode="transparent"/>';
  x += '</object>';
  return x;
}
function resizeFlashBox(parWidth, parHeight) {
  if (parHeight == undefined) {
    parHeight = 576;
  }
  if (parWidth == undefined) {
    parHeight = 1024;
  }
  document.getElementById("myFlashMovie").width = parWidth;
  document.getElementById("myFlashMovie").height = parHeight;
}
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();
  }
}

