function showPic(currentimg) {
	//if the placeholder exists
	if (!document.getElementById("productsample")) return true;
	//get background image for selected thumbnail
	var source = currentimg.getAttribute("id");
	//find and set background image for big placeholder
	var productsample = document.getElementById("productsample");
	productsample.setAttribute("src",source);
	
	//find the description
	if (!document.getElementById("description")) return false;
	//test attribute 
	if (currentimg.getAttribute("longdesc")) {
		var text = currentimg.getAttribute("longdesc");
	} else {
		var text = "";
	}
	//set description
	var description = document.getElementById("description");
	if (description.firstChild.nodeType == 3) {
		description.firstChild.nodeValue = text;
	}
	return false;
}

function prepareGallery() {
	//tests
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("imagegallery")) return false;
	//identify major nodes
	var gallery = document.getElementById("imagegallery");
	var links = gallery.getElementsByTagName("a");
	//for each item returned, get ready to call the main function
	for ( var i=0; i < links.length; i++) {
		links[i].onmouseover = function() {
			return showPic(this);
		}
		links[i].onkeypress = links[i].onmouseover;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		 window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

addLoadEvent(prepareGallery);
