/* ***********************************************************
** SLIDE.JS - JS SlideShow Library
** ===============================
** This library contains code to create a simple slideshow.
** It's yours for free, but please maintain this header!
**
** To load this library in an HTML doc, put the following
** line in the doc's HEAD (before any other SCRIPT tags):
**
** <SCRIPT SRC="slide.js" LANGUAGE="JavaScript"></SCRIPT>
**
** Author      Ver  Date    Comments
** ======      ===  ====    ========
** Rick Scott  1.0  1/1/00  First release
**
** Copyright 2000, Rick Scott, all rights reserved.
*********************************************************** */

var CurrSlideIndex = 0;      // index of current SlidesArray[] slide
var IsPlaying      = false;  // the slide show is running
var IsPaused       = false;  // the slide show is paused
var JustStarted    = true;   // the slide show just started

function slideshowStart()  // start/run slide show
  {
  if (document.images[IMGTAGNUM].complete)  // ensure current slide is loaded
    {                                       // before fetching next slide
    if (JustStarted)  // show just starting
      {
      dispSlide(0);
      JustStarted = false;
      document.slideshowForm.slideshowPlayBtn.value = "** Stop **";
      }
    else              // show already running
      {
      slideNext();
      }
    if (document.slideshowForm.slideshowPauseBtn.value == "Resume")
      {
      document.slideshowForm.slideshowPauseBtn.value = "&nbsp;Pause&nbsp;"
      IsPaused = false;
      }
    }
  IsPlaying = true;
  slideTimerID = setTimeout("slideshowStart();", SlideSecs*1000);
  }

function slideshowStop()  // stop slide show
  {
  clearTimeout(slideTimerID);  // stop slide show by stopping setTimeout()
  IsPlaying = false;           // in slideshowStart()
  JustStarted = true;
  document.slideshowForm.slideshowPlayBtn.value = "AutoPlay";
  dispSlide(0);
  }

function slideshowPause()  // pause slide show
  {
  clearTimeout(slideTimerID);  // stop slide show by stopping setTimeout()
  document.slideshowForm.slideshowPauseBtn.value = "Resume"
  IsPaused = true;
  }

function slideshowResume()  // resume slide show (after pausing)
  {
  document.slideshowForm.slideshowPauseBtn.value = "Pause"
  IsPaused = false;
  slideshowStart();  // restart slide show
  }

function doPauseClick()  // process Pause/Resume button click
  {
  if (!IsPlaying)  // don't toggle to "Resume" if show not playing
    return;
  if (!IsPaused)
    slideshowPause()
  else
    slideshowResume();
  }

function doPlayClick()  // process AutoPlay/Stop button click
  {
  if (!IsPlaying)
    slideshowStart();
  else
    slideshowStop();
  if (IsPaused)       // if Resume showing, clicking Stop toggles to Pause
    {
    document.slideshowForm.slideshowPauseBtn.value = "Pause"
    IsPaused = false;
    }
  }

function dispSlide(slideIndex)  // display current slide image/title
  {
  document.currSlide.src = SlidesArray[slideIndex];
  document.slideshowForm.slidetitleTxt.value = SlideTitlesArray[slideIndex];
  CurrSlideIndex = slideIndex;
  }

function slidePrev()  // display previous slide image/title
  {
  CurrSlideIndex = CurrSlideIndex - 1;
  if (CurrSlideIndex < 0)  // at beginning of show
    {
    if (document.slideshowForm.loopChk.checked)  // loop
      {
      dispSlide(SlidesArray.length - 1);
      }
    else  // don't loop
      {
      CurrSlideIndex = 0;
      alert("First slide!\n(Loop show is off.)");
      }
    }
  else  // not at beginning of show
    {
    dispSlide(CurrSlideIndex);
    }
  }

function slideNext()  // display next slide image/title
  {
  CurrSlideIndex = CurrSlideIndex + 1;
  if (CurrSlideIndex > SlidesArray.length - 1)   // at end of show
    {
    if (document.slideshowForm.loopChk.checked)  // loop
      {
      dispSlide(0);
      }
    else  // don't loop
      {
      alert("Last slide!\n(Loop show is off.)");
      CurrSlideIndex = SlidesArray.length - 1;
      if (IsPlaying)  // if in AutoPlay mode, stop it
        setTimeout("slideshowStop()", 250);  // need to delay this a bit ... 
      }
    }
  else  // not at end of show
    {
    dispSlide(CurrSlideIndex);
    }
  }

function slideshowSpeed()  // set show speed on the fly
  {
  var index = document.slideshowForm.speedSelect.selectedIndex;
  SlideSecs = document.slideshowForm.speedSelect.options[index].text;
  }

