/*(C)Andrea Giammarchi*/;(function(a,n,y,I,E,A,c,t,i,v,e,X){var l,O,G="getAttribute",P="parentNode",T="type",p=function(i,s,a){while(i<a[I])s+=e[t](a[i++].nodeName)?a[i-1][A]:"";return s};if(!window.opera&&/msie (6|7)/i[t](navigator.userAgent)){i.write("<"+c+" defer src=//:></"+c+">");c=i[y](c);c[c[I]-1].onreadystatechange=function(){if((c=this).readyState=="complete"){for(l=i[y](E);n<l[I];n++)if(v[t]((O=l[n])[G](T)))a(O);c[P].removeChild(c)}};window.attachEvent("onload",function(){for(l=i[y](E),n=0;n<l[I];n++)if(v[t]((O=l[n])[G](T))){a(O,1);O[A]=O[A].split(">")[0]+">"+p(0,"",O.childNodes)+O.innerHTML.replace(X,"")+"</"+E+">"}})}else if(i[a="addEventListener"])i[a]("DOMContentLoaded",function(){for(l=i[y](E);n<l[I];n++)if(v[t]((O=l[n])[G](T)))O[P].replaceChild(O.cloneNode(true),O);},false);})(function(O,v){O.style.visibility=v?"visible":"hidden"},0,"getElementsByTagName","length","object","outerHTML","script","test",document,/^application\/x-shockwave-flash$/i,/^param$/i,/^\s+|\s+$/g);
/*
 *
 *
 * OnLoad
 *
 *
 */
$(function(){
	$('<div id="pboverlay"></div>').appendTo('body');
	/*
	 * CHEST
	 **/
	$.ajax({
		url: "/news.html",
		success: function(data){
			var $response=$(data);
			chest=$response.filter('#chest');
			$('body').append(chest).append('<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4f2811f34e37e4f7"></script>');
			$('#chest').after('<div id="chest-controll"><div class="wrap"></div></div>');
			$('#chest>div.chest-item').css('display','none').each(function(){
				$('#chest-controll>.wrap').append('<a id="chest-controll-'+$(this).attr('id')+'" href="#'+$(this).attr('id')+'">'+$(this).attr('title')+'</a>');
				$(this).append('<div class="clear"></div><div class="chest-close"></div><div class="clear"></div>');
			});
			$('div.chest-close').live('click',function(e){
				e.preventDefault();
				$('#pboverlay').fadeOut(1000);
				$('#chest>div.chest-item').slideUp(1000);
			});
			$('#chest-controll a').live('click',function(e){
				e.preventDefault();
				target=$(this).attr('href');
				target=target.substring(target.indexOf('#')); // IE7FIX

				if($('#chest>div.chest-item:visible').length>0){
					$('#chest>div.chest-item:visible').fadeOut(800,function(){
						$('#chest>div.chest-item'+target).fadeIn(800);
					});
				} else {
					$('#pboverlay').css({
						'display':'block',
						'opacity':0,
						'width':document.body.clientWidth,
						'height':document.body.clientWidth
					}).animate({
						'opacity':'0.8'
					}, 800);
					$('#chest>div.chest-item'+target).slideDown(800);
				}
				
			})
		}
	});
	/*
	 * Load FadeIn
	 **/
	$('#wrap>div:not(#header,#footer)').css({'display':'none'}).fadeIn(1000);
    $("a[href^='http://']:not([href*='"+location.hostname+"'])").attr("target", "_blank");
	$('a[rel^=pengine]').css('cursor','pointer');
	
	/*
	 * Cookie
	 * (controllo)
	 **/
	if (document.cookie.length > 0) {
		var inizio = document.cookie.indexOf('pomilioslpash' + "=");
		if (inizio == -1){
			/* Animazione */
			$('#content').css({
				'display':'none',
				'position':'relative',
				'z-index':'99'
			}).fadeIn(2000);
			
			$('<img src="/template/certificazione-etica.gif" alt="Certificazione Etica" />').css({
				'margin-top':(window.innerHeight/2)+'px',
				'display':'none'
			}).appendTo('#pboverlay');
			
			$('#pboverlay').css('display','block');
			
			$('#pboverlay img').delay(600).fadeIn(1500,function(){
				$('#pboverlay').delay(3000).fadeOut(2000,function(){$(this).empty()});
				$('#content').pengine({'type':'auto','interval':8000});
			});
		}
	} else $('#content').pengine({'type':'auto','interval':8000});
	
	/* (Genera) */
	var scadenza = new Date();
	var adesso = new Date();
	scadenza.setTime(adesso.getTime() + (23 * 3600 * 1000));
	document.cookie = 'pomilioslpash=true; expires=' + scadenza.toGMTString() + '; path=/';
	
	// if(location.pathname=='/') {}
	/* if(document.referrer == null || document.referrer.indexOf(window.location.hostname) < 0) {}*/
	// $('body').raptorize({'enterOn' : 'konami-code' /*, 'enterOn' : 'timer', 'delayTime' : 2000 */})
	
	/*
	 * jqengine
	 **/
	$('.media,.ideasfactory,.celebrazioni,.mondo,.storia,.generazioni,.bibliografia,.casehistory,.clienti,.rhinostory,.blummspecialist,.gallery,.sociale,.coverstory,.interview,.consulenti,.languages').find('#content').pengine();
	
});
