//Preloaded slideshow script- By Jason Moon
//For this script and more
//Visit http://www.dynamicdrive.com

// PUT THE URL'S OF YOUR IMAGES INTO THIS ARRAY...
var Slides = new Array('/images/bg_home_2.jpg','/images/bg_home_3.jpg','/images/bg_home_1.jpg','/images/bg_home_4.jpg','/images/bg_home_5.jpg');
var SlideLinks = new Array('/popups/whatsinthisphoto_2.shtml','/popups/whatsinthisphoto_3.shtml','/popups/whatsinthisphoto_1.shtml','/popups/whatsinthisphoto_4.shtml','/popups/whatsinthisphoto_5.shtml');
//var rotateDelay = 5000; //milliseconds
//var rotator;
var autoSlide = false;

if(Slides.length!=SlideLinks.length){
	alert("ERROR: The number of links must equal the number of images.")	
}


function manualSlide(Direction){
	if(autoSlide){
		clearInterval(rotator);
		autoSlide = false;
	}
	ShowSlide(Direction);
}

// DO NOT EDIT BELOW THIS LINE!
function CacheImage(ImageSource) { // TURNS THE STRING INTO AN IMAGE OBJECT
   var ImageObject = new Image();
   ImageObject.src = ImageSource;
   return ImageObject;
}

function ShowSlide(Direction) {
   if (SlideReady) {
	   if(isNaN(Direction)){
			Direction = 1;		
		}
      NextSlide = CurrentSlide + Direction;
      // THIS WILL DISABLE THE BUTTONS (IE-ONLY)
      //document.SlideShow.Previous.disabled = (NextSlide == 0);
      //document.SlideShow.Next.disabled = (NextSlide == (Slides.length-1));  
	  
	  if (NextSlide >= Slides.length){
		NextSlide=0;  
		clearInterval(rotator);
		autoSlide=false;
	  }
 	  if ((NextSlide >= 0) && (NextSlide < Slides.length)) {
            document.images['Screen'].src = Slides[NextSlide].src;
            CurrentSlide = NextSlide++;
            Message = 'Picture ' + (CurrentSlide+1) + ' of ' + Slides.length;
            self.defaultStatus = Message;
            if (Direction == 1) CacheNextSlide();
      }
	  document.getElementById("whatsinlink").href = SlideLinks[CurrentSlide];
	  document.getElementById("whatsinpic").href = SlideLinks[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);
   rotator = setInterval(ShowSlide,rotateDelay,1);
}
