var iss;
var jss = 0;
var pss = Picture.length-1;

var preLoad = new Array();
for (iss = 1; iss < pss+1; iss++) {
  preLoad[iss] = new Image();
  preLoad[iss].src = Picture[iss];
}

var manual = true;
var CrossFadeDuration = 2;

function control(how) {
  var stop = false;
  if (how=="A") { jss = jss + 1; }
  if (how=="F") { jss = jss + 1; if (!manual) stop = true; }
  if (how=="B") { jss = jss - 1; if (!manual) stop = true; }
  if ((jss == pss) && !manual) stop = true;
  if (jss > (pss)) jss=1;
  if (jss < 1) jss = pss;
  if (document.all) {
    document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
    document.images.PictureBox.filters[0].Apply();
  }
  document.images.PictureBox.src = preLoad[jss].src;
  if (document.getElementById) document.getElementById("CaptionBox").innerHTML = Caption[jss];
  if (document.all) document.images.PictureBox.filters[0].Play();
  if (stop)
    doPlay();
  return stop;
}

function doPlay() {
  if (document.getElementById) document.getElementById("Play").value=manual?" || ":" > ";
  if (manual)
    startTimer();
  else
    stopTimer();
  manual = !manual;
}

var timerID = 0;
var tStart = null;

function startTimer() {
  control("A");
  tStart = new Date();
  timerID = setTimeout("updateTimer()", 1000);
}

function stopTimer() {
  clearTimer();
  tStart = null;
}

function clearTimer() {
  if (timerID) {
    clearTimeout(timerID);
    timerID = 0;
  }
}

function updateTimer() {
  var stop = false;
  clearTimer();
  var tDate = new Date();
  var tDiff = tDate.getTime() - tStart.getTime();
  tDate.setTime(tDiff);
  if (tDate.getSeconds() >= SlideshowSpeed[jss]) {
    tStart = new Date();
    stop = control("A");
  }
  if (!stop)
    timerID = setTimeout("updateTimer()", 1000);
}