<!--
// by W.Wodarski (c) - w.wlodarski@gmail.com
function zwrocObiekt (objectID,withStyle)
{
	if (withStyle) return (document.getElementById(objectID).style);
	else return (document.getElementById(objectID));
}

function getWindowDimensions()
{
  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;
  }
  dim = new Array();
  dim[0] = myWidth;
  dim[1] = myHeight;
  return dim;
}

function reklamaOn(objectID,tloID)
{
	// trzeba ustawi wielko obrazkw z reklamami
	switch (objectID)
	{
		//case 'drop': w=800; h=500; break;
		case 'ds2009': w=800; h=500; break;
		case 'dsGm2009': w=800; h=500; break;
		case 'bestoff': w=942; h=500; break;
		default: w=800; h=500;
	}	
	
	
	var dim = getWindowDimensions();
	var reklama = zwrocObiekt(objectID,0);
	var reklamaStyle = zwrocObiekt(objectID,1);
	reklamaStyle.left = Math.floor(dim[0] - w)/2 + "px";
	
	// centrowanie w pionie
	var marginesVertical = 20; // naley ustawi margines grny i dolny
	if ((h+2*marginesVertical)<=dim[1])
		var marginTop = Math.floor((dim[1] - h - 2*marginesVertical)/2) + marginesVertical;
	else
		var marginTop = marginesVertical;
	reklamaStyle.top = marginTop + "px";
	reklamaStyle.display = "block";
	
	var tloStyle = zwrocObiekt(tloID,1);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("firefox") != -1) tloStyle.width = "100%"; // Firefox liczy rozmiary obrazu dodajc rozmiary suwakw
	else tloStyle.width = dim[0] + "px";
	
	
	if ((h+2*marginesVertical)<=dim[1]) 
		var hTlo = dim[1] - 2*marginesVertical;
	else
		var hTlo = h;
	
	tloStyle.height = 2*marginesVertical + hTlo + "px";
	tloStyle.display = "block";
	
	var szczegoly = zwrocObiekt('szczegoly_'+objectID,1);
	szczegoly.display = "block";
}

function reklamaOff	(objectID,tloID)
{
	var reklamaStyle = zwrocObiekt(objectID,1);
	reklamaStyle.display = "none";
	var tloStyle = zwrocObiekt(tloID,1);
	tloStyle.display = "none";
	
	var szczegoly = zwrocObiekt('szczegoly_'+objectID,1);
	szczegoly.display = "none";
	document.location="#";
}

/**
*
*  Javascript cookies
*  http://www.webtoolkit.info/
*
**/

function CookieHandler()
{	
	this.setCookie = function (name, value, seconds) {

		if (typeof(seconds) != 'undefined') {
			var date = new Date();
			date.setTime(date.getTime() + (seconds*1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else {
			var expires = "";
		}

		document.cookie = name+"="+value+expires+"; path=/";
	}

	this.getCookie = function (name)
	{	
		name = name + "=";
		var carray = document.cookie.split(';');

		for(var i=0;i < carray.length;i++) {
			var c = carray[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
		}

		return null;
	}

	this.deleteCookie = function (name)
	{
		this.setCookie(name, "", -1);
	}

}


function pokazReklame(nazwa,sekundy)
{
	 // TUTAJ! ustawiamy co ile wizyt na stronie ma si pojawia reklama
	 var freq = 1;
	
	// pod zmienna 'nazwa' kryje si ID obiekltu div z reklam
	var reklamaID = nazwa;
	var tloID = 'tlo_' + nazwa;
	
	var Cookies = new CookieHandler(); // init engine
	if (Cookies.getCookie(nazwa))
	{
		var x = Cookies.getCookie(nazwa); // get cookie
		if (!(x%freq))
		{
			reklamaOn(reklamaID,tloID);
		}
		x++;
		Cookies.setCookie(nazwa, x, sekundy); // set cookie
	}
	else
	{
		Cookies.setCookie(nazwa, 1, sekundy); // set cookie
		reklamaOn(reklamaID,tloID);
	}
}



function czyPokazacReklame(dataStart,dataStop,reklamaID)
{	
	var teraz = new Date();
	teraz.getTime();

	roznica = new Date();
	if (dataStart <= teraz)
		roznica = dataStop - teraz;
	else
		roznica = dataStop - dataStart;
		
	// document.write("rnica: " + (Math.round(roznica/1000)) + " [sec]<br />");
	
	if ((dataStart < teraz)&&(dataStop > teraz))
	{
		// poka reklam
		// document.write(dataStart + "<br />" + dataStop);
		pokazReklame(reklamaID,roznica);
	}
	else
	{
		// usu reklam (jej ciacho)
		var Cookies = new CookieHandler(); // init engine
		Cookies.deleteCookie(reklamaID);
	}
}



function reklama()
{	
	// document.write(poczatek.getTimezoneOffset()/60+"<br />");
	// USTAW DAT POCZTKU I KOCA KAMPANII REKLAMOWEJ

	var poczatek	=	new	Date(2010,(7-1),6,01,00,01);
	var koniec		=	new	Date(2010,(7-1),10,15,00,00);	
	czyPokazacReklame(poczatek,koniec,'ds2009');

	var poczatek	=	new	Date(2009,(5-1),11,2,00,01);
	var koniec		=	new	Date(2009,(5-1),21,8,00,00);	
	czyPokazacReklame(poczatek,koniec,'dsGm2009');

/*
	// zapisy: od 26 lutego (8:00) do 2 marca (15:00) 2008 roku
	var poczatek	=	new	Date(2008,(3-1),16,18,00,01);
	var koniec		=	new	Date(2008,(3-1),18,19,00,00);	
	czyPokazacReklame(poczatek,koniec,'blekitneNiebo');*/
/*
	// zapisy: od 23 stycznia (8:00) do 27 stycznia (20:00) 2008 roku
	var poczatek	=	new	Date(2008,(1-1),23,8,00,01);
	var koniec		=	new	Date(2008,(1-1),27,20,00,00);	
	czyPokazacReklame(poczatek,koniec,'miasta');*/

/*	// zapisy: od 14 padziernika (20:00) do 28 padziernika (20:00) 2007 roku
	var poczatek	=	new	Date(2007,(10-1),14,20,00,01);
	var koniec		=	new	Date(2007,(10-1),28,20,00,00);	
	czyPokazacReklame(poczatek,koniec,'zapisyD');*/
}

-->
