// Two objects defined in this file:
// "slide" - contains all the information for a single slide
// "slideshow" - consists of multiple slide objects and runs the slideshow

//==================================================
// slide object
//==================================================
function Slide(src,link) {
  // This is the constructor function for the slide object.
  // It is called automatically when you create a new slide object.
  // For example: s = new slide();

	this.src = src;
	this.link = link;
	this.image = new Image();

  //--------------------------------------------------
  this.load = function() {
     //This method loads the image for the slide

    if ( !document.images ) { return; }
    this.image.src = this.src;
  }

  //--------------------------------------------------
  this.hotlink = function() {
    // This method jumps to the slide's link.

    if ( !this.link ) return;// If this slide does not have a link, do nothing
	window.open( this.link,"_blank" );
	}
}

//==================================================
// slideshow object
//==================================================
function SlideShow( slideshowname ) {
  // This is the constructor function for the slideshow object.
  // It is called automatically when you create a new object.
  // For example: ss = new slideshow("ss");
  // Name of this object.For example, "SLIDES1"

  this.name = slideshowname;
  this.slides = new Array();
  this.current = 0;

  //--------------------------------------------------
  // Public methods
  //--------------------------------------------------
  this.add_slide = function(slide) {
    // Add a slide to the slideshow.
  
    var i = this.slides.length;
    slide.load();// Prefetch the slide image
    this.slides[i] = slide;
  }

  //--------------------------------------------------
  this.play = function(timeout) {
    // This method implements the automatically running slideshow.

    this.image.src = this.slides[ this.current ].image.src;// Update the image.
	this.timeout = timeout;
    setTimeout( this.name + ".next()", this.timeout);
  }

  //--------------------------------------------------
  this.next = function() {
    // This method advances to the next slide.

    if (this.current < this.slides.length - 1) {
      this.current++;
    } else {
      this.current = 0;
    }
	this.play(this.timeout);
  }

  //--------------------------------------------------
  this.hotlink = function() {
    // This method calls the hotlink() method for the current slide.

    this.slides[ this.current ].hotlink();
  }

  // Declare image object
  //--------------------------------------------------
  this.set_image = function(imageobject) {

    if ( !document.images )
      return;
    this.image = imageobject;
  }
}

