// FUNZIONI ==================================	
// disabilito link attivi ////////////////////
$('.active').click(function(){return false;});

// apri dettagli /////////////////////////////
apriLayer= function(layer){
			chiudiLayer();			
			$("#hc"+layer).animate({"height": "110px"}).fadeIn('fast');						
		};
// chiudi dettagli //////////////////////////
chiudiLayer= function(){
	$("#hiddenContent div").animate({"height": "0px"}, function(){
		$(this).hide();
		});			
	};		
// apri Colazione ////////////////////////////
apriColazione= function(col){
	document.location.href='nutella_con.php?colazione='+col;
}
// leggi etichetta ///////////////////////////
leggiEtichetta= function(eti){	
	document.location.href='etichetta.php';
}
// effetto fisarmonica ///////////////////////
$.tools.tabs.addEffect("customSlide", function(i, done) {
	this.getPanes().slideUp('fast');	
	this.getPanes().eq(i).slideDown('fast', function()  {
		done.call();
	});
});

// scarica pdf //////////////////////////////////
function scaricaPDF(pdf){
	switch(pdf){
		case 'etichetta':
		window.open('download/etichetta_nutrizionale.pdf', '_blank');
		break;
		case 'storia':
		window.open('download/la_storia.pdf', '_blank');
		break;
		case 'manifesto':
		window.open('download/Nutella_Manifesto.zip');
		break;
	}
};
// stampa etichetta (3d) //////////////////////////////////
function stampaEtichetta(){
	window.open('download/etichetta_nutrizionale.pdf', '_blank');		
};
// chiedi info (3d) //////////////////////////////////
function apriInfo(){
	window.open('http://www.ferrero.it/?mail=true', '_blank');		
};
// Finestra modale ///////////////////////////
function apriModale(){
		// $('html').addClass('noScroll'); //blocco scroll verticale
		$('select').hide(); // nascondo select per problema ie6			
		$('#modalBoxOverlay').show();	//apro finestra	
	};
	function chiudiModale(){
		// $('html').removeClass('noScroll');
		$('select').show(); 
		$('#modalBoxOverlay, #finestraModale ').hide();
	};
	function mostraContenuto(data){
		var offset =$('#finestraModale').outerHeight()/2;
		if(typeof document.body.style.maxHeight == "undefined") {
			// IE6
			var viewportheight = document.documentElement.clientHeight //altezza area visibile
			var scrOfY = document.documentElement.scrollTop; //scroll verticale
			var topIe6 =scrOfY+(viewportheight/2)-offset;	//margin-top	
			$('#finestraModale').css({'top':topIe6+'px'}).fadeIn();
		}else{
			// tutti gli altri
			$('#finestraModale').css({'top':'50%', 'margin-top':'-'+offset+'px'}).fadeIn();
		};		
		//$('div#finestraModale .messaggio').html(data).css({'visibility':'visible'});
	}
		
