var cachedImages = new Array();
function cacheImages() {
	for (i=0; i<document.images.length; i++) {
		var workingImage = document.images[i];
		if (workingImage.getAttribute("overImage") && workingImage.getAttribute("offImage")) {
			
			eval("workingImage.onmouseover = function() {this.src =cachedImages['"+workingImage.getAttribute('overimage')+"'].src;}");
			eval("workingImage.onmouseout = function() {this.src =cachedImages['"+workingImage.getAttribute('offimage')+"'].src;}");
			var index = cachedImages.length;
			cachedImages[""+workingImage.getAttribute('overimage')] = new Image(); 
			cachedImages[""+workingImage.getAttribute('overimage')].src = workingImage.getAttribute('overimage')
			cachedImages[""+workingImage.getAttribute('offimage')] = new Image(); 
			cachedImages[""+workingImage.getAttribute('offimage')].src = workingImage.getAttribute('offimage')
		}
	}
}


function roll(imgName, which) {
	if (eval(imgName + "_" + which + ".src")) {
		document.images[imgName +"_image"].src = eval(imgName + "_" + which + ".src");
	}
}

function PhotoViewer(photoArray) {
	this.currentImage = 0;
	this.numberOfImages = photoArray.length
	this.photoArray = new Array();
	for (i=0; i<this.numberOfImages; i++) {
		this.photoArray[i] = photoArray[i];
		cachedImages[photoArray[i]] = new Image();
		cachedImages[photoArray[i]].src = photoArray[i];
	}
}
PhotoViewer.prototype.next = function() {
	if (this.currentImage+1 < this.numberOfImages) {
		this.currentImage++;
		eval("document.images['thumb"+(this.currentImage)+"'].src ='images/icon_thumb_off.gif'" );
		eval("document.images['thumb"+(this.currentImage+1)+"'].src = 'images/icon_thumb_on.gif'" );
		this.refreshPhoto()
	}
}
PhotoViewer.prototype.previous = function() {
	if (this.currentImage-1 >= 0) {
		this.currentImage--;
		eval("document.images['thumb"+(this.currentImage+2)+"'].src ='images/icon_thumb_off.gif'" );
		eval("document.images['thumb"+(this.currentImage+1)+"'].src = 'images/icon_thumb_on.gif'" );
		this.refreshPhoto()
	}
}
PhotoViewer.prototype.jumpTo = function(which) {
	which = which-1;
	if ((which < this.numberOfImages)&&(which>= 0)) {
		eval("document.images['thumb"+(this.currentImage+1)+"'].src = 'images/icon_thumb_off.gif'" );
		this.currentImage = which;
		eval("document.images['thumb"+(this.currentImage+1)+"'].src = 'images/icon_thumb_on.gif'" );
		this.refreshPhoto();

	}
}
PhotoViewer.prototype.refreshPhoto = function() {
	document.images['pvPhoto'].src = this.photoArray[this.currentImage];
}

function init() {
	cacheImages();
}

window.onload=init;
