// JavaScript Document


window.onload = preparelinks;

function preparelinks(){
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById("gallery"))	return false;
	
	var gallery = document.getElementById("gallery");
	var links = gallery.getElementsByTagName("a");

	for (var i=0; i<links.length; i++){
		links[i].onclick = function(){
			return showPic(this);
		}
		links[i].onkeypress = links[i].onclick;
	}
}

function showPic(whichpic){
	if(!document.getElementById("placeholder")) return true;
	var source = whichpic.getAttribute("href");
	var placeholder = document.getElementById("placeholder");
	placeholder.setAttribute("src", source);
	
	//check for caption paragraph:
	if(!document.getElementById("caption")) return false;
	var text = whichpic.getAttribute("title");
	var caption = document.getElementById("caption");
	caption.firstChild.nodeValue = text;
	
	if(!document.getElementById("dimensions")) return false;
	var dimText = whichpic.getAttribute("dimensions");
	var dimCaption = document.getElementById("dimensions");
	dimCaption.firstChild.nodeValue = dimText;
	
	if(!document.getElementById("materials")) return false;
	var matText = whichpic.getAttribute("materials");
	var matCaption = document.getElementById("materials");
	matCaption.firstChild.nodeValue = matText;
	return false;
}