
var ss1;
window.onload = function()
{
  // Create slideshow object
  ss1 = new xSlideShow(6000, 'slideshow1', 'images/',
                       ['homeimage3.jpg', 'homeimage4.jpg','homeimage.jpg', 'homeimage2.jpg'],
                       ['http://www.otcireland.com/product.php?xProd=22&xSec=11', 'http://www.otcireland.com/section.php?xSec=11','http://www.otcireland.com/product.php?xProd=21&xSec=2', 'http://www.otcireland.com/product.php?xProd=20&xSec=11' ],
                       ['OTC1', 'OTC2', 'OTC3', 'OTC4']);


  ss1.start(); // default to Auto - start immediately

  // Initialize buttons
  if (ss1) {
    var b = document.getElementById('btnPrev');
    b.onclick = function() { ss1.prev(); };
    b = document.getElementById('btnAuto');
    b.onclick = function() { ss1.start(); };
    b = document.getElementById('btnNext');
    b.onclick = function() { ss1.next(); };
  }
}
/*
  xSlideShow - A simple slideshow object.

  uInterval  - The time in milliseconds for auto-slide.
  sImgEleId  - The IMG element in the HTML.
  sImagePath - The path to be prepended to each image file name.
               It must have a trailing backslash.
  aFiles     - An array of image file names.
  aLinks     - An optional array of URLs for when the image is clicked.
  aTitles    - An optional array of titles for each image.

  If provided, aLinks and aTitles must have the same length as aFiles.
*/

function xSlideShow(uInterval, sImgEleId, sImagePath, aFiles, aLinks, aTitles)
{
  // Private Properties

  var ths = this;
  var tmr = null;
  var idx = -1;
  var imgs = []; // zero-based

  // Private Methods

  function run()
  {
    tmr = setTimeout(run, uInterval);
    ths.next(true);
  }

  function onClick()
  {
    // note: In this function, 'this' points to the IMG object
    var t = aTitles ? aTitles[idx] + ': ' : '';
     {
      window.location = aLinks[idx];
    }
  }

  // Public Methods

  this.start = function()
  {
    if (tmr == null) {
      run();
    }
    else {
      this.stop(); // implements a 'toggle'
    }
  };

  this.stop = function()
  {
    if (tmr != null) {
      clearTimeout(tmr);
      tmr = null;
    }
  };

  this.next = function(bRunning)
  {
    var i = document.getElementById(sImgEleId);
    if (i) {
      if (!bRunning) {
        // stop auto-slide unless next() is called from run()
        this.stop();
      }
      if (++idx >= imgs.length) {
        idx = 0;
      }
      i.src = imgs[idx].src;
      if (aTitles) {
        i.title = aTitles[idx];
      }
    }
  };

  this.prev = function()
  {
    var i = document.getElementById(sImgEleId);
    if (i) {
      this.stop(); // stop auto-slide
      if (--idx <= 0) {
        idx = imgs.length - 1;
      }
      i.src = imgs[idx].src;
      if (aTitles) {
        i.title = aTitles[idx];
      }
    }
  };

  this.onunload = function()
  {
    var i = document.getElementById(sImgEleId);
    if (i) {
      i.onclick = null;
    }
    ths = null;
  };

  // Constructor Code

  var i;
  i = document.getElementById(sImgEleId);
  if (i) {
    if (aLinks) {
      i.onclick = onClick;
    }
    for (i = 0; i < aFiles.length; ++i) {
      imgs[i] = new Image();
      imgs[i].src = sImagePath + aFiles[i];
    }
    this.next(true); // show first image
  }
  else return null; // error
}
// end xSlideShow Object Prototype
