function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
			{
				oldonload();
				func();
			}
	}
}


// set up the page
function init()
{
	pz = new photoZoom();
}

addLoadEvent(init);




// photoZoom class
photoZoom = function()
{
	this.init();
}


photoZoom.prototype.init = function()
{
	if ( !document.getElementById ) return;
	if ( !document.getElementsByTagName ) return;
	if ( !document.createElement ) return;
	if ( !document.appendChild ) return;
	
	this.buildContainer();
	this.initThumbs();
}


photoZoom.prototype.buildContainer = function() {
	var d = document.createElement('DIV');
	d.id = 'lgphoto';
	
	// create an image element
	var i = document.createElement('IMG');
	i.src = '';
	i.width = 400;
	i.height = 300;
	i.alt = '';
	
	// create a paragraph to hold the image caption
	var p = document.createElement('P');
	var tn = document.createTextNode('');
	p.appendChild(tn);
	
	// append the image and the paragraph to the container
	d.appendChild(i);
	d.appendChild(p);
	
	// append the container to the end of the document
	document.body.appendChild(d);
}


photoZoom.prototype.initThumbs = function() {
	var sb = document.getElementById('sidebar');
	var thumbs = sb.getElementsByTagName('IMG');
	
	if ( thumbs.length > 0 )
	{
		for ( var i=0; i<thumbs.length; i++ )
		{
			thumbs[i].onmouseover = this.showLgImg;
			thumbs[i].onmouseout = this.hideLgImg;
		}
	}
}


photoZoom.prototype.showLgImg = function(e) {
	if ( e && e.target)
		img = e.target;
	if ( window.event && window.event.srcElement )
		img = window.event.srcElement;
	if (!img) return;
	
	var smPath = img.src;
	var div = document.getElementById('lgphoto');
	var regex = new RegExp('/sm/');
	var lgPath = smPath.replace(regex, '/lg/');
	div.getElementsByTagName('IMG')[0].src = lgPath;
	div.getElementsByTagName('IMG')[0].alt = img.alt;
	div.getElementsByTagName('P')[0].firstChild.nodeValue = img.alt;
	div.style.display = 'block';
}


photoZoom.prototype.hideLgImg = function() {
	var div = document.getElementById('lgphoto');
	div.style.display = 'none';
	div.getElementsByTagName('IMG')[0].src = '/img/loading.png';
}
