var slideSpeed = 9000;
var slideTimer = 0;
var slideNextNdx = 0;
var slideAutoPlay = 0;

var Pic = new Array();
var Cap = new Array();

function S(cat,num) {
   var loc="S.php?cat=" + cat + "&num=" + num;
   window.open(loc,"HFSlideShow","width=520,height=520,directories=0,location=0,status=0,toolbar=0,menubar=0,resizable=1");
   return false;
}

function setSlideIndex(ndx) {
   if (null != ndx) slideNextNdx = ndx;
   if (slideNextNdx < 0) slideNextNdx += Pic.length;
   if (slideNextNdx >= Pic.length) slideNextNdx -= Pic.length;
}

function pauseSlideShow() {
   clearTimeout(slideTimer);
   slideAutoPlay = 0;
   if (document.images.pause)
      document.images.pause.src = 'pausing.gif';
}

function autoplaySlideShow() {
   slideAutoPlay = 1;
   if (document.images.pause)
      document.images.pause.src = 'pause.gif';
}

function backupSlideShow() {
   // slideNextNdx points to next image, back it up two places
   setSlideIndex(slideNextNdx - 2);
   runSlideShow();
}

function setCaption(str) {
   if (document.getElementById && document.getElementById("Caption"))
      document.getElementById("Caption").innerHTML= str;
}

function setPicture(str) {
   if (document.all) {
      document.images.SlideShow.style.filter="blendTrans(duration=1)";
      document.images.SlideShow.filters.blendTrans.Apply();
   }
   document.images.SlideShow.src = str;
   if (document.all) {
      document.images.SlideShow.filters.blendTrans.Play();
   }
}

var slideCache = new Image();
function cacheImage(src) {
   slideCache.src = src;
}

var captimer;
var pictimer;
function runSlideShow(ndx) {
   clearTimeout(slideTimer);
   clearTimeout(captimer);
   clearTimeout(pictimer);

   if (null == ndx)
      autoplaySlideShow();
   else
      pauseSlideShow();

   setSlideIndex(ndx);

   setCaption("&nbsp;");
   captimer = setTimeout('setCaption("' + Cap[slideNextNdx] + '");', 500);

   if (document.all)
      setPicture( Pic[slideNextNdx] );
   else {
      document.images.SlideShow.src = "black.gif";
      pictimer = setTimeout('setPicture("' + Pic[slideNextNdx] + '");', 350);
   }

   setSlideIndex(slideNextNdx + 1);
}

function imageLoaded() {
   // ignore transition graphic
   if ("black.gif" == document.images.SlideShow.src)
      return;
   if (slideAutoPlay) {
      clearTimeout(slideTimer);
      slideTimer = setTimeout('runSlideShow()', slideSpeed);
   }
   cacheImage( Pic[slideNextNdx] );
}
