/////////////////////////////////////////////////////////////////////

var picker_is_opened=false;

var adscsw = false;
var petlenie = false;
var adstart = 0;

/////////////////////////////////////////////////////////////////////

function Gallery_findObj(n, d) 
{ 
	//v4.01
	var p,i,x;  
	if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) 
	{
	 d=parent.frames[n.substring(p+1)].document; 
	 n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/////////////////////////////////////////////////////////////////////

function Gallery_Warstwa(w,h,x,y) 
{
	var output='';
	output +=  '<table id=\'obiekt_gallery\' cellspacing=\'0\' style=\'display:none; position:absolute; z-index:999; background-color: #ffffff; border-collapse: collapse;filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=3,OffY=3,Color=#bbbbbb,Positive=true\' bordercolor=\'#777777\' border=\'1\'>';	
        output +=  '<tr height=\''+h+'\'><td align=\'center\' vAlign=\'center\'>';
        output +=  '<DIV Class=\'galeria_zamknij\' id=\'galeria_zamknij\' style=\'display:none;\'><A HREF=\'JavaScript:UkryjWarstweGallery();\' Class=\'a\'>zamknij&nbsp;X</A></DIV>';
	output +=  '<div id=\'tresc\'><\/div>';
	output +=  '<\/td><\/tr><\/table>';
	return output;
}

/////////////////////////////////////////////////////////////////////

function Gallery_Warstwa_polozenie(w,h,x,y) 
{
	var gall=Gallery_findObj('obiekt_gallery');
	gall.style.display='';
	gall.style.left=x;
	gall.style.top=y;
	gall.width=w;
	gall.height=h;
        picker_is_opened=true;
} 


/////////////////////////////////////////////////////////////////////


function adsc_gallery(adid)
{
  if(!petlenie) return 0;

  if (!adscsw)
  {
     adstart = parseInt(eval('document.all.'+adid+'.style.top'))-document.body.scrollTop;
     adscsw = true;
  }

  adoY=document.body.scrollTop+adstart;

  adoYr=parseInt(eval('document.all.'+adid+'.style.top'));

  if (adoY != adoYr) adscsl_gallery(adid, adoYr, adoY,0);
   else 
    {
      ada = setTimeout('adsc_gallery(\''+adid+'\')', 50)
    };
}

function adscsl_gallery(adid, from, to, adsgntmp)
{
  if(!petlenie) return 0;

  if (to - from) adsgn = Math.abs(to - from)/(to - from); else adsgn = 2;
  if (!adsgntmp) adsgntmp = adsgn;
  from = Math.ceil(from + adsgn*Math.sqrt(Math.ceil(10*adsgn*(to-from))/10));
  eval('document.all.'+adid+'.style.top='+from);
  if (adsgn==adsgntmp) 
   {
     setTimeout('adscsl_gallery(\''+adid+'\','+from+','+(document.body.scrollTop+adstart)+','+adsgntmp+')', 25);
   }
  else adsc_gallery(adid);
}

/////////////////////////////////////////////////////////////////////

function pokaz_zamknij()
{
  if(document.all['gallery_image'].width < 100) setTimeout("pokaz_zamknij()", 100);
   else
   {
     zamknij=Gallery_findObj('galeria_zamknij');
     zamknij.style.display='';
   } 
}

function UkryjWarstweGallery() 
{
   var gall=Gallery_findObj('obiekt_gallery');

   gall.style.display='none';
   picker_is_opened=false;

   petlenie = false;
   adstart = 0;
   adscsw = false;

   zamknij=Gallery_findObj('galeria_zamknij');
   zamknij.style.display='none';
} 


function zmien_wielkosc(w,h)
{
   petlenie = true;

   positionTop = Math.ceil((document.body.offsetHeight)/2)+document.body.scrollTop-(h/2);
   positionLeft = Math.ceil(document.body.offsetWidth)/2-(w/2)-20;

   Gallery_Warstwa_polozenie(w,h,positionLeft,positionTop);

   adscsw = false;
   adstart = 0;
   adsc_gallery('obiekt_gallery');
}

/////////////////////////////////////////////////////////////////////

function image(typ,id,width,height) 
{
   var output = '';
   var thumbwidth = 0;
   var thumbheight = 0;
   var obrazek = new Image();

   if(width > document.body.offsetWidth)
   { 
     thumbwidth = document.body.offsetWidth-100;    
     height = Math.round((thumbwidth*height)/width);
     width = thumbwidth;         
   }

   if(height > document.body.offsetHeight)
   { 
     thumbheight = document.body.offsetHeight-100;
     width = Math.round((thumbheight*width)/height);
     height = thumbheight;    
   } 

   output += '<IMG SRC="design/prosze_czekac.gif" id="gallery_image" Style="MARGIN: 0px 10px 10px 10px;">';

   gall=Gallery_findObj('tresc');
   gall.innerHTML=output;

   zmien_wielkosc(100,100);

   if(typ == 1) 
   {
     //obrazek.src = "plik.php?zalacznikid="+id+"&typ=galeria&width="+width+"&height="+height;
     obrazek.src = "gallery_"+id+"w"+width+"h"+height+".jpg";
   }
   if(typ == 2) 
   {
     //obrazek.src = "plik.php?zalacznikid="+id+"&typ=zalacznik&width="+width+"&height="+height;
     obrazek.src = "image_"+id+"w"+width+"h"+height+".jpg";
   }

   zmien_wielkosc(width+25,height+35);

   document.all['gallery_image'].src=obrazek.src;

   pokaz_zamknij();
}

/////////////////////////////////////////////////////////////////////

function show_okno()
{
   czekac.style.display='none'; 
   main_okno.style.display='';
}

/////////////////////////////////////////////////////////////////////

function okno(sciezka,winWidth,winHeight,scroll,close)
{
   var margin = 0;
   var output = '';

   winHeight += 10;
   winWidth += 30;

   if(close == "no") galeria_zamknij.style.display='none'; else galeria_zamknij.style.display='';
 
   margin = Math.ceil(winHeight/2)-35;

   output += '<DIV id="czekac" BGColor="#FFFFFF">';
   output += '<IMG SRC="design/prosze_czekac.gif" Style="MARGIN: '+margin+'px 0px '+margin+'px 0px;">';
   output += '</DIV>';

   //zmien_wielkosc(winWidth,winHeight);

   if(scroll == "nie") scroll = "no"; else scroll = "yes";

   output += '<DIV id="main_okno" Style="display: none" BGColor=\"#FFFFFF\">';
   output += '<iframe Class="iframe_okno" src="'+sciezka+'" Align="center" frameborder="0" id="cms_window" name="cms_window" onLoad="show_okno();" width="'+winWidth+'" height="'+winHeight+'" scrolling="'+scroll+'"></iframe>';
   output += '</DIV>';

   kal=Gallery_findObj('tresc');
   kal.innerHTML=output;

   zmien_wielkosc(winWidth,winHeight);
}


/////////////////////////////////////////////////////////////////////

document.write(Gallery_Warstwa(0,0,0,0));

/////////////////////////////////////////////////////////////////////

