// Gallery 1.2 SP ED
// Author: Adam Major
// Copyright: Freshdata, http://www.freshdata.pl
// Date: 2007.12.10 
// 

function pv_close()
{
phw = document.getElementById('pview');	
phw.style.display = 'none';	
ovd = document.getElementById('overlay');
ovd.style.display = 'none';
}

function page_jump(nb, dt)
{
phw = document.getElementById('pview');	
phw.style.display = 'none';
location= gal_rf + '.php?id=' + gid + '&pg=' + nb+'&dt='+dt;	
}

function photoview(pid)
{
if (self.innerWidth)
	{ // IE
		var frameWidth = self.innerWidth-20;
		var frameHeight = self.innerHeight;
		var frameTop = self.pageYOffset;
		if (window.scrollMaxY) var yScroll = window.innerHeight + window.scrollMaxY
		else var yScroll = window.innerHeight * 3; // bad hack
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{// NIE IE
		var frameWidth = document.documentElement.clientWidth;
		var frameHeight = document.documentElement.clientHeight;
		var frameTop = document.documentElement.scrollTop;
		var yScroll = document.body.scrollHeight;
		
	}
	else if (document.body)
	{
		var frameWidth = document.body.clientWidth;
		var frameHeight = document.body.clientHeight;
		var frameTop = document.body.scrollTop;
		var yScroll = document.body.scrollHeight;
		
	}	
if(yScroll < frameHeight)pageHeight = frameHeight;
	else  pageHeight = yScroll;
	
if (p_width[pid] < 300) p_width[pid] = 300;
v_width = parseInt(p_width[pid]);
v_height= parseInt(p_height[pid]) + 50;
v_top =  Math.ceil(frameHeight / 2 - v_height / 2) + frameTop-12;
v_left =  Math.ceil(frameWidth / 2 - v_width / 2);
ovd = document.getElementById('overlay');
ovd.style.width = frameWidth + 'px';
ovd.style.height = pageHeight + 'px';

ovd.style.display = 'block';

phw = document.getElementById('pview');
phw.style.position = 'absolute';
phw.style.top = v_top + 'px';
phw.style.left = v_left + 'px';
phw.style.width = v_width + 'px';	
phw.style.height = v_height + 'px';	
phw.style.border = '1px solid #808080';
phw.style.padding = '10px 10px 10px 10px';
phw.style.background = '#FFFFFF';
phw.style.zIndex = 12;

phw.style.display = 'block';
phw.innerHTML = '<div id="photo" style="text-align:center"></div><div id="p_controls"></div>';

ph = document.getElementById('photo');
ph.style.height = v_height - 45 + 'px';	
ph.innerHTML = '<img src="dimg/big/' + p_id[pid] + '.jpg" />';

cp_id = p_id[pid].substring(p_id[pid].lastIndexOf('/')+1);

p_max = p_width.length;
if (pid+page_s-1 > 0) 
	{
	if (pid == 0)
		{
		l_arr = '<a href="javascript:page_jump('+ (page_nb-1) + ',2'
		+')" title="Poprzednia strona"><img src="img/back2.gif" border="0" alt="Poprzednia strona"></a>';
		}
	else	
		{	
		l_arr = '<a href="javascript:photoview('+ (pid-1)
		+')" title="Poprzednie"><img src="img/back.gif" border="0" alt="Poprzednie"></a>';
		}
	}
else l_arr = '<img src="img/back0.gif" border="0" alt="Pierwsze zdjêcie">';

if (pid+page_s < max_id) 
	{
	if (pid == p_max-1)
		{
		p_arr = '<a href="javascript:page_jump('+ (page_nb+1) + ',1'
		+')" title="Nastêpna strona"><img src="img/next2.gif" border="0" alt="Nastêpna strona"></a>';
		}
	else	
		{	
	p_arr = '<a href="javascript:photoview('+ (pid+1)
	+')" title="Nastêpne"><img src="img/next.gif" border="0" alt="Nastêpne"></a>';
		}
	}
else p_arr = '<img src="img/next0.gif" border="0" alt="Ostatnie zdjêcie">';

pch = document.getElementById('p_controls');
pch.style.fontFamily = 'Arial';
pch.style.fontColor = '#000000';
pch.style.width = v_width - 2 + 'px'
pch.innerHTML = '<table width="100%" style="font-size:12px;text-align:left"><tr><td width="95%">'
	+ '<tt style="font-size:11px;color:#a0a0a0;font-style:normal;font-family: Arial;margin-right:15px">ID:'+ cp_id + '</tt>'	
	+ ' '+ p_desc[pid] + '</tt>'
	+'</td><td align="right" width="5%"><a href="javascript:pv_close()" title="Zamknij okno"><img src="img/close.gif" border="0" alt="Zamknij okno"></a></td></tr>'
	+'<tr><td width="100%" colspan="2" align="center" style="color:#000000">' + l_arr 
	+ (pid+page_s) + ' z ' + max_id + p_arr + '</td></tr></table>';
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( 
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
} 

function auto_display()
{
dt = getURLParam('dt');
if (dt == '') return;		
else if (dt == 1) photoview(0);
else  photoview(p_width.length-1);	
}
