function GetScreenSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ parseInt(myWidth), parseInt(myHeight) ];
}

function TopLayer()
{
	$('#TopLayerContent').each(function(){
		var tlWidth = parseInt($(this).width());
		var tlHeight = parseInt($(this).height());
		var screenSize = GetScreenSize();
		var pozycjaX = ((screenSize[0] - tlWidth) / 2) - 9;
		//var pozycjaY = (screenSize[1] - tlHeight) / 2;
		var pozycjaY = 163;
		if (pozycjaX < 0) pozycjaX = 0;
		if (pozycjaY < 0) pozycjaY = 0;
		$(this).parent().css('width', screenSize[0] + 'px');
		$(this).parent().css('height', screenSize[1] + 'px');
		$(this).parent().css('left', '0px');
		$(this).parent().css('top', '0px');
		$(this).css('left', pozycjaX + 'px');
		$(this).css('top', pozycjaY + 'px');
		$('BODY').css('overflow-y', 'hidden');
	});
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function TopLayerClose()
{
	var chb = $('#TopLayer').find('INPUT:eq(0)').attr('checked');
	if (chb)
	{
		var nazwa = $('#TopLayer').find('INPUT:eq(0)').attr('name');
		createCookie(nazwa, 1, 365);
	}
	$('#TopLayer').css('left', '-3000px');
	$('#TopLayer').css('top', '-3000px');
	$('#TopLayer').css('visibility', 'hidden');
	$('BODY').css('overflow-y', 'auto');
}

function TopLayerInit()
{
	if (!getCookie('toplayer_patt'))
	{
		TopLayer();
	}

}

$(document).ready(function(){
	$('A[rel^="lightbox"]').lightBox();
});

