function addLoadEvent(func)
{
	var oldonload = window.onload;
	if(typeof window.onload!= 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

function prepareGallery ()
{
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("thumbs")) return false;
	var thumbs = document.getElementById("thumbs");
	var links = thumbs.getElementsByTagName("a");
	for(var i = 0; i < links.length; i++)
	{
		links[i].onclick = function()
		{
			return showPic(this);
		}
	}
}

function showPic(whichpic)
{
	if(!document.getElementById("main_picture")) return true;
	if(!document.getElementById("description")) return true;
	if(!whichpic.getAttribute("title")) return true;
	if(!whichpic.getAttribute("rev")) return true;
	var source = whichpic.getAttribute("rel");
	var main_picture = document.getElementById("main_picture");
	var new_picture = 'images/' + source;
	main_picture.src = new_picture;
	var descriptionElement = document.getElementById("description_text");
	var pieceElement = document.getElementById("piece");
	var description = whichpic.getAttribute("title");
	var piece = 'Piece #' + whichpic.getAttribute("rev");
	pieceElement.firstChild.nodeValue = piece;
	descriptionElement.firstChild.nodeValue = description;
	return false;
}

addLoadEvent(prepareGallery);