var width=0;
var tempX = 0; 
var tempY = 0; 
var scrollY = 0; 

function pokaz_powiekszenie(wiersz,nazwa_zdjecia,szerokosc,wysokosc)
{
	document.getElementById('divZdjecie').style.width=szerokosc+'px';
	document.getElementById('divZdjecie').style.height=(wysokosc+30)+'px';
	document.getElementById('imgZdjecie').src='galeria/'+nazwa_zdjecia;
	document.getElementById('divZdjecie').style.left=(screen.width-750)/2+(750-szerokosc)/2+'px';
	document.getElementById('divZdjecie').style.display='block';
}

function ukryj_powiekszenie(div_id)
{
	document.getElementById(div_id).style.display='none';
	document.getElementById('imgZdjecie').src='';
}

function poprzednieZdjecie()
{	
	
	if (akt_zdjecie>0)
	{
		akt_zdjecie--;
		document.getElementById("zdjecie").src='upload/'+tz[akt_zdjecie];
	}
	sprawdzPrzewijanie();
}

function nastepneZdjecie()
{		
	if (akt_zdjecie<iz-1)
	{
		akt_zdjecie++;
		document.getElementById("zdjecie").src='upload/'+tz[akt_zdjecie];
	}
	sprawdzPrzewijanie();
}

function sprawdzPrzewijanie()
{
	document.getElementById("aktzd").innerHTML=(akt_zdjecie+1);
	
	if (akt_zdjecie>0) document.getElementById("zdjprev").style.display='';
	else document.getElementById("zdjprev").style.display='none';
	
	if (akt_zdjecie<iz-1) document.getElementById("zdjnext").style.display='';
	else document.getElementById("zdjnext").style.display='none';
}

function addEvent(obj, type, fn)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(type, fn, false);
	}
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() {obj["e"+type+fn](window.event); }
		obj.attachEvent("on"+type, obj[type+fn]);
	}
}

function eventStart(e)
{	
	var IE = document.all?true:false; 
	if (IE)
	{ 
		width=document.body.clientWidth;
	} 
	else
	{ 
		width=window.innerWidth;
	}
	
	addEvent(document.getElementById("oferta"), "mousedown", eventMouseDown);
	addEvent(document, "keydown", eventKeyDown);
	(e.preventDefault) ? e.preventDefault() : (e.returnValue = false);
}

function eventKeyDown(e)
{	
	if (e.keyCode==27)
	{
		for (var ii=2; ii<=72; ii++)
		{
			if (document.getElementById('dOferta'+ii))
			{
				document.getElementById('dOferta'+ii).style.display='none';
			}
		}
	}
}
//var standardBody = (document.compatMode=="CSS1Compat")? document.documentElement: document.body; //This won't contaminate anything; I'm using a closure (along with some other code, like the event handler)
function eventMouseDown(e)
{	
	var IE = document.all?true:false; 
	
	if (IE)
	{ // grab the x-y pos.s if browser is IE 
		tempX = event.clientX;
		//tempY = document.documentElement.scrollTop; 
		tempY = event.clientY+document.body.scrollTop+document.documentElement.scrollTop; 
		//alert(standardBody.scrollTop); 
	} 
	else
	{ // grab the x-y pos.s if browser is NS 
		tempX = e.pageX; 
		tempY = e.pageY;
		//tempY = window.scrollY;
		//scrollY = window.scrollY; 
	} 
	//(e.preventDefault) ? e.preventDefault() : (e.returnValue = false);
	//alert(tempX);
}

function pokazZdjecia(aktg)
{
	akt_galeria=aktg;
	akt_zdjecie=0;
	if (akt_galeria==1)
	{
		tz=iz_wykonczone1;
		document.getElementById("rm").innerHTML='50m<sup>2</sup>';
	}
	else if (akt_galeria==2)
	{
		tz=iz_wykonczone2;
		document.getElementById("rm").innerHTML='78m<sup>2</sup>';
	}
	else if (akt_galeria==3)
	{
		tz=iz_wykonczone3;
		document.getElementById("rm").innerHTML='91m<sup>2</sup>';
	}
	else if (akt_galeria==4)
	{
		tz=iz_wykonczone4;
		document.getElementById("rm").innerHTML='93m<sup>2</sup>';
	}
	document.getElementById("zdjecie").src='upload/'+tz[0];
	iz=tz.length;
	
	document.getElementById('dZdjecia').style.left=Math.ceil((width-853)/2)+'px';
	document.getElementById('dZdjecia').style.display='block';
	document.getElementById("izd").innerHTML=(iz);
}

function pokaz_szczegoly(id,ile)
{
	for (var ii=2; ii<=82; ii++)
	{
		if (document.getElementById('dOferta'+ii))
		{
			document.getElementById('dOferta'+ii).style.display='none';
		}
	}
	ido = id;
	document.getElementById('dOferta'+ido).style.top=tempY-300+'px';
	document.getElementById('dOferta'+ido).style.left=Math.ceil((width-250)/2)+'px';
	document.getElementById('dOferta'+ido).style.display='block';
}

addEvent(window, "load", eventStart); 

$(document).ready(function() {
   
	if ($.cookie("popup") != 'fired' )
	{
		var IE = document.all?true:false; 
		if (IE)
		{ 
			width=document.body.clientWidth;
		} 
		else
		{ 
			width=window.innerWidth;
		}
		/*
		document.getElementById('popup_lightbox').style.left=Math.ceil((width-474)/2)+'px';
		//odpala banner przy starcie strony
		$('#popup_lightbox').animate({
		'top' : '35%'
		}, {
		duration: 2000,
		easing: 'easeOutBounce'
		});
		
		//cookie zapamiętuje czy banner był już odpalony
		$.cookie("popup", "fired");
		*/
	}

});
