function checkload(){

var iimg = document.getElementById("zoomed_image");
iimg.style.display = "none";
(iimg.complete)? hideczekaj() : setTimeout('checkload()', 50);
}

function hideczekaj()
{
	document.getElementById("czekaj").style.display = "none";
	document.getElementById("zoomed_image").style.display = "";

}

function documentheight()
{
 	var size = window.innerHeight + window.scrollMaxY;
	return size;
}

function windowheight() 
{
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) 
  {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}


function zoom (adres, p, n, kat)
{
	var div = document.createElement("div");
	div.id = "zoom_image";

	var link_p = '<a id="zoom_wstecz" href="index.php?pg=img&kat='+kat+'&gfx='+p+'&big=1">wstecz</a>';
	var link_n = '<a id="zoom_dalej"  href="index.php?pg=img&kat='+kat+'&gfx='+n+'&big=1">dalej</a>';
	
	if (p == '' || isNaN(kat)) link_p = '';
	if (n == ''  || isNaN(kat)) link_n = '';
	
	var czekaj = '<div id="czekaj"><br /><br />trwa ładowanie obrazu...<br /><div class="progress"></div></div>';
	var navi = '<div id="zoom_naw">'+link_p+link_n+'<br /></div>'
	div.innerHTML = '<div>'+navi+czekaj+'<img style="cursor:pointer;" onClick="zoom_close();" src="obrazy/b/'+adres+'" alt="zoom" id="zoomed_image" /></div>';
	document.body.appendChild(div);

	var wH = windowheight();
	var tH = wH;
	var dH = documentheight();
	
	if (dH > 0) 
	{
		if (dH > wH) div.style.height = dH+'px'; else div.style.height = tH+'px';
	}
	else
	{
		if (document.body.scrollHeight > 0) div.style.height = document.body.scrollHeight+'px';
		else div.style.height = '4000px'; // desperacja?
		
	}
	checkload();
	scroll(0,0);
}

function zoom_close()
{
	var div = document.getElementById('zoom_image');
	document.body.removeChild(div);
}