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

function showPic(whichpic){
	if(!document.getElementById("mainImage"))return true;
	var src = whichpic.getAttribute("href");
	var mainImage = document.getElementById("mainImage");
	mainImage.setAttribute("src",src);
	return false;
}
function prepareGallery(){
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("test4")) return false;
	var gallery = document.getElementById("test4");
	var links = gallery.getElementsByTagName("a");
	for(var i = 0; i<links.length;i++){
//currently means, go through the multi-level list, and for everyone, onclick, show pic. 
//even if there aint no pic there.
//what if show pic if href contains a ".jpg"?
		var hrefs = links[i].getAttribute("href");
		if(hrefs.indexOf("php") == -1){
			links[i].onclick = function(){
				return showPic(this);
			}
		}
	}
}
addLoadEvent(prepareGallery);
