/**********************
Released under Creative Commons License
http://creativecommons.org/licenses/by/2.0/

Author: Kornel Lesinski
http://pornel.ldreams.net/pornpups
**********************/

/* click handler */
function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function pp_click()
{
	/* toggle window */
	if (this.pp_win && this.pp_win.close && !this.pp_win.closed) {this.pp_win.close(); this.pp_win=false; return false;}

	/* collect title from image/link */
	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 winopts = "dependent=yes,toolbar=no,resizable=yes,"+pp_titl2size(this.getAttribute('title')?this.getAttribute('title'):title);

	/* do the boogie */
  if (win = window.open(this.href,'_blank',winopts))
  {
	  this.pp_win = win;
	  pp_writedoc(this.href,win.document,title,alt);
    return false;
  }
  /* follow link on failure */
  return true;
}

/* finds dimensions in given string, format: (<width>x<height>), outputs width=<width>,height=<height> */
function pp_titl2size(str)
{
	if (str)
	{
		var out = str.match(new RegExp('\(([0-9]+)x([0-9]+)\)'));
		return "width="+(parseInt(out[2])+30)+",height="+(parseInt(out[3])+50);
	}
	return "width=800,height=550";
}

/* create new document. Code it using DOM if you wish :> */
function pp_writedoc(href,doc,title,alt)
{
  doc.open();
  doc.write('<?xml version="1.0" encoding="ISO-8859-2" ?>');
  doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">');
	doc.write('<html xmlns="http://www.w3.org/1999/xhtml">');
	doc.write('<head><head><title>'+alt+'</title>');
	doc.write('<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2" />');
	doc.write('<style type="text/css">body {	margin: 0;	padding: 0;	background: #57676b;	font-size: 11px;	font-family: arial,sans-serif;	color: white;} p {	margin: 0;	text-align: center;} img {background: black; padding: 3px; border: 3px double gray;} </style>');
	doc.write('</head><body onclick="window.close()">');
	doc.write('<p>Klik zamyka</p><p><img title="'+title+'" src="'+href+'" alt="'+alt+'"></p><p>'+title+'</p></body></html>');
  doc.close();
}

/* set click handler on descendants */
function pp_init(element)
{
	if (!element.getElementsByTagName) {return false;}
  
	var as = element.getElementsByTagName('a');
	for(i=0;i<as.length;i++)
	if (as[i].className=='pop')  {as[i].onclick = pp_click;}
  return true;
  
}

/* you need something smarter than that in production code! */
function pp_init_body()
{
	pp_init(document.body);
}
window.onload = pp_init_body;
preloadImages('buttons/1_o.png');preloadImages('buttons/1_o.png');preloadImages('buttons/2_o.png');preloadImages('buttons/3_o.png');preloadImages('buttons/4_o.png');preloadImages('buttons/5_o.png');preloadImages('buttons/6_o.png');

