// Gallery 1.0
// Author: Adam Major
// Copyright: Freshdata, http://www.freshdata.pl
// Date: 2007.06.24
// 

function pv_close()
{
phw = document.getElementById('pview');	
phw.style.display = 'none';	
}

function page_jump(nb, dt)
{
phw = document.getElementById('pview');	
phw.style.display = 'none';
location='gallery_photo.php?id=' + gid + '&pg=' + nb+'&dt='+dt;	
}

function photoview(pid)
{
if (self.innerWidth)
	{
		var frameWidth = self.innerWidth;
		var frameHeight = self.innerHeight;
		var frameTop = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		var frameWidth = document.documentElement.clientWidth;
		var frameHeight = document.documentElement.clientHeight;
		var frameTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		var frameWidth = document.body.clientWidth;
		var frameHeight = document.body.clientHeight;
		var frameTop = document.body.scrollTop;
	}	
	
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);
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.display = 'block';
phw.innerHTML = '<div id="photo"></div><div id="p_controls"></div>';

ph = document.getElementById('photo');
ph.style.height = v_height - 45 + 'px';	
ph.innerHTML = '<img src="dimg/gallery/full/' + 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.width = v_width - 2 + 'px'
pch.innerHTML = '<table width="100%" style="font-size:12px;"><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]
	+'</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">' + 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;		
if (dt == 1) photoview(0);
else  photoview(p_width.length-1);	
}
