/********************************************************************
 * Name: slideshow.js
 * Version: 0.2
 * Description: Simple script to flick through a series of images.
 * Author: adapted by Ross Kendall (based off some old code floating on the interweb)
 * Created: 2006-03-08
 * Updated: 2007-09-21
 * 
 */



/***** Example of how to use this script *****
 * (insert following in web page...)

<img name="SlideShow1" width="438" height="200" src="/images/banner-1_438x200.jpg" />

<script language="JavaScript" type="text/javascript">

  // Image Name (must match 'name' attribute of img tag)
  var imgName = 'SlideShow1';

  // Specify the image files (make sure they are all the same size!)
  var aPic = new Array();
  // to add more images, just continue the pattern, adding to the array below
  aPic[0] = '/images/banner-2_438x200.jpg';
  aPic[1] = '/images/banner-3_438x200.jpg';
  aPic[2] = '/images/banner-4_438x200.jpg';
  aPic[3] = '/images/banner-1_438x200.jpg';  // go back to starting image

  // Set slideShowSpeed (milliseconds)
  var slideShowSpeed = 6000;

  // Duration of crossfade (seconds) - IE only
  var crossFadeDuration = 3;

  // ...and go!
  slideShow(imgName ,aPic, slideShowSpeed, crossFadeDuration);

</script>


 ***** End of example *****/




function slideShow(imgName ,aPic, slideShowSpeed, crossFadeDuration) {

  var ap = aPic.length;

  var preLoada = new Array();

  for (ai = 0; ai < ap; ai++){
    preLoada[ai] = new Image();
    preLoada[ai].src = aPic[ai];
  }
  
  var thisSlideShow = runSlideShow(imgName, slideShowSpeed, 1, ap, preLoada, crossFadeDuration);
  
  timoutId = setTimeout(thisSlideShow, slideShowSpeed);
  
} // end slideShow()


function runSlideShow(imgName, slideShowSpeed, aj, ap, preLoada, crossFadeDuration){

  return (function(){
   if (document.all){
      document['images'][imgName]['style'].filter = "blendTrans(duration=2)";
      document['images'][imgName]['style'].filter = "blendTrans(duration=crossFadeDuration)";
      document['images'][imgName]['filters'].blendTrans.Apply();
   }
   document['images'][imgName].src = preLoada[aj-1].src;
   if (document.all){
      document['images'][imgName]['filters']['blendTrans'].Play();
   }
   aj = aj + 1;
   if (aj > (ap)) aj=1;

   var thisSlideShow = runSlideShow(imgName, slideShowSpeed, aj, ap, preLoada, crossFadeDuration);
   timoutId = setTimeout(thisSlideShow, slideShowSpeed);
  });
  
}

