function SlideShow(id)
{
   this.id = document.getElementById(id);
   this.running = false;
   this.delay = 4000; // milliseconds
   this.pos = 0;
   this.tid = 0;

   // slides are in a child select element with class 'slides'
   var selects = this.id.getElementsByTagName('select');
   for (var i in selects)
   {
      if (selects[i].className == 'slides')
      {
         this.id.slides = selects[i];
         break;
      }
   }

   if (!this.id.slides) throw "No class slides select element found";

   // img is in a child img element with class 'slide'
   var imgs = this.id.getElementsByTagName('img');
   for (i in imgs)
   {
      if (imgs[i].className == 'slide')
      {
         this.id.img = imgs[i];
         break;
      }
   }

   if (!this.id.img) throw "No class slide image element found";
}

SlideShow.prototype.go = function(n)
{
   this.id.slides.options[this.pos = n].selected = true;
   this.id.img.src=this.id.slides.options[n].value;
};

SlideShow.prototype.first = function()
{
   return this.go(0);
};

SlideShow.prototype.last = function()
{
   return this.go(this.id.slides.options.length-1);
};

SlideShow.prototype.back = function()
{
   return (this.pos>0) ? this.go(--this.pos) : this.last();
};

SlideShow.prototype.next = function()
{
   return (this.pos<this.id.slides.options.length-1) ? this.go(++this.pos) : this.first();
};

SlideShow.prototype.play = function()
{
   this.stop();
   this.running=true;
   this.run();
};

SlideShow.prototype.run = function()
{
   var self = this;
   this.tid=setInterval(function() { self.next(); }, this.delay);
};

SlideShow.prototype.pause = function()
{
   if (this.running) { clearTimeout(this.tid); } else { this.run(); }
};

SlideShow.prototype.stop = function()
{
    clearTimeout(this.tid);
    this.first();
};

