// BEGIN Slideshow v1.01 functions
//
// Set up preloaded images array with blank strings
var preloadedimages=new Array();
for (i=0;i<photos.length;i++) {
  preloadedimages[i]="hi";
}

function CacheImage(ImageSource) { // TURNS THE STRING INTO AN IMAGE OBJECT
  var ImageObject = new Image();
  ImageObject.src = ImageSource;
  return ImageObject;
}

function CacheNextSlide() {
  if ((which < photos.length) && (typeof preloadedimages[which] == 'string')) {
    // ONLY CACHES THE IMAGES ONCE
    SlideReady = false;
    window.status = 'Downloading next picture...';
    imagecount.innerText = 'Downloading';
    preloadedimages[which] = CacheImage(photos[which]);
    Download();
  }
  return true;
}

function Download() {
  if (preloadedimages[which].complete) {
    SlideReady = true;
  }
  else setTimeout("Download()", 100); // CHECKS DOWNLOAD STATUS EVERY 100 MS
  keeptrack();
  return true;
}

function applyeffect() {
  if (document.all && (document.slideshow.fancyswitch.checked==true)) {
    effect=0;
    while (effect == 0 || effect == 2 || effect == 13) { effect=Math.floor(Math.random()*23); }
    photoslider.filters.revealTrans.Transition=effect;
    photoslider.filters.revealTrans.stop();
    photoslider.filters.revealTrans.apply();
  }
}

function playeffect() {
  if (document.all && (document.slideshow.fancyswitch.checked==true)) { photoslider.filters.revealTrans.play(); }
}

function keeptrack() {
  window.status="Image "+(which+1)+" of "+photos.length;
  if (document.all) {
    document.slideshow.Previous.disabled = (which == 0);
    document.slideshow.Next.disabled = (which == ((photos.length)-1));    
    imagecount.innerText="Image "+(which+1)+" of "+photos.length;
  }
  if (showdescriptions==1) {
    document.slideshow.desc.value=photosdesc[which];
  }
}

function slidechange(towhere) {
  if (SlideReady) {
    switch (towhere) {
      case 1 : // First - not used
        which=0; break;
      case 2 : // Previous
        if (which>0) { which--; } break;
      case 3 : // Next
        if (which<photos.length-1) { which++; }
        CacheNextSlide();
        break;
      case 4 : // Last - not used
        // must add cache code if you start using first and last slidechange
        which=photos.length-1; break;
    }
    applyeffect();
    document.images.photoslider.src=photos[which];
    playeffect();
    keeptrack();
  }
}

function transport() { window.location=photoslink[which]; }
//
// END Slideshow functions
