function showPic(whichpic)
{
	if(!document.getElementById("selected_photo")) return true;
	var source = whichpic.getAttribute("href");
	var selected_photo = document.getElementById("selected_photo");
	selected_photo.setAttribute("src",source);

	if(!document.getElementById("caption")) return false;
	if (whichpic.getAttribute("title")) {
            var text = whichpic.getAttribute("title");
	} else {
            var text = " ";
	}
	var caption = document.getElementById("caption");

	if (caption.firstChild.nodeType == 3) {
		caption.firstChild.nodeValue = text;
	}

	return false;
}

function prepareGallery()
{
	//exit points
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("thumbnails")) return false;

	var gallery=document.getElementById("thumbnails");
	var links=gallery.getElementsByTagName("a");

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

}

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

addLoadEvent(prepareGallery);

