// Title: slideshow
// Description: See the demo at url
// URL: http://www.danielbanks.net/
// Version: 1.0
// Date: 08-28-2003 (mm-dd-yyyy)
// Author: Gary Jaspersohn <jaspersohn@hotmail.com>
// Notes: registration by sending e-mail to author needed to use this script on your web site.
// 	Registration for this version (1.0) is free of charge.

// -----------------------------------------------------------------------------------
// These JavaScript Functions operate on 2 arrays required to be defined on web page
// il = Image List   (images are assumed to be in the 'pic' subdirectory)   (Required)
//      image 'name' will be converted to the filename format "pic/name.jpg"
// cl = Comment List (HTML formatted text associated with each image above) (Required)
// -----------------------------------------------------------------------------------

var delay = 5000;
var timer = "";
var slideshow_on = 0;

totpix = il.length;
ssarr = new Array(); for(a=0;a<totpix;a++) ssarr[a]=a;
ind = -1;

function writit(text,id)
{
  if (document.getElementById)
  {
    x = document.getElementById(id);
    x.innerHTML = '';
    x.innerHTML = text;
  }
  else if (document.all)
  {
    x = document.all[id];
    x.innerHTML = text;
  }
  else if (document.layers)
  {
    x = document.layers[id];
    x.document.open();
    x.document.write(text);
    x.document.close();
  }
}

function setspeed(n)
{
  delay = n * 1000;
  if(slideshow_on==1) {
    clearTimeout(timer);
    timer = setTimeout("showNext(-1)", delay/2);
  }
}

function play()
{
  if(slideshow_on==0) {
    slideshow_on = 1;
    clearTimeout(timer);
    timer = setTimeout("showNext(-1)", 1);
    writit("Playing . . .",'playstat');
  }
}

function pause()
{
  if(slideshow_on==1) {
    slideshow_on = 0;
    clearTimeout(timer);
    writit("Paused . . .",'playstat');
  }
}

function showPrev()
{
  ind = ind-1;
  if(ind<0) ind = totpix-1;
  showNext(ind);
}

function showNext(i)
{
  ind = (i==-1) ? ind+1 : i;
  if(ind>=ssarr.length) ind = 0;
  trg = il[ssarr[ind]];
  document.images["image"].src = "pic/"+trg+".jpg";
  txt = (!cl[ssarr[ind]]) ? trg : cl[ssarr[ind]];
  ftxt = "<B>"+txt+"</B>";
  writit(ftxt,'comment');
  num = ind+1;
  ftxt = "Slide "+num+" of "+totpix;
  writit(ftxt,'slidenum');
  if(slideshow_on==1) {
    clearTimeout(timer);
    timer = setTimeout("showNext(-1)", delay);
  }
  return stat('restore');
}

var laststat = "";
function stat(s) {
  if(s=="restore") s = laststat;
  laststat = s;
  window.status = s;
  return true;
}
