// JavaScript Document
// you set these up:

var showSeconds = 5;

// these belong to the program:

var limitShow = -1;  // max message number
var iShow = limitShow;               // current message number
var tShow = showSeconds*1000;        // show time in milliseconds
var incrShow = 1;                    // needed for reverse (-1)
var running = true;                  // flipping (true) or paused (false)
var timerID = 'ss';                  // needed to ID your timer
var limitShow=0;
var iShow = limitShow;

function initializeTheShow(countDivs) {
   if (typeof countDivs == 'undefined') {

     // NOTICE:  Currently, this code is inoperable ... please count your div's & pass that value
      limitShow=-1;
      for (var i=0;i<document.form.elements.length;i++) {
         if (document.form.elements[i].type == 'div' && document.form.elements[i].name == 'theShow') limitShow++;
         alert('initialize is counting, limitShow = '+limitShow);
      }
     //

   } else {
      limitShow = countDivs*1 - 1
   }
   iShow = limitShow;
   swapTheShow();
}

function swapTheShow() {
  // hide the current
  document.getElementById('theShow'+iShow).style.display = 'none';
  iShow += incrShow;
  if (iShow > limitShow) iShow = 0;
  if (iShow < 0) iShow = limitShow;
   // show the next
  document.getElementById('theShow'+iShow).style.display = 'block';
  if (running) timerID = setTimeout(swapTheShow, tShow);
}

function toggleAuto() {
   timerID = clearTimeout(timerID);
   running=!running;
   if (running) {
      document.getElementById('playPause').innerText = 'PAUSE';
      swapTheShow();
   } else {
      document.getElementById('playPause').innerText = ' PLAY ';
   }
}

function showDirection(direction) {
   incrShow = (direction=='R')?-1:1;
   timerID = clearTimeout(timerID);
   swapTheShow();
}