// photomenu.js

   var RefreshRate = 6;             // Seconds between refresh during slideshow.
   var CrossfadeDuration = 1;
   var CrossfadeDurationSlow = 4;
   var running = false;
   var busy = false;

   function show(id) {
      e = document.getElementById(id);
      if (e) e.style.visibility = "visible";   
   }

   function hide(id) {
      e = document.getElementById(id);
      if (e) e.style.visibility = "hidden";   
   }

   function photoPrev() {
      if (!running && !busy && !crossfadeBusy(document.images.photoslider)) {
         busy = true;
         hide('photoprev');
         hide('photonext');
         prevIndex = index;
         index--;
         if (index < 0) index = images.length - 1;
         setTitle(imageTitle[index], index, images.length);
         setDescription(imageTitle[index]);
         fadeInImage(document.images.photoslider, document.getElementById('photoslider'), images[index], DefaultImageTitle, CrossfadeDuration); 
         busy = false;
         checkReady();      
      }
   }

   function photoNext() {
      if (!running && !busy && !crossfadeBusy(document.images.photoslider)) {
         busy = true;
         hide('photoprev');
         hide('photonext');
         prevIndex = index;
         index++;
         if (index >= images.length) index = 0;
         setTitle(imageTitle[index], index, images.length);
         setDescription(imageTitle[index]);
         fadeInImage(document.images.photoslider, document.getElementById('photoslider'), images[index], DefaultImageTitle, CrossfadeDuration); 
         busy = false;
         checkReady();      
      }
   }

   function photoStop() {
      running = false;
      busy = false;
      index = 0;
   }

   function photoShowNext() {
      if (running) {
         prevIndex = index;
         index++;
         if (index >= images.length) index = 0;
         setTitle(imageTitle[index], index, images.length);
         setDescription(imageTitle[index]);
         fadeInImage(document.images.photoslider, document.getElementById('photoslider'), images[index], 'landschapsfotografie',CrossfadeDurationSlow);
         setTimeout('photoShowNext()', RefreshRate*1000);
      }
   }

   function photoPlay() {
         // Start or pause slide show. 
      if (!running) {
         running = true;
         hide('photoprev');
         hide('photonext');
         show('photopause');
         hide('photoplay');
         photoShowNext();
         checkReady();      
      } else {
         running = false;
         hide('photopause');
      }
   }

   function sendEcard() {
      document.location.href = 'ecard.php?imagename=' + images[index] + '&amp;title=' + imageTitle[index];
   }

   function shopEcard() {
      document.location.href = 'shop.php?imagename=' + images[index] + '&amp;title=' + imageTitle[index];
   }

   function checkReady() {
         // Check whether fade has finished. If so show buttons prev, next and next, hide button pause.
      if (!running && !busy && !crossfadeBusy(document.images.photoslider)) {
         show('photoprev');
         show('photonext');
         show('photoplay');
         hide('photopause');
      } else {
         setTimeout('checkReady()', 100);
      }
   }