// ONLOAD =====================================================
$(function(){			
	// popup
	$('a.popup').click(function(){
		var target=$(this).attr('href');
		var windowLeft = (screen.width - 500) / 2;
  		var windowTop = (screen.height - 400) / 2;
      window.open(target, 'popup', 'height=400, width=500, top=' + windowTop + ',left=' + windowLeft + ',scrollbars=no, resizable=0, menubar=0, toolbar=0, location=0, statusbar=0, fullscreen=0');
      return false;
	});
		// popup manifesto leggi
	$('a.popupManLeggi').click(function(){
		var target=$(this).attr('href');
		var windowLeft = (screen.width - 630) / 2;
  		var windowTop = (screen.height - 578) / 2;
      window.open(target, 'mnfs', 'height=578, width=630, top=' + windowTop + ',left=' + windowLeft + ',scrollbars=no, resizable=0, menubar=0, toolbar=0, location=0, statusbar=0, fullscreen=0');
      return false;
	});
	// popup manifesto aderisci
	$('a.popupManAd').click(function(){
		var target=$(this).attr('href');
		var windowLeft = (screen.width - 645) / 2;
  		var windowTop = (screen.height - 500) / 2;
      window.open(target, 'mnfsA', 'height=500, width=645, top=' + windowTop + ',left=' + windowLeft + ',scrollbars=no, resizable=0, menubar=0, toolbar=0, location=0, statusbar=0, fullscreen=0');
      return false;
	});
	// finestre modali
	$('a[rel="ajax"]').live('click', function(event){ //intercetto il click
		apriModale();	
		var target = $(this).attr('href');			
		//$('div#finestraModale .messaggio').load(target, null, mostraContenuto);	
		mostraContenuto();
		event.preventDefault();		
	});
	
	// effetto fisarmonica
	$("#boxAccordion").tabs("#boxAccordion div.pane", {tabs: 'h3', effect: 'customSlide', initialIndex: null});	
	
	// FLASH REPLACE ///////////////////////////////////////////////////////////
	// HOME PAGE
	$('#videoHp').flashembed({
			src:'http://ferrerovideo.farm.inrete.it/FerreroPlayer/player.swf',
			wmode: 'transparent',
			quality: 'high',
			 allowfullscreen: 'true',
			 allowscriptaccess: 'sameDomain'
			},	{
			hq: 'http://ferreroenc.inrete.it/files/D2/90/97WdyyCr2xsNEfzQ3ZLHtIzLCnV0/6f8f14526119798805fd31cbb8286e3a.flv',
	  		//lq: 'http://ferreroenc.inrete.it/files/D2/90/97WdyyCr2xsNEfzQ3ZLHtIzLCnV0/343404157413f288b92f8978965326f0.flv',
	  		splashimg: 'http://ferreroenc.inrete.it/files/D2/90/97WdyyCr2xsNEfzQ3ZLHtIzLCnV0/splash_video_hp.jpg',
			autoplay: 'false',
			//bwCheck: 'true',
			bwMsg: 'Per limitare i tempi di buffering puoi anche vedere questo video in bassa risoluzione'	
			}
		);	
	//includes/footer.php
	$('#counter').flashembed({src:'swf/counter.swf', wmode:'transparent'}); 
	//nutella_con.php
	$('#boxNutellaCon').flashembed({src:'swf/nutella_con.swf', wmode:'transparent'}); 
	//confezioni.php
	$("#flashConf").flashembed({src:'swf/pagina_prodotto_def.swf', wmode:'transparent'});  
	//etichetta.php
	$('#boxEtichetta').flashembed({src:'swf/etichetta.swf', wmode:'transparent'}); 
	 // nocciola.php
	$('#flashNocciola').flashembed({src:'swf/nocciola.swf'}); 
	// nutella_mito.php
	$('#flashMito').flashembed({src:'swf/storia_nutella.swf'});
	 // sapevi_che.php
	$('#flashSapevi').flashembed({src:'swf/sapevi_che.swf'});
	// manifesto.php
	$('#flashManifestoSmall').flashembed({src:'swf/pin.swf', wmode:'transparent'});
	$('#flashManifestoBig').flashembed({src:'swf/manifesto.swf', wmode:'transparent'});
	// modale 3D
	$('#flash3d').flashembed({src:'swf/popup_3d.swf', wmode:'transparent'}); 
	
	
	// MENU ROLLOVER //////////////////////////////////////////////////////
	// sottomenu iniziale
	$('#mainMenu li.active').filter('.roll').parent().parent().find('#sfondoSubMenu').css({'top':'30px'});
	$('#mainMenu li.active').filter('.roll').children('ul').css({'top':'20px'});
	// namespace per le variabili
	$.g = {};
	$.g.wait = false;
	// sottomenu ROLLOVER
	$('li.roll').hoverIntent(function(){			
		if(!($(this).hasClass('active'))){
			if($.g.wait==false){
				$.g.wait=true; 
				$(this).addClass('rolling'); 
				$('.subMenu').css('top', '-10px');
				$('#sfondoSubMenu').animate({'top':'30px'}, 'fast');
				$(this).children('ul').animate({'top':'20px'}, 'fast');
				$(this).children('ul').queue(function(){ 
				$.g.wait=false; 
				$(this).dequeue();
				});
			};
		} 
	// sottomenu ROLLOUT
	}, function(){		
		if(!($(this).hasClass('active'))){		
			$(this).children('ul').css({'top':'-10px'});							
			$('#sfondoSubMenu').css('top', '10px');
			$('#mainMenu li.active').filter('.roll').children('ul').css({'top':'20px'});
			$('#mainMenu li.active').filter('.roll').parent().parent().find('#sfondoSubMenu').css({'top':'30px'});	
			$(this).removeClass('rolling');		
			if($.g.wait==true){
				$(this).children('ul').stop();
			}		
		}	
	});	
	
	// cambia pagina via select
	$('.cambiaSelect').change(function(){
		var target= $(this).attr('value');
		document.location.href=target;
	});
	
	// NUTELLA CON... ///////////////////////////
	// mostra/nascondi valori nutrizionali
	$('.changeLink').click(function(){
		var target= $(this).attr('href');
		$(this).parent().hide();
		$(target).fadeIn();
		return false;
	});
	
		
});

