function addEvent (t, e, h) {
// target, event, handler
  if (t.addEventListener) { t.addEventListener (e, h, false); }
  else if (t.attachEvent) { t.attachEvent ('on' + e, h); }
  else if (t.onload) { var o = t.onload; t.onload = new Function ('o (); h ();'); }
  else { t.onload = h; }
}

var imagePopuper = {
	init: function () {
		for (var i = document.links.length - 1; i >= 0; i--) {
			var l = document.links[i];
			var w = l.width || l.getAttribute ('width');
			var h = l.height || l.getAttribute ('height');
			if (w && h) l.onclick = imagePopuper.popupImage;
		}
	},
	popupImage: function () {
		var t = this.title || this.getAttribute ('title');
		var w = this.width || this.getAttribute ('width');
		var h = this.height || this.getAttribute ('height');	
		var x = Math.round ((self.screen.width - w)/2);
		var y = Math.round ((self.screen.height - h)/2);
		if (window.opera) y = Math.abs (y - self.screenTop);
		var p = window.open ('', '_blank',
			'width=' + w + ',height=' + h +
			',top=' + y + ',left=' + x);
		var d = p.document;
		d.write("<html><head><title>" + t + "</title>");
		d.write("<style type='text/css'>body { margin: 0; padding: 0; }</style>");
		d.write("</head><body><a href='javascript:self.close ()' title='[Закрыть]'>");
		d.write("<img alt='" + t + "' src='" + this.href + "' border='0' /></a>");
		d.write("</body></html>");
		d.close();
		if (window.focus) { p.focus (); }
		return false;
	}
}

addEvent (window, 'load', imagePopuper.init);

