var time_delay = 3000 // default display time in milliseconds
function reset_delay() {
   window.alert("Delay must be an integer from 1 to 30");
   slidesform.delay.value = time_delay/3000;
};
function set_delay (entry) {
// note that entire control object is passed as parameter
var strlen = entry.length;
for (var i = 0; i < strlen; i++ ) {
    if ('0123456789'.indexOf(entry.charAt(i)) < 0) {reset_delay(); return};
    };
if (entry<01) {reset_delay(); return};
if (entry>30) {reset_delay(); return};
slidesform.delay.value = entry;   // displayed value in seconds
time_delay = entry * 1000;        // actual delay must be in milliseconds
};
function slide(image_url,link,text,window,attr) {
  this.image = new Image();
  this.image.src = image_url;
  this.link = link;
  this.text = text;
  this.window_name = window;
  this.window_attr = attr;
  this.hotlink = slide_hotlink;
};
function slide_hotlink() {
// If a window name was specified, open a new window
if (this.window_name) {
    // If window attributes are specified, use them to open the new window
    if (this.window_attr) {
      window.open(this.link, this.window_name, this.window_attr);
    // If window attributes are not specified, do not use them
    // (this will copy the attributes from the originating window)
    } else {
      window.open(this.link, this.window_name);
    }
    // Else open the hotlink in the current window
  } else {location.href = this.link};
};
function slideshow(slideshowname) {
  this.name = slideshowname;
  this.image;
  this.textarea;
  this.timeout = time_delay;
  this.slides = new Array();
  this.current = 0;
  this.timeoutid = 0;
  this.add_slide = slideshow_add_slide;
  this.set_image = slideshow_set_image;
  this.set_textarea = slideshow_set_textarea;
  this.play = slideshow_play;
  this.pause = slideshow_pause;
  this.next = slideshow_next;
  this.previous = slideshow_previous;
  this.get_text = slideshow_get_text;
  this.display_text = slideshow_display_text;
  this.hotlink = slideshow_hotlink;
  this.loop = slideshow_loop;
  this.valid_image = slideshow_valid_image;
};
function slideshow_add_slide(slide) {
// for example: SLIDES1.add_slide(new slide("s1.jpg", "link.html", "text"))
// If this version of JavaScript does not allow us to
// change images, then we can't do the slideshow.
  if (!document.images) {return};
  var i = this.slides.length;
  this.slides[i] = slide;
};
function slideshow_set_textarea(textareaobject) {
  this.textarea = textareaobject;
  this.display_text();
};
function slideshow_set_image(imageobject) {
  // If this version of JavaScript does not allow us to
  // change images, then we can't do the slideshow.
  if (!document.images) {return};
  // Set the "image" property of the slideshow object.
  this.image = imageobject;
};
function slideshow_valid_image() {
// Returns 1 if a valid image has been set for the slideshow
  if (!this.image)
  {
    // Stop the slideshow
    this.pause;
    // Display an error message
    window.status = "Error: slideshow image not initialized for "+this.name;
    return 0;
  }
  else
    return 1;
};
function slideshow_hotlink() {
// windowattributes can be:
// width=n,height=n,resizable=yes or no,scrollbars=yes or no,
// toolbar=yes or no,location=yes or no,directories=yes or no,
// status=yes or no,menubar=yes or no,copyhistory=yes or no
  this.slides[this.current].hotlink();
}
function slideshow_next() {
  if (! this.valid_image()) return;
  // Increment the image number
  if (this.current < this.slides.length - 1)
    this.current++;
  else
    this.current = 0;
  // Change the image.
  this.image.src = this.slides[this.current].image.src;
  // Change the text
  this.display_text();
}

function slideshow_previous() {
  if (! this.valid_image()) return;
  // Decrement the image number
  if (this.current > 0)
    this.current-- ;
  else
    this.current = this.slides.length - 1;
  // Change the image.
  this.image.src = this.slides[this.current].image.src;
  // Change the text
  this.display_text();
}

function slideshow_display_text(text) {
  if (this.textarea) {
    if (text) {
      this.textarea.value = text;
    } else {
      this.textarea.value = this.slides[this.current].text;
    };
  };
}
function slideshow_get_text() {
  return(this.slides[this.current].text);
}
function slideshow_loop() {
  // Go to the next image
  this.next();
  // Keep playing the slideshow
  this.play();
}
function slideshow_play(timeout) {
  // Make sure we're not already playing
  this.pause();
  // If a new timeout was specified (optional)
  // set it here
  if (timeout) {
    this.timeout = timeout;
  }
  // After the timeout, call this.loop()
  this.timeoutid = setTimeout( this.name+".loop()", time_delay);
}
function slideshow_pause() {
  if (this.timeoutid != 0)
  {
    clearTimeout(this.timeoutid);
    this.timeoutid = 0;
  }
}
