
// Finestra modale ///////////////////////////
function apriModale(){
		$('#flashConf object, #flashConfNatale object').hide();
		$('select').hide(); // nascondo select per problema ie6			
		$('#modalBoxOverlay').show();	//apro finestra	
	};
	function chiudiModale(){	
		$('#flashConf object, #flashConfNatale object').show();	
		$('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();		
	});
	
	//tutti gli share su fb aprono in una nuova finestra.
	$('a.fb', 'a[name=fbShare]').live('click', function(event){ //intercetto il click		
		var target = $(this).attr('href');
		window.open(target);
		event.preventDefault();
	});
	
	// effetto fisarmonica
	$("#boxAccordion").tabs("#boxAccordion div.pane", {tabs: 'h3', effect: 'customSlide', initialIndex: null});	
	
	
	
	// MENU ROLLOVER //////////////////////////////////////////////////////
	// sottomenu iniziale
	$('#mainMenu li.active').filter('.roll').parent().parent().find('#sfondoSubMenu').css({'top':'30px'});
	$('#mainMenu li.active').filter('.roll').children('ul').show();//.css({'top':'20px'}).show();
	// 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').hide();//.css('top', '-10px');//.hide();
				$('#sfondoSubMenu').animate({'top':'30px'}, 'fast');
				$(this).children('ul').delay(200).fadeIn();//.animate({'top':'20px'}, 'fast');//.fadeIn();
				$(this).children('ul').queue(function(){ 
				$.g.wait=false; 
				$(this).dequeue();
				});
			};
		} 
	// sottomenu ROLLOUT
	}, function(){		
		if(!($(this).hasClass('active'))){		
			$(this).children('ul').hide();//.css({'top':'-10px'});//.hide();							
			$('#sfondoSubMenu').css('top', '10px');
			$('#mainMenu li.active').filter('.roll').children('ul').fadeIn();//.css({'top':'20px'});//.fadeIn();
			$('#mainMenu li.active').filter('.roll').parent().parent().find('#sfondoSubMenu').css({'top':'30px'});//.fadeIn();	
			$(this).removeClass('rolling');		
			if($.g.wait===true){
				$(this).children('ul').stop();
				$('#sfondoSubMenu').stop();
			}		
		}	
	});	
	
});


