function doPopups()
{
		var gallery = document.getElementById("popupGallery");
		var links = gallery.getElementsByTagName("a");
		var href;
		
		for(var i=0; i < links.length; i++) {
			href = links[i].href;
			var preloaded = new Image();
			preloaded.src = links[i].href;
			w = preloaded.width;
			h = preloaded.height;
			links[i].setAttribute("onclick", "return popUp(this, w, h);");
			if(i > 100) break;

		}
  
}

function popUp(pic, w, h) {
	var title = pic.title;
	var src = pic.href;
	
	var mywin = window.open('', '', 'width='+w+', height='+h+', fullscreen=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes');
	
	mywin.document.open();
	mywin.document.write('<head><title>'+title+'</title></head><body bgcolor="silver" leftmargin=0 topmargin=0>');
	mywin.document.write('<style>body {overflow: hidden; margin: 0px;}</style>');
	mywin.document.write('<img src="' + src + '" alt="' + title + '"/>');
	mywin.document.write('</body>');
	mywin.document.close();	
	
	var bigPic; 

	mywin.onload = function() {
		bigPic = mywin.document.images[0];
		newWidth = bigPic.offsetWidth;
		newHeight = bigPic.offsetHeight;
		
		mywin.self.resizeTo(newWidth, newHeight);
		mywin.moveTo((screen.width - newWidth) / 2,(screen.height - newHeight) / 2);
	}

	bigPic = mywin.document.images[0];
	newWidth = bigPic.offsetWidth;
	newHeight = bigPic.offsetHeight;
	
	mywin.self.resizeTo(newWidth, newHeight);
	mywin.moveTo((screen.width - newWidth) / 2,(screen.height - newHeight) / 2);
	
	return false;
}

window.onload = doPopups;
