/* /includes/slideShow.js

   This file requires a photo array defined in the variable photo.
   For the home page, this file is: "/includes/photos.js"

   This file is used in the /default.shtml /Waynesboro/default.shtml and /Thomson/default.shtml pages
   
   Modified by James B. Gilbert
   Added a check for the SlideShow img to avoid errors being displayed.
*/

//Declare Variables
var Speed;
var Fade;
var t;
var j;
var i;
var p;
var preLoad;
var altTags;
var numRandomIter;

function sortRandomly(a, b)
{
 numRandomIter++;
 if ( numRandomIter > 100 )
  return false;
 if ( Math.random() > 0.5 )
  return true;
 return false;
}

function prepSlideShow() {
 //Do we have a "SlideShow" on this page?
 if ( document.getElementsByName( "SlideShow" ).length == 0 )
 	return;

 //Assign Variable Values
 Speed = 6000;
 Fade = 3;
 j = 1;
 numRandomIter = 0;
 preLoad = new Array();

 p = photo.length;

 //Randomize Images 
 photo.sort( sortRandomly );

 //Load Images
 for (i = 0; i < p; i++) {
  preLoad[i] = new Image();
  preLoad[i].src = photo[i];
 }
 
 //Start the show
 t = setTimeout('PhotoShow()', Speed );
}

function PhotoShow() {
 //Do we have a "SlideShow" on this page?
 if ( document.getElementsByName( "SlideShow" ).length == 0 )
 	return;

 var slideShowNode = document.getElementsByName( "SlideShow" )[0];
 if (document.all) {
  slideShowNode.style.filter="blendTrans(duration=2)";
  slideShowNode.style.filter="blendTrans(duration=Fade)";
  slideShowNode.filters.blendTrans.Apply();
 }
 slideShowNode.src = preLoad[j].src;
 if (document.all) {
  slideShowNode.filters.blendTrans.Play();
 }
 j = j + 1;
 if (j > (p - 1)) j = 0;
  t = setTimeout('PhotoShow()', Speed);
}