function setMegaMenu(){
	if(isIE7){
		$(".MegaMenu").css({"margin-left":getMenuitemsPosition(-154)})  
		 
	}else{
		$(".MegaMenu").css({"margin-left":getMenuitemsPosition(33)})  
	} 
}

function getMenuitemsPosition(gap){ 
	gap=gap||0;
	return ($("#outer-pos").offset().left-40+gap)+'px';
}

(function ($) {
	$.fn.vAlign = function(gap) {
		gap=gap||0;
		return this.each(function(i){
		var ah = $(this).height();
		var ph = $(this).parent().height();
		var mh = (ph - ah) / 2 + gap;
		$(this).css('margin-top', mh);
		});
		
	};
})(jQuery);


try{fadeInSpeed=fadeInSpeed || 1}
catch(e){fadeInSpeed=1} 
		
$(function(){
	
	
	$("#template-header1").load("page-fixed-empty.xml",function(){
		var languageBar=$("#languages-bar");
		var logo=$("#Barra-bianca-logo");
		var payOff=$("#pay-off");
		var mainTopic=$("#main-topic");
		//mainTopic.css({position:'fixed'})
		$("img[src^='http://s12.shinystat.com/cgi-bin/shinystat.cgi']" ).hide()
	 
		var resizeElements = function(onload){ 
			onload=onload||0;
			
			if(onload){
				if(fadeInSpeed<=1) payOff.center().show();
				else setTimeout(function() { payOff.center().fadeIn(2000); },800)
			}
			
			languageBar.gapFromCenter(400).show();
			logo.gapFromCenter(-830).show();
			setMegaMenu()
			 
		}; 	
		
		var onWindowResize = function(){
			resizeElements();
			$(".MegaMenuTable").css({"margin-left":getMenuitemsPosition(-5)})	
		}
		
		resizeElements(1);
		 
		
		$(window).resize(onWindowResize); 
		    
		mainTopic.fadeIn(fadeInSpeed,fadeOuter)    
		 
		setMegaMenu();	
		
		
		$("#mnu-item-search").css({"margin-left":"23px",border:'0px solid black','text-align':'right'})
		
		try{
			//console.log( getMenuitemsPosition(63) )
		}catch(e){}
		
		
		if(fadeInSpeed<=1)$(".MegaMenuLink").megamenu(".MegaMenuContent", { width: "100%" }); 
		 
		$("#bread-crumb").wrapInner('<span id="bread-crumb-text"></span>')
		 
		 var msie6 = $.browser == 'msie' && $.browser.version < 7;
		 var top=44;
			
			if (!msie6) {
				 
				$(window).scroll(function (event) { 
					var y = $(this).scrollTop();
					if (y >= top) {
						//$('#main-topic').addClass('fixed');
					} else {
						//$('#main-topic').removeClass('fixed');
					}
				});
			}
			
			 
 
		
		
	})	
	
	 
	 
	function fadeOuter(){
			$("#outer").wrap('<div id="outer-shadow"   ></div>')
			$("#outer")
				//.append("<div id='main-page-footer'>Technital&#174; spa &#232; un marchio registrato. Ogni diritto &#232; riservato. Ogni riproduzione non prevista dall'azienda &#232; vietata e sar&#224; perseguitata a norma di legge secondo il codice penale vigente</div>")
				.fadeIn(fadeInSpeed,function(){	
					
					if(fadeInSpeed>1)$(".MegaMenuLink").megamenu(".MegaMenuContent", { width: "100%" }); 
					 
					setTimeout(function() {  
						$(".MegaMenuTable").css({width:"900px","margin-left":getMenuitemsPosition(-5)})	  
						
						if(isIE7){
							
							$(".mnu-item-text").css({
								"position":"relative"
								,"top":"-4px"
							})
							
							$(".mnu-item-text-sector").css({
								"position":"relative"
								,"top":"-0px"
							})
							
							$("#MegaMenuContentShadow,#MegaMenuContent").css({
								"margin-left":"-200px" 
								,"border-right":"13px solid black" 
								,"position":"absolute"  
							}).width(12000)  
							$("body").css({ "overflow-x":"hidden"})
						}
					}, 50); 
					
					try{ if(afterFadeIn)  afterFadeIn()  }catch(e){}
					
				})	
	}
})
