var img;
var title;

function picture(picgoal,picname)
{
  if(top.PicWin && !top.PicWin.closed) top.PicWin.close();//jesli okno otwarte to zamknij
	
  top.PicWin=window.open("","popupwindow",'scrollbars=0,status=0,resizable=0,width=200,height=100,screenX=50,screenY=50,top='+(screen.height/2-50)+',left='+(screen.width/2-100));
  top.PicWin.document.open();
  top.PicWin.document.writeln('<html>');
  top.PicWin.document.writeln('<head><meta http-equiv="Content-type" content="text/html; charset=iso-8859-2">');
  top.PicWin.document.writeln('<title>'+picname+'</title>');
  top.PicWin.document.writeln('</head>');
  top.PicWin.document.writeln('<body bgcolor="#B1B7C2" style="margin: 0;padding: 0"><table style="width: 200px; height: 100px; vertical-align: middle; text-align: center"><tr><td>');
  top.PicWin.document.writeln('Trwa ³adowanie pliku...');
  top.PicWin.document.writeln('</td></tr></table></body>');
  top.PicWin.document.writeln('</html>');
  top.PicWin.document.close();
  title = picname;	
  img = new Image;	
  img.src = picgoal;	
  checkIfLoaded();
}
 
 
function checkIfLoaded()
{
  if(top.PicWin.closed) return;

  if(!img.complete)
  {
    setTimeout('checkIfLoaded()', 500);
  }
  else
  {
    var w;
    var h;
    var x_scale;
    var y_scale;
    var scale = 1;
    var margin = 20;
    
    top.PicWin.document.open();
    top.PicWin.document.writeln('<html>');
    top.PicWin.document.writeln('<head><meta http-equiv="Content-type" content="text/html; charset=iso-8859-2">');
    top.PicWin.document.writeln('<title>'+title+'</title>');
    top.PicWin.document.writeln('</head>');
    top.PicWin.document.writeln('<body style="margin: 0;padding: 0">');
    top.PicWin.document.writeln('<div id="container" style="overflow: hidden; margin: auto; padding: auto; text-align: center; veritcal-align: middle">');
    top.PicWin.document.writeln('<acronym title="Kliknij aby zamkn±æ okno"><img src="" name="_img"><div style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; background-image: url(\'./img/gif.gif\'); background-repeat: repeat;" alt="Kliknij aby zamkn±æ okno" onclick="self.close()" onmouseover="style.cursor=\'pointer\'"></div></acronym>');
    top.PicWin.document.writeln('</div>');
    top.PicWin.document.writeln('</body>');
    top.PicWin.document.writeln('</html>');
    top.PicWin.document.close();
    top.PicWin.document._img.src = img.src;
    adj_w = 10;
    adj_h = 30;

    w = img.width;
    h = img.height;
    x_scale = (screen.width-margin)/w;
    y_scale = (screen.height-margin)/h;
    scale = Math.min(x_scale, y_scale);

    if(scale < 1)
    {
	    w = top.PicWin.document._img.width  = img.width * scale;
	    h = top.PicWin.document._img.height = img.height * scale;
    }
    h+=adj_h;
    w+=adj_w;
    //move the window
    top.PicWin.moveTo((screen.width/2-w/2),(screen.height/2-h/2));
    //resize container div
    top.PicWin.document.getElementById("container").style.width = ""+(w-10)+"px";
    top.PicWin.document.getElementById("container").style.height = ""+(h-30)+"px";
    //resize the window
    top.PicWin.resizeTo(w, h);
  }
}
