/*
	 Skrypt jest darmowy, poki ten komentarz w nim pozostaje.
	 Released under Creative Commons License
	 http://creativecommons.org/licenses/by/2.0/
	 Original author: Kornel Lesinski
	 http://pornel.net/pups/
*/

var pornpups = {
	init: function(element)	{
		if (!element || !element.getElementsByTagName) {return false;}
		var as = element.getElementsByTagName('a');
		for(var i=0;i<as.length;i++) {
			if ((as[i].className)=='popup')
				as[i].onclick = this.click;
         }
		return true;
	},

	writedoc: function(win,href,title,alt,h,opis) {
		var doc = win.document;
		doc.open('text/html;charset=utf-8');
		doc.write(
		'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' +
		'<html id="popup">' +
		'<head><title>' + alt + '</title>' +
		'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' +
		'<meta http-equiv="imagetoolbar" content="false">' +
		'<style type="text/css">' +
      'html, body {background:#000; color: #fff; font-family: verdana,arial,helvetica,sans-serif; font-size: 0.9em; padding:0; margin:0; cursor:pointer; height:100%; width:100%;} ' +
      'table {border: none; height:100%; width:100%;}' +
      '</style></head>' +		
		'<body onclick="window.close();">' +
		'<table summary="foto+opis"><tr><td align="center" valign="middle"><img src="'+href+'" alt="'+alt+'">' +
      (opis ? '<p>' + opis + '</p>':'') +
      '</td></tr></table></body></html>'
		);
		doc.close();
	},

	title2size: function(str) {
		if (str) {
			var out = str.match(/\(([0-9]+)x([0-9]+)\)/);
			if (out) return new Array(str.replace(/\(([0-9]+)x([0-9]+)\)/g,''),parseInt(out[1],10),parseInt(out[2],10));
		}
		return new Array(str,550,420);
	},

   getNumber: function(str) {
      var out = str.match(/([0-9]+)/);
      if (out) return parseInt(out[0],10);
      else return 0; 
   },
   
	click: function()	{
		try {
			if (this.pp_win && this.pp_win.close && !this.pp_win.closed) {this.pp_win.close(); this.pp_win=false;}
		}
		catch(e){}
		try {
			var imgs = this.getElementsByTagName('img');
			var title = imgs[0].getAttribute('title')?imgs[0].getAttribute('title'):this.getAttribute('title');
			var alt = imgs[0].getAttribute('alt');
			var titleandsize = pornpups.title2size(title);
			var nr = pornpups.getNumber(imgs[0].getAttribute('src'));
			var winopts = "dependent=yes,toolbar=no,resizable=yes,scrollbars=auto";
			var win = window.open(this.href,'_blank',winopts);
			if (nr && typeof(opisyZdjec_pl) != 'undefined')
			   opis = opisyZdjec_pl[nr];
			else
			   opis = '';
			if (win && win.opener) {
				this.pp_win = win;
				pornpups.writedoc(win,this.href,titleandsize[0],alt,titleandsize[2],opis);
				return false;
			}
		}
		catch(e){}
		return true;
	},

	initNow: function() {
		this.init(document.body);
	},

	initLoad: function()	{
		var oldOnload = window.onload;
		var that = this;
		window.onload = function() {
			if (oldOnload) try{oldOnload();}catch(e){}
			that.initNow();
		}
	}
};

pornpups.initLoad();
