function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function prepLinks(){
	if (!document.getElementById) return false;
	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(){
			pop(this);
			return false;
		}
	}
}

function pop(imglink){

	var imgsource = imglink.getAttribute("href");
	var title = imglink.getAttribute("title");
	var HTMLString;
	var newwindow;
	var newdocument;
	
	HTMLString='<html><head><title>Gallery</title>';
	HTMLString+='<style>body { padding: 10px; margin: 0px; background: #fff; text-align: center; color: #999; font: 80% Verdana, Arial, sans-serif; } ';
	HTMLString+='a:link { color: #004990; } a:visited { color: #366899; } a:active, a:hover { color: #6db33f; }';
	HTMLString+='html { padding: 0px; margin: 0px; } </style></head>';
	HTMLString+='<body onBlur="self.close()" onClick="self.close()"><p><img src="' + imgsource + '" /><br /></p>';
	HTMLString+='<p><a href="photos.html" onclick="self.close();">close window</a></p></body></html>';
	newwindow = window.open('blank.html', 'photo', 'width=450,height=450,resizable');
	newwindow.document.open();
	newwindow.document.write(HTMLString);
	HTMLString='';
	newwindow.document.close();
	newwindow.focus();
}

addLoadEvent(prepLinks);