/* animazione homePage */
function homePage() {
	$("#hf_link a").css("opacity",0);
	$("#cf_link a").css("opacity",0);
	$("#hf_enter").css("opacity",0);
	$("#cf_enter").css("opacity",0);
	
	function hfOver(){
		$("#hf_link a").mouseover(function(){
			if ($.browser.msie) {
				if ($.browser.version == "6.0") {
					$("#cf_tab a").css({color:"#697175", background:"transparent url(../img/menu/cf_arrow_hover.gif) no-repeat scroll right top"});
					$("#cf_tab").css({background:"transparent url(../img/menu/cf_tab_hover.png) no-repeat scroll left top"});
					$("#hf_tab a").css({color:"#ffffff", background:"transparent url(../img/menu/hf_arrow.gif) no-repeat scroll right top"});
					$("#hf_tab").css({background:"transparent url(../img/menu/hf_tab.png) no-repeat scroll left top"});
					$(document).pngFix();
				}
			}
			$("#enter :animated").stop();
			$("#hf_link a").css({zIndex:10}).animate({width:"575px"},250);
			$("#cf_link a").css({zIndex:5}).animate({width:"390px"},250);
			$("#hf_link a").css({zIndex:10}).css({opacity:1});
			$("#cf_link a").css({zIndex:5}).css({opacity:0});
			$("#hf_pic").css({zIndex:9}).animate({width:"577px", opacity:1},250);
			$("#cf_pic").css({zIndex:4}).animate({width:"390px", opacity:0.4},250);
			$("#hf_tab").css({zIndex:10}).animate({left:"357px", opacity:1},250);
			$("#cf_tab").css({zIndex:4}).animate({opacity:0.3},250);
			$("#hf_enter").css({zIndex:10}).animate({opacity:1},250);
			$("#cf_enter").css({zIndex:4}).animate({opacity:0},100);
		});
		$("#hf_link a").mouseout(out);
	}
	
	function cfOver(){
		$("#cf_link a").mouseover(function(){
			if ($.browser.msie) {
				if ($.browser.version == "6.0") {
					$("#cf_tab a").css({color:"#40545e", background:"transparent url(../img/menu/cf_arrow.gif) no-repeat scroll right top"});
					$("#cf_tab").css({background:"transparent url(../img/menu/cf_tab.png) no-repeat scroll left top"});
					$("#hf_tab a").css({color:"#acacae", background:"transparent url(../img/menu/hf_arrow_hover.gif) no-repeat scroll right top"});
					$("#hf_tab").css({background:"transparent url(../img/menu/hf_tab_hover.png) no-repeat scroll left top"});
					$(document).pngFix();
				}
			}
			$("#enter :animated").stop();
			$("#cf_link a").css({zIndex:10}).animate({width:"575px"},250);
			$("#hf_link a").css({zIndex:5}).animate({width:"388px"},250);
			$("#cf_link a").css({zIndex:10}).css({opacity:1});
			$("#hf_link a").css({zIndex:5}).css({opacity:0});
			$("#cf_pic").css({zIndex:9}).animate({width:"577px", opacity:1},250);
			$("#hf_pic").css({zIndex:4}).animate({width:"390px", opacity:0.4},250);
			$("#cf_tab").css({zIndex:10}).animate({opacity:1},250);
			$("#hf_tab").css({zIndex:4}).animate({left:"169px", opacity:0.3},250);
			$("#cf_enter").css({zIndex:10}).animate({opacity:1},250);
			$("#hf_enter").css({zIndex:4}).animate({opacity:0},100);
		});
		$("#cf_link a").mouseout(out);
	}
	
	function out(){
		if ($.browser.msie) {
			if ($.browser.version == "6.0") {
				$("#cf_tab a").css({color:"#40545e", background:"transparent url(../img/menu/cf_arrow.gif) no-repeat scroll right top"});
				$("#cf_tab").css({background:"transparent url(../img/menu/cf_tab.png) no-repeat scroll left top"});
				$("#hf_tab a").css({color:"#ffffff", background:"transparent url(../img/menu/hf_arrow.gif) no-repeat scroll right top"});
				$("#hf_tab").css({background:"transparent url(../img/menu/hf_tab.png) no-repeat scroll left top"});
				$(document).pngFix();				
			}
		}
		$("#enter :animated").stop();
		$("#cf_link a").css({zIndex:5}).animate({width:"482px"},250);
		$("#hf_link a").css({zIndex:5}).animate({width:"482px"},250);
		$("#cf_link a").css({zIndex:5}).css({opacity:0});
		$("#hf_link a").css({zIndex:5}).css({opacity:0});
		$("#cf_pic").css({zIndex:4}).animate({width:"484px", opacity:1},250);
		$("#hf_pic").css({zIndex:4}).animate({width:"484px", opacity:1},250);
		$("#hf_tab").css({zIndex:5}).animate({left:"264px", opacity:1},250);
		$("#cf_tab").css({zIndex:10}).animate({opacity:1},250);
		$("#hf_enter").css({zIndex:4}).animate({opacity:0},100);
		$("#cf_enter").css({zIndex:4}).animate({opacity:0},100);
	}
	
	// init
	hfOver();
	cfOver();
	out();
}


/* tooltip homePage */
function tooltipHome(){
	$("#markets ul li a div").css({display:"block", opacity:0});
	
	$("#markets ul li").hover(function(){
		$("#markets :animated").stop();
		$(this).find("div").animate({opacity:0.9},200).show();
		$(this).find("a").addClass("on");
	},function(){
		$("#markets :animated").stop();
		$(this).find("div").hide();
		$(this).find("a").removeClass("on");
	});
}

/* vertical align link pannello azienda */
function vertAlignLinkHome() {
	$("#about_hp a").each(function(){
		switch ($(this).height()) {
			case 11:
				$(this).css("padding","7px 0px 8px 31px");
			break;
			case 22:
				$(this).css("padding","4px 0px 2px 31px");
		}
	});
}


function allineaMercati(){
	h2Width = $("#markets h2").width()+8; // 8 è il padding dell'h2
	maxUlWidth = 976 - h2Width - 5; // 5 è il padding dell'ul

	var ulWidth = 0;
	var numMarkets = $("#markets ul li a").size();
	
	$("#markets ul li a").each(function(i){
		ulWidth = ulWidth + $("#markets ul li a:eq("+i+")").width();
	});
	
	padding = Math.floor(((maxUlWidth - ulWidth)/numMarkets)/2);
	$("#markets ul li a").css("padding","3px " + padding + "px");
}


function allEvents() {
	$("#events_hp a.more").css("position","absolute");
	$("#events_hp a.more").css("zIndex","100");
	$("#events_hp a.more").css("left","50%");
	$("#events_hp a.more").css("margin-left","352px");
	$("#events_hp a.more").css("top","527px");
	$("#events_hp a.more").css("textAlign","right");
	$("#events_hp a.more").css("width","120px");
}


/* init homePage */
$(document).ready(function(){
	homePage();
	tooltipHome();
	vertAlignLinkHome();
	allineaMercati();
	allEvents();
	//$("#enter").pngFix({blankgif:'../img/homepage/transp.gif'});
	$(document).ready(function(){
	if ($("body").attr("area") == "1") {
			$("#cf_pic").css("background-image","url(../img/img_commercial_fitness.jpg)");
			$("#cf_pic img").attr("src","img/img_commercial_fitness.jpg");
		}
	});
});
