photopicker_slideshow = function(showname, image, pics, wait, fade, backbutton, pausebutton, forwardbutton) {

  // 23 Mar 2008 - pass control button object names (for Safari)
  // 21 feb 2008 - remove image sources
  // 26 Nov 2007 - select function added
  // 21 Mar 2006
  //    Firefox requires id attribute on image (not name attribute)
  //    other browsers work with either id or name

  if(navigator.userAgent.indexOf("Opera") != -1)this.is_opera = true;
  else this.is_opera = false;

  // name for this instance
  this.showname = showname;

  // ID of base image tag
  if(image == null)var image = "";
  this.image = image;

  // array of slideshow images
  if(pics == null)var pics = new Array();
  this.pics = pics;

  // interval between slides (milliseconds)
  if(wait == null)var wait = 5000;
  this.wait = wait;

  // cross fade time (seconds)
  if(fade == null)var fade = 3;
  this.fade = fade;

  // controls
  if(backbutton == null)var backbutton = "";
  this.backbutton = backbutton;
  if(pausebutton == null)var pausebutton = "";
  this.pausebutton = pausebutton;
  if(forwardbutton == null)var forwardbutton = "";
  this.forwardbutton = forwardbutton;

  this.first = true;

  this.picnum = 1;
  this.loaded_pics = new Array();

  this.running = true;
  this.stepping = false;
  this.reversing = false;
  this.loaded = false;

  if(document.images) {

    // control images
    this.back_normal = new Image();
    this.back_hover = new Image();
    this.back_active = new Image();
    this.pause_normal = new Image();
    this.pause_hover = new Image();
    this.pause_active = new Image();
    this.forward_normal = new Image();
    this.forward_hover = new Image();
    this.forward_active = new Image();

  }

  photopicker_slideshow.prototype.preload = function() {

    this.preload = new Array();
    for(i=0;i<this.pics.length;i++) {
      this.preload[i] = new Image();
      if(document.all && !this.is_opera && this.fade > 0) {
        this.preload[i].src = this.pics[i];
      }
    }

  }

  photopicker_slideshow.prototype.start = function() {

    eval("this.loaded = setInterval('" + this.showname + ".run()'," + this.showname + ".wait)");

  }

  photopicker_slideshow.prototype.run = function() {

    if(this.pics.length > 0 && (this.running || this.stepping )) {

      this.stepping = false;
      var basepic = document.getElementById(this.image);

      if(document.all && !this.is_opera && this.fade > 0) {

        basepic.style.filter="blendTrans(duration=this.fade)";
        basepic.filters.blendTrans.Apply();
        basepic.src = this.preload[this.picnum].src;
        basepic.filters.blendTrans.Play();
      }

      else {

        if(!this.loaded_pics[this.picnum]) {
          this.preload[this.picnum].src = this.pics[this.picnum];
          this.loaded_pics[this.picnum] = true;
        }
        basepic.src = this.pics[this.picnum];

      }

      if(this.reversing) {
        this.picnum--;
        if(this.picnum < 0)this.picnum = this.pics.length-1;
      }

      else {
        this.picnum++;
        if(this.picnum == this.pics.length)this.picnum = 0;
      }

    }

  }

  photopicker_slideshow.prototype.step = function() {

    this.stepping = true;
    this.run();

  }

  photopicker_slideshow.prototype.forward = function() {

    if(this.reversing) {
      this.picnum++;
      if(this.picnum == this.pics.length)this.picnum = 0;
      this.picnum++;
      if(this.picnum == this.pics.length)this.picnum = 0;
    }
    this.reversing = false;
    this.run();

  }

  photopicker_slideshow.prototype.reverse = function() {

    if(!this.reversing) {
      this.picnum--;
      if(this.picnum < 0)this.picnum = this.pics.length-1;
      this.picnum--;
      if(this.picnum < 0)this.picnum = this.pics.length-1;
    }
    this.reversing = true;
    this.run();

  }

  photopicker_slideshow.prototype.select = function(number) {
    if(this.loaded) {
      this.picnum = number;
      if(this.picnum < 0)this.picnum = this.pics.length;
    }
  }

  // control functions

  if(document.images) {

    photopicker_slideshow.prototype.back_mouseover = function(back) {
      if(this.loaded) {
        if(!this.reversing || !this.running)document.getElementById(this.backbutton).src = this.back_hover.src;
      }
    }

    photopicker_slideshow.prototype.back_mouseout = function(back) {
      if(this.loaded) {
        if(!this.reversing || !this.running)document.getElementById(this.backbutton).src = this.back_normal.src;
      }
    }

    photopicker_slideshow.prototype.back_click = function(back, pause, forward) {
      if(this.loaded) {
        clearInterval(this.loaded);
        if(this.first)this.running = true;
        this.reverse();
        document.getElementById(this.backbutton).src = this.back_active.src;
        if(this.running)document.getElementById(this.pausebutton).src = this.pause_normal.src;
        else document.getElementById(this.pausebutton).src = this.pause_active.src;
        document.getElementById(this.forwardbutton).src = this.forward_normal.src;
        if(!this.running)this.step();
        if(!this.stepping)eval("this.loaded = setInterval('" + this.showname + ".run()'," + this.showname + ".wait)");
      }
    }

    photopicker_slideshow.prototype.pause_mouseover = function(pause) {
      if(this.loaded) {
        if(this.running)document.getElementById(this.pausebutton).src = this.pause_hover.src;
      }
    }

    photopicker_slideshow.prototype.pause_mouseout = function(pause) {
      if(this.loaded) {
        if(this.running)document.getElementById(this.pausebutton).src = this.pause_normal.src;
      }
    }

    photopicker_slideshow.prototype.pause_click = function(back, pause, forward) {
      if(this.loaded) {
        clearInterval(this.loaded);
        this.first = false;
        if(this.reversing)document.getElementById(this.backbutton).src = this.back_active.src;
        else document.getElementById(this.backbutton).src = this.back_normal.src;
        document.getElementById(this.forwardbutton).src = this.forward_normal.src;
        if(this.running) {
          this.running = false;
          document.getElementById(this.pausebutton).src = this.pause_active.src;
        }
        else {
          this.running = true;
          document.getElementById(this.pausebutton).src = this.pause_hover.src;
        }
        eval("this.loaded = setInterval('" + this.showname + ".run()'," + this.showname + ".wait)");
      }
    }

    photopicker_slideshow.prototype.forward_mouseover = function(forward) {
      if(this.loaded) {
        document.getElementById(this.forwardbutton).src = this.forward_hover.src;
      }
    }

    photopicker_slideshow.prototype.forward_mouseout = function(forward) {
      if(this.loaded) {
        document.getElementById(this.forwardbutton).src = this.forward_normal.src;
      }
    }

    photopicker_slideshow.prototype.forward_click = function(back, pause, forward) {
      if(this.loaded) {
        clearInterval(this.loaded);
        if(this.first)this.running = true;
        this.forward();
        document.getElementById(this.backbutton).src = this.back_normal.src;
        if(this.running)document.getElementById(this.pausebutton).src = this.pause_normal.src;
        else document.getElementById(this.pausebutton).src = this.pause_active.src;
        if(this.running)document.getElementById(this.pausebutton).src = this.pause_normal.src;
        else document.getElementById(this.pausebutton).src = this.pause_active.src;
        document.getElementById(this.forwardbutton).src = this.forward_active.src;
        if(!this.running)this.step();
        if(!this.stepping)eval("this.loaded = setInterval('" + this.showname + ".run()'," + this.showname + ".wait)");
      }
    }

  }

}
