function advertInit()  { advert.init() }
function advertClose() { advert.close(); }

var advert = {

	date : new Date(),
	isActive : false,

	init : function()
	{
	   var c = U.getCookie('advert');
	   
		if(this.isActive && ((U.getInt(c) + 36000000) <= this.date.getTime() || window.location.toString().match(/www.absolonova.cz\/?$/)))
		{
		   this.open();
		}
		else if(this.isActive)
		{
			var newCookie = 'advert=' + this.date.getTime();

			this.date.setDate(this.date.getDate() + 1);

			newCookie += '; expires=' + this.date.toUTCString();
			newCookie += '; path=/';

			document.cookie = newCookie;
		}
	},
	
	open : function()
	{
   	jsEffects.Curtain.create('#000000');

		var advertMain = document.createElement('DIV');
		advertMain.id = 'advert';
		advertMain.style.background = '#cba97c';
      advertMain.style.width = '384px';
      advertMain.style.position = 'absolute';
      advertMain.style.top = '0';
      advertMain.style.left = '0';
      advertMain.style.color = 'white';
      advertMain.style.fontWeight = 'bold';
      advertMain.style.padding = '0px';
      advertMain.style.border = '3px solid #ffeaac';

		document.body.appendChild(advertMain);
		
		var close = document.createElement('IMG');
		close.width = 36;
		close.height = 36;
		close.src = '/res/close.' + (isIE6 ? 'gif' : 'png');
		close.alt = 'X';
		close.onclick = function() {advert.close()};
		close.style.position = 'absolute';
		close.style.right = '-18px';
		close.style.top = '-18px';
		close.style.cursor = 'pointer';
		
		img = document.createElement('IMG');
		img.src = '/res/pf2012_small.jpg';
		img.width = 384;
		img.height = 500;
		img.alt = 'Přeji Vám příjemné prožití vánočních svátků a úspěšný rok 2012. Ať je Váš nový rok dostatečně funny! Monika ABS.';
		img.id = 'advertImg';

		advertMain.appendChild(img);
		advertMain.appendChild(close);

		U.centerElement(advertMain);
		
		if(parseInt(advertMain.style.top) < 20)
			advertMain.style.top = '20px';

		jsEffects.setOpacity(advertMain, 0);
		jsEffects.fadeIn('advert', {inc : 0.02});

		var newCookie = 'advert=' + this.date.getTime();

		this.date.setDate(this.date.getDate() + 1);

		newCookie += '; expires=' + this.date.toUTCString();
		newCookie += '; path=/';

		document.cookie = newCookie;
	},
	
   close : function()
   {
      jsEffects.cancleEffect(uId($('advert')), null, 'FadeIn');
      document.body.removeChild($('advert'));
      jsEffects.Curtain.destroy();
   }
}

U.setEvent(window, 'onload', advertInit);



