//Preloaded slideshow script- By Jason Moon
//For this script and more
//Visit http://www.dynamicdrive.com

// DO NOT EDIT BELOW THIS LINE!
function CacheImage(ImageSource) { // TURNS THE STRING INTO AN IMAGE OBJECT
   var ImageObject = new Image();
   ImageObject.src = ImageSource;
   ImageObject.onload = onloadHandler;
   return ImageObject;
}

function onloadHandler()
{
    var height=Slides[CurrentSlide].height;
    var width=Slides[CurrentSlide].width;
    if((height>480)||(width>640))
    {
        var scale=Math.min(480/height,640/width);
        if(scale<1)
        {
        height=Math.floor(scale*height);
        width=Math.floor(scale*width);
        }
        if(height==0)
        {
        height=480;
        }
        if(width==0)
        {
        width=640;
        }
        Screen=document.getElementById("Screen");
        Screen.height=height;
        Screen.width=width;
    }
}

function ShowSlide(Direction) {
   if (SlideReady) {
      NextSlide = CurrentSlide + Direction;
      document.getElementById('Previous').disabled = (NextSlide == 0);;
      document.getElementById('Next').disabled = (NextSlide ==(Slides.length-1));
       if ((NextSlide >= 0) && (NextSlide < Slides.length)) {
            var scale=Math.min(480/Slides[NextSlide].height,640/Slides[NextSlide].width);
            var height=Slides[NextSlide].height;
            var width=Slides[NextSlide].width;
            if(scale<1)
            {
            height=Math.floor(scale*height);
            width=Math.floor(scale*width);
            }
            if(height==0)
            {
                height=480;
            }
            if(width==0)
            {
                width=640;
            }
            Screen=document.getElementById("Screen");
            Screen.src = Slides[NextSlide].src;
            Screen.height=height;
            Screen.width=width;
            CurrentSlide = NextSlide++;
            Message = 'Picture ' + (CurrentSlide+1) + ' of ' +
                Slides.length;
            self.defaultStatus = Message;
            if (Direction == 1) CacheNextSlide();
            document.getElementById("CurrentSlide").value=CurrentSlide;
      }
      return true;
   }
}

function Download() {
   if (Slides[NextSlide].complete) {
      SlideReady = true;
      self.defaultStatus = Message;
   }
   else setTimeout("Download()", 100); // CHECKS DOWNLOAD STATUS EVERY 100 MS
   return true;
}

function CacheNextSlide() {
   if ((NextSlide < Slides.length) && (typeof Slides[NextSlide] == 
'string'))
{ // ONLY CACHES THE IMAGES ONCE
      SlideReady = false;
      self.defaultStatus = 'Downloading next picture...';
      Slides[NextSlide] = CacheImage(Slides[NextSlide]);
      Download();
   }
   return true;
}

function StartSlideShow() {
   CurrentSlide=-1;
   Slides[0] = CacheImage(Slides[0]);
   SlideReady = true;
   ShowSlide(1);
}

window.onload=new Function("if(document.getElementById('Screen')!=null){StartSlideShow();}")

