function SlideShow(image_arr) { //arr is the array of images in the slide show this.arr = image_arr; this.arrLength = this.arr.length; this.imagesLoaded = new Array(this.arrLength); this.imagesLoaded[0] = true; // this image is loaded by default this.imagesLoaded[1] = true; // this image is pre-loaded in the BODY tag for (i = 2; i < this.arrLength; i++) { this.imagesLoaded[i] = false; } this.indx = 0; this.direction = 0; this.arrLength -= 1; this.next = next; this.prev = prev; this.moveIndex = moveIndex; this.getNewIndexPosition = getNewIndexPosition; this.showImage = showImage; } function next() { this.moveIndex(1); this.showImage(); } function prev() { this.moveIndex(-1); this.showImage(); } function moveIndex(i) { this.indx = this.getNewIndexPosition(i); } function getNewIndexPosition(p) { var p_new = this.indx + p; if (p_new > this.arrLength) { p_new = 0; } else if (p_new < 0) { p_new = this.arrLength; } return p_new; } function showImage() { if (this.arr[this.indx] != null) { document.images.showcaseimage.src = this.arr[this.indx]; if (! this.imagesLoaded[this.indx]) { this.imagesLoaded[this.indx] = true; } var prev = this.getNewIndexPosition(this.indx - 1); if (! this.imagesLoaded[prev]) { this.imagesLoaded[prev] = true; //alert("preloading " + this.arr[prev] + " indx="+ indx); MM_preloadImages(this.arr[prev]); } var next = this.getNewIndexPosition(this.indx + 1); if (! this.imagesLoaded[next]) { this.imagesLoaded[next] = true; //alert("preloading " + this.arr[next] + " indx="+ indx); MM_preloadImages(this.arr[next]); } } }