// FUNZIONI ==================================	
// disabilito link attivi ////////////////////
$('.active').click(function(){return false;});
// apri sottomenu header /////////////////////
$.fn.apriSM = function(){
	this.addClass('rolling'); //rollover
	//$('#sfondoSubMenu').css('top', '10px');
	$('.subMenu').css('top', '-10px');
	$('#sfondoSubMenu').animate({'top':'30px'}, 'fast');
	this.children('ul').animate({'top':'20px'}, 'fast');
};
// chiudi sottomenu header ///////////////////
$.fn.chiudiSM = function(){		
	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');	
};
// 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();
	});
});
// Finestra modale ///////////////////////////

// ONLOAD =====================================================
$(function(){			
	// TUTTE LE PAGINE //////////////////////////
	
	// 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);	
		event.preventDefault();		
	});
	
	// effetto fisarmonica
	$("#boxAccordion").tabs("#boxAccordion div.pane", {tabs: 'h3', effect: 'customSlide', initialIndex: null});	
	
	// flash replace

	
	// sottomenu
	$('#mainMenu li.active').filter('.roll').parent().parent().find('#sfondoSubMenu').css({'top':'30px'});
	$('#mainMenu li.active').filter('.roll').children('ul').css({'top':'20px'});
	$('li.roll').hoverIntent(function(){	
		if(!($(this).hasClass('active'))){
			$(this).apriSM();
		}
	}, function(){		
		if(!($(this).hasClass('active'))){
			$(this).chiudiSM();
		}	
	});	
	
	// NUTELLA CON... ///////////////////////////
	// cambia colazione via select
	$('#altreCol').change(function(){
		var target= $(this).attr('value');
		document.location.href=target;
	});
	// mostra/nascondi valori nutrizionali
	$('.changeLink').click(function(){
		var target= $(this).attr('href');
		$(this).parent().hide();
		$(target).fadeIn();
		return false;
	});
});


