if (document.getElementById) {navigator.family="gecko";}

var curImg = 0;
var timerId = -1;
var secTimerId = -1;
var interval = 6000;
var secInterval = interval / 1000;
var currSec = secInterval;
var copyType = "";
var isPlaying = 1;

function replaceNum()
{
  var input = SHOWINGSTRING;
  var output = input;
  var idx = output.indexOf("%slideNum");
  if (idx > -1) {
    output = input.substring(0, idx);
    output += eval(curImg+1);
    output += input.substr(idx+9);
  }
  return output;
}

function changeSpeed()
{
  var sidx = document.fSlideshow.speedMenu.selectedIndex;
  var speed = document.fSlideshow.speedMenu.options[sidx].value;

  interval = speed;
  secInterval = interval / 1000;

  if (timerId != -1) {
    clearTimers();
  }

  play();
}

function imgLoadNotify()
{
  if (isPlaying == 1)
    setTimers();
}

function changeSlide()
{
  var width = a_width[curImg];
  var height = a_height[curImg];
  if (timerId != -1) {
    clearTimers();
    dispLoading();
  }

  var tableWidth = ( width < 400 || height > 400 ) ? 776 : width;

  var html = "<center><table width=" + tableWidth + " cellpadding=3 cellspacing=10 border=0><tr><td valign=top>" +
      "<img src=" + a_src[curImg] + " alt=\"photo\" width=" + width +
      " height=" + height + " border=1 onload=\"imgLoadNotify();\">";

  if ( width < 400 || height > 400 ) {
    html += "</td><td valign=top>";
  } else {
    html += "<br/><br/>";
  }

  html += "<font face=arial size='-1'>" + a_cap[curImg] + "</font><br><span class=\"ysptimedate\">" + a_credit[curImg] + "</span></td></tr></table></center>";

  var pnumLine = "<font face=arial size=-1>";
  pnumLine += replaceNum();
  pnumLine += "</font>";


  var htmlTs = a_ts[curImg];
  var htmlCopy = PROVIDER_TO_COPYRIGHT[a_copy[curImg]];

  parent.copyright.location = "/s/slideshow_copyright?prov=" + a_copy[curImg];

  switch(navigator.family) {
    case 'gecko':
      document.getElementById("imgDiv").innerHTML = html;
      document.getElementById("pnumDiv").innerHTML = pnumLine;
      document.getElementById("tsDiv").innerHTML = htmlTs;
      document.getElementById("copyDiv").innerHTML = htmlCopy;
      break;
    case 'nn4':
      document.layers[2].document.imgDiv.document.open();
      document.layers[2].document.imgDiv.document.write(html);
      document.layers[2].document.imgDiv.document.close();

      document.layers[0].document.pnumDiv.document.open();
      document.layers[0].document.pnumDiv.document.write(pnumLine);
      document.layers[0].document.pnumDiv.document.close();

      document.layers[3].document.tsDiv.document.open();
      document.layers[3].document.tsDiv.document.write(htmlTs);
      document.layers[3].document.tsDiv.document.close();

      document.layers[4].document.copyDiv.document.open();
      document.layers[4].document.copyDiv.document.write(htmlCopy);
      document.layers[4].document.copyDiv.document.close();
      break;
    case 'ie4':
      document.all.pem.innerHTML = pnumLine;
      document.all.imgp.innerHTML = html;
      document.all.tstxt.innerHTML = htmlTs;
      document.all.copytxt.innerHTML = htmlCopy;
      break;
  }
}

function forward()

{
  curImg++;
  if (curImg == numImgs) 
    curImg = 0;
  changeSlide();


}

function rewind()
{
  curImg--;
  if (curImg < 0) 
      curImg = numImgs - 1;
  changeSlide();
}

function dispSec()
{
  var dispSec = ( currSec < 0 ) ? 0 : currSec;
  var secText = "<font face=arial color=green size=-2>Next slide in " + dispSec + " sec</font>";

  switch(navigator.family) {
    case 'gecko':
      document.getElementById("timerDiv").innerHTML = secText;
      break;
    case 'nn4':
      document.layers[1].document.timerDiv.document.open();
      document.layers[1].document.timerDiv.document.write(secText);
      document.layers[1].document.timerDiv.document.close();
      break;
    case 'ie4':
      document.all.timer.innerHTML = secText;
      break;
  }

  currSec--;
}


function dispLoading()
{
  var text = "<font face=arial color=green size=-2>Loading image...</font>";

  switch(navigator.family) {
    case 'gecko':
      document.getElementById("timerDiv").innerHTML = text;
      break;
    case 'nn4':
      document.layers[1].document.timerDiv.document.open();
      document.layers[1].document.timerDiv.document.write(text);
      document.layers[1].document.timerDiv.document.close();
      break;
    case 'ie4':
      document.all.timer.innerHTML = text;
      break;
  }
}

function stop()
{
  clearTimers();

  isPlaying = 0;

  var secText = "<font face=arial color=red size=-2>Slideshow Stopped</font>";

  switch(navigator.family) {
    case 'gecko':
      document.getElementById("timerDiv").innerHTML = secText;
      break;
    case 'nn4':
      document.layers[1].document.timerDiv.document.open();
      document.layers[1].document.timerDiv.document.write(secText);
      document.layers[1].document.timerDiv.document.close();
      break;
    case 'ie4':
      document.all.timer.innerHTML = secText;
      break;
  }

  document.playbtn.src = buttonImgPfx + buttonOffArray[0];
  document.stopbtn.src = buttonImgPfx + buttonOnArray[1];
}

function play()
{
  setTimers();
  startShow();
}

function startShow()
{
  isPlaying = 1;

  document.playbtn.src = buttonImgPfx + buttonOnArray[0];
  document.stopbtn.src = buttonImgPfx + buttonOffArray[1];
}

function setTimers()
{
  currSec = secInterval;
  dispSec();

  if (secTimerId == -1)
    secTimerId = window.setInterval('dispSec();', 1000);
  if (timerId == -1)
    timerId = window.setInterval('forward();', interval);
}

function clearTimers()
{
  window.clearInterval(timerId);
  timerId = -1;
  window.clearInterval(secTimerId);
  secTimerId = -1;
}

function setButton(direction)
{
  if (direction == 0) {
    document.prevbtn.src = buttonImgPfx + buttonOnArray[2];
    window.setTimeout("document.prevbtn.src = buttonImgPfx + buttonOffArray[2];", 300);
  } else {
    document.fowdbtn.src = buttonImgPfx + buttonOnArray[3];
    window.setTimeout("document.fowdbtn.src = buttonImgPfx + buttonOffArray[3];", 300);
  }
}

