/*
	Script: weddings.js
	
	Copyright: Fishnet NewMedia (c) 2006
	
	Create: 01.27.06
	
	Version: 1.0
	
	Compatibility: JavaScript 1.2
	
	Changes: none
*/


function initThumb() {
	// create a reference to all thumbnails
	thumbs = document.getElementsByName("thumbnail");
	// set the onclick event handler for all thumbs
	for (var i = 0; thumbs[i]; i++) {
		thumbs[i].onclick = clickThumb;
		thumbs[i].onmouseover = mouseOverThumb;
		thumbs[i].onmouseout = mouseOutThumb;
	}
}

var imgCache = new Object();

function clickThumb() {
	// create a reference to all thumbnails
	thumbs = document.getElementsByName("thumbnail");
	// swap the large photo
	var	loading = document.getElementById("loading");
	loading.style.visibility = "visible";
	var regx = /(.*)thumb([0-9]{2}[a-z])\.(gif|jpg)$/;
	var match = regx.exec(this.src);
	// var num = Math.round(Math.random() * 1000000000);
	if (imgCache[match[2]]) {
		loading.style.visibility = "hidden";
		document.photo.src = imgCache[match[2]].src; 
	}
	else {
		var img = new Image();
		img.src = match[1] + "photo" + match[2] + ".jpg?";
		img.onload = function () {
			imgCache[match[2]] = img;
			loading.style.visibility = "hidden";
			document.photo.src = img.src; 
		};
	}
}

function mouseOverThumb() {
	// change the thumbnail border
	this.className = "box_hover";
}

function mouseOutThumb() {
	// change the thumbnail border
	this.className = "box";
}