// JavaScript Document
var imgwin = null;
function initPopup() {
	for(var i = 0; i < document.getElementsByTagName('a').length; i++) {
		var node = document.getElementsByTagName('a')[i];
		if (node.className.match(/^popup$/)) {

			// preload image
			var img=node.getAttribute('href');

            var image = new Image();
            image.src = img;

			node.onfocus = function() {
				this.blur();
			}

			// change link-behaviour
			node.onclick = function() {
				var reg = /^popup$/;
				reg.exec(this.className);

				w = 632;
				h = 432;

				var url=this.getAttribute('href');

				// bring back relative link for ff
				url = '/popup.php?img=' + url;

				var padding = 20;

				var screenw = screen.availWidth;
				var screenh = screen.availHeight;
				var winw = (w + padding);
				var winh = (h + padding);
				var posx = (screenw / 2) - (winw / 2);
				var posy = (screenh / 2) - (winh / 2);
				
				if (imgwin) {
					imgwin.close();
				}
				
				imgwin = window.open(url,"imgwin","top="+posy+",left="+posx+",width="+winw+",height="+winh+",menubar=no,locationbar=no,statusbar=no,resizable=no,toolbar=no,dependent=yes,scrollbars=no,X=0,Y=0");
				imgwin.focus(); 
				return !imgwin;

			}	
		}
	}
}
addInitFunction(initPopup);
