/*
Filename: photocycle.js
Desc:     Change images every X seconds from a list with coordinated links.
Author:   Relevant Arts Enterprise, Inc. <http://www.relevantarts.com/>
          John A. Lock <jlock@relevantarts.com>
Created:  2000-Aug-8
Modified: 
*/

// Set up default values
var photocycle_image_path = "img/";
var photocycle_delay = 3000;
var LinkCtr = 0;
var LinkNbr = 0;
var PhotoNbr = 0;
var PhotoMax = 0;
var NextPhotoNbr = 0;
var AllCached = false;

// Initialize the photo cycler
function InitCycle() {
	// Find the link number of the photo URL and save it
	for (LinkCtr=0; LinkCtr<document.links.length; LinkCtr++) {
		if (document.links[LinkCtr].href.indexOf(PhotoLink[0]) != -1) {
			LinkNbr = LinkCtr;
			LinkCtr = document.links.length;
		}
	}
	PhotoMax = Photo.length - 1;
	// Preload the next image in the list
	document["PreLoad1"] = new Image();
	document["PreLoad1"].src = photocycle_image_path + Photo[1];
	// Set the timer to run the next cycle after the delay period
	TimerID = setTimeout("CyclePhotos()", photocycle_delay);
}

// Change photo image by cycling thru the list of photos
function CyclePhotos() {
	if (document.images) {
		// If we've reached the end of the photos, start the list over
		PhotoNbr++;
		if (PhotoNbr > PhotoMax) {
			PhotoNbr = 0;
			AllCached = true;
		}
		// Set the photo image and link URL to current values
		document.phototag.src = photocycle_image_path + Photo[PhotoNbr];
		document.links[LinkNbr].href = PhotoLink[PhotoNbr];
		// If all the photos are not cached yet, preload the next one
		if ((!AllCached) && (PhotoNbr < PhotoMax)) {
			NextPhotoNbr = PhotoNbr + 1;
			document["PreLoad" + NextPhotoNbr] = new Image();
			document["PreLoad" + NextPhotoNbr].src = photocycle_image_path + Photo[NextPhotoNbr];
		}
		// Set the timer to run the next cycle after the delay period
		TimerID = setTimeout("CyclePhotos()", photocycle_delay);
	}
}
