// =======================================
// The following vars should be defined and initialized prior to this script being loaded
//   iFirstChangeSpeed ..... speed of initial slide change (milliseconds)
//   iSlideShowSpeed ....... speed of subsequent slide changes (milliseconds)
//   iCrossFadeDuration .... duration of crossfade (seconds)
//   iImageTagCount ........ count of image tags to randomly cycle
//   aImageFileName ........ array of image names to cycle through
var i;
var iImageCount = aImageFileName.length;

var aPreLoadedImage = new Array();
for (i = 0; i < iImageCount; i++)
{
  aPreLoadedImage[i] = new Image();
  aPreLoadedImage[i].src = aImageFileName[i];
}

var aSlideCurrentImage = new Array();
for (i = 0; i < iImageTagCount; i++)
{
  aSlideCurrentImage[i] = i;
}

var iPreviousSlideFlipped = 99;

// =======================================
if (document.all && !document.getElementById)
{
  document.getElementById = function(id) { return document.all[id]; }
}
// =======================================

function iRandomNum(iMinVal, iMaxVal)
{
  var iRanNum = Math.floor(Math.random() * (iMaxVal - iMinVal + 1)) + iMinVal;

  return iRanNum;
}

function imageAlreadyShowing(iNumToCheck)
{
  for (i = 0; i < iImageTagCount; i++)
  {
    if (aSlideCurrentImage[i] == iNumToCheck) return true;
  }

  return false;
}

function flipOneSlide(iSlideNum)
{
  var sSlideID = "slide" + iSlideNum;
  var iNewImageNum;

  do
  {
    iNewImageNum = iRandomNum(0, iImageCount - 1)
  } while (imageAlreadyShowing(iNewImageNum));

  if (document.all)
  {
    document.getElementById(sSlideID).style.filter = "blendTrans(duration=iCrossFadeDuration)";
    document.getElementById(sSlideID).filters.blendTrans.Apply();
  }

  document.getElementById(sSlideID).src = aPreLoadedImage[iNewImageNum].src;

  if (document.all)
  {
    document.getElementById(sSlideID).filters.blendTrans.Play();
  }

  aSlideCurrentImage[iSlideNum] = iNewImageNum;
  iPreviousSlideFlipped = iSlideNum;
}

function runSlideShow()
{
  var iSlideToFlip;

  do
  {
    iSlideToFlip = iRandomNum(0, iImageTagCount - 1)
  } while (iSlideToFlip == iPreviousSlideFlipped);

  flipOneSlide(iSlideToFlip);
  i = setTimeout("runSlideShow()", iSlideShowSpeed);
}
  
function timedSlideShow()
{
  i = setTimeout("runSlideShow()", iFirstChangeSpeed);
}
