An image gallery: Current version

  1. Wait for idle time
  2. An image gallery
  3. Animation

Just to make sure we’re all on the same page, here’s the current version of the SlideShow object and related functions:

function SlideShow() {

this.slides = document.getElementById("images").getElementsByTagName('A');

this.imageFrame = document.getElementById("frame");

this.captionParagraph = document.getElementById("caption");

this.currentSlide = 0;

this.advance = function() {

this.currentSlide++;

if (this.currentSlide >= this.slides.length) {

this.currentSlide = 0;

}

this.displayImage(this.slides[this.currentSlide]);

}

this.displayImage = function(link) {

this.imageFrame.src=link.href;

this.captionParagraph.innerHTML = link.title;

}

this.switchImage = function(link) {

this.displayImage(link);

this.lastActionTime = new Date();

return false;

}

this.lastActionTime = new Date();

this.idle = function() {

var now = new Date();

if (now.valueOf() > this.lastActionTime.valueOf() + 30000) {

return true;

} else {

return false;

}

}

this.idleAdvance = function() {

if (this.idle()) {

this.advance();

}

}

}

//create a gallery and start the slide show in motion

function beginShow() {

gallery = new SlideShow();

window.setTimeout(advanceSlide, 30000);

}

//advance the slide show, and set the timer for the next advance

function advanceSlide() {

gallery.idleAdvance();

window.setTimeout(advanceSlide, 5000);

}

window.onload=beginShow;

  1. Wait for idle time
  2. An image gallery
  3. Animation