/* v2 of this file */

window.onload = function() {
	prepareGallery();
}

function prepareGallery() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("thumbs")) return false;

	var gallery = document.getElementById("thumbs");

/* Prepare links and thumbnails */
	var links = gallery.getElementsByTagName("a");

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

function getNextElement(node) {
	if (node.nodeType == 1) {
		return node;
	}
	if (node.nextSibling) {
		return getNextElement(node.nextSibling);
	}
	return null;
}

function getPrevElement(node) {
	if (node.nodeType == 1) {
		return node;
	}
	if (node.previousSibling) {
		return getPrevElement(node.previousSibling);
	}
	return null;

}

function showPic(whichpic) {
	/* Change the picture */
	if (!document.getElementById("image")) return false;
	var source = whichpic.getAttribute("href");
	var image = document.getElementById("image");
	image.setAttribute("src",source);

	/* Code to change title here -- Commented out because no title. 
	var parent = whichpic.parentNode;
	var titlenode = getPrevElement(parent.previousSibling);
	var title = titlenode.innerHTML;
	var titletext = document.getElementById("pagetitle");
	titletext.innerHTML = title;*/
}