$(window).load(function() {
		
	// RICERCA TRANSFORM
	$("#service_search").each(function() {
		h = $(this).html();
		$(this).html("<table align=\"right\" cellspacing=\"0\" cellpadding=\"0\"><tr><td class=\"L\">"+h+"</td><td class=\"R\"></td></tr></table>");
	});
	$("#service_search").show();
	
	// MENU POSITION		
	menuW = 0;
	$("#menu ul li").each(function() {
		mr = parseInt(($(this).css("margin-right")).replace("px",""));
		menuW += $(this).width()+mr;
	});
	var distanzaMenuUL = ((940 - menuW)/2);
	$("#menu ul").css("left",distanzaMenuUL+"px");
	$("#menu ul").css("visibility","visible");	
	
	// MENU HOVER	
	var s;
	$("#menu li").hover(function() {
		s=0;
		if($(this).hasClass("current")) s=1;
		if(s==0) {
			$(this).addClass("current");
		}
		
		if($(this).find("#popMenu_8").size()==1 || $(this).find("#popMenu_9").size()==1) {
			$(".wallobject").css("visibility","hidden");
		}
		
		if(isIE6()) $("select").css("visibility","hidden");
		$(this).find(".popMenu").css("visibility","visible");

	},function() {
		if(s==0) $(this).removeClass("current");				
		$(this).find(".popMenu").css("visibility","hidden");		
		$(".wallobject").css("visibility","visible");		
		if(isIE6()) $("select").css("visibility","visible");		
	});
	
	
	// LOGINBOX	
	$("#service_menu .login").hover(function() {
		$(this).find(".loginLink").addClass("current");
		$("#loginBox").show();
	},function() {
		$(this).find(".loginLink").removeClass("current");		
		$("#loginBox").hide();	
	});
	
	
	
	// POPITEMS
	$(".popItems").hover(function() {$(this).css("cursor","pointer");},function() {$(this).css("cursor","default");});
	$(".popItems").click(function() {
		$(".popMenu").css("visibility","hidden");
		location.href = $(this).find(".popContents h2").attr("rel");
	});
	
	
	var larghezzaUltimoLI = parseInt($(".popMenu:last").parent().position().left);
	var ul_length = 940;
	var popMenuLength = 832;
	var offset = 30;
	
	var f = (ul_length + offset) - larghezzaUltimoLI;
	var g = popMenuLength - f - distanzaMenuUL - offset - 48;
			
	// POPMENU
	$(".popMenu").each(function() {		
		$(this).show();		
		// ricalcolo
		popMenuLength = $(this).find("table").width();
		g = popMenuLength - f - distanzaMenuUL - offset - 48;
		$(this).width(popMenuLength+14);
		$(this).hide();

		var li_distanceFromLeft = parseInt($(this).parent().position().left);
		var li_length = parseInt($(this).parent().width());		
		var v = parseInt(-((li_distanceFromLeft * g) / larghezzaUltimoLI)) + (-distanzaMenuUL - offset - 48);
		$(this).css("left",v+"px");		
		$(this).show();		
	});
	
	
	// RICERCA POP		
	var default_search_value = $("#search_pop_contents .search_pop_q").val();	
	$(".mondo_prev").hide();
	$("#mondo_icons").css("margin-top","105px");
	
    $("#service_search").click(function() { 
		$("#search_pop_contents .search_pop_q").attr("value",default_search_value);	
		$.blockUI({
			message: $("#search_pop"),
			css : {
				top: "100px",
				cursor: "default",
				border: "none",
				backgroundColor: "transparent",
				left: "50%",
				marginLeft: "-193px"
			}, 
		    overlayCSS:  { 
		        backgroundColor: "#000", 
		        opacity:         0.9
		    },		
		    focusInput: false
		});     
		
		
		
		$(".blockUI").css("z-index","99999999");
		
		if($.browser.safari) {
			$(".flashObject").hide();
		}
		
		$("#mondo_icons ul .m").click(function() {
			$("#mondo_icons ul .m a").removeClass("current");
			$(this).find("a").addClass("current");
			
			if($.browser.msie) {
				$("#mondo_icons ul .m a").css("background-position","0 0");
				$(this).find("a").css("background-position","0 -67px");
			}
			
			id = "#mondo_prev_"+$(this).find("a").attr("id");
			if(!$(".mondo_prev").is(":visible")) {
				$("#mondo_icons").animate({
					marginTop : 40
				},function() {
					showMondoIcon(id);
				});				
			} else {
				showMondoIcon(id);				
			}
		});
					  
    });

	if($.browser.msie) {
		$("#mondo_icons ul .m a").hover(function() {
			$(this).css("background-position","0 -67px");
		},function() {
			if(!$(this).hasClass("current")) {
				$(this).css("background-position","0 0");			
			}
		});
	}

	$("div.blockOverlay, .blockUiX").live("click",function(e) {
		
		if($.browser.safari) {
			$(".flashObject").show();			
		}			
		
		var loc = ""+window.location+"";
		if($.browser.msie && !isIE6() && loc.indexOf("blog")>0) {
			location.href = loc;
		} else {		
			$.unblockUI();
		}

       	return false;
	});
	
	
	$("#search_pop_contents .search_pop_q").focus(function() {
		f = $(this).val();
		if($(this).val()==f) $(this).attr("value","");
	});
	
	
	if($("#rotating_banners").length>0) {
		$("#rotating_banners").cycle({
		    fx:     "cover", 
		    speed:  "slow", 
		    timeout: 4000, 
			cleartype: 1		
		});
	}
	
	$(".zebraLinks ul li:odd").css("background-color","#141414");
	
});

function showMondoIcon(id) {
	$(".mondo_prev").hide();
	$(id).show();		
}

function isIE6() {
	if($.browser.msie && $.browser.version=="6.0") {
		return true;
	} else {
		return false;
	}
}

function emailIsValid(emailObj) {
	rt = true;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(!reg.test(emailObj)) rt = false;
	
	return rt;	
}

function popMessage(msgType, title,msg) {	
	
	var msgTypeClass = " info";
	if(msgType!=null && msgType!="") msgTypeClass = " "+msgType;
	
    $.blockUI({ 
        message: "<div class=\"popMsg"+msgTypeClass+"\"><a href=\"javascript:closePopMsg();\" class=\"popCross\"><img src=\"/images/popcross.png\" /></a><div><h6>"+title+"</h6><p>"+msg+"</p></div></div>",
        fadeIn: 700, 
        fadeOut: 700, 
        timeout: 5000, 
        showOverlay: true,
		baseZ: 1000, 
		css : {
			border : "none",
            "-moz-border-radius": "10px",
			"-webkit-border-radius": "10px"
		}
    });	
}

function closePopMsg() {
	$.unblockUI();
}

function coinStyle() {
	$("#logo").after("<div id=\"logo_world\"><img src=\"/images/style.gif\" style=\"position:relative; top:-2px;\" /></div>");
}

function webcam() {
	newWindow("/jsp/it/webcam/index.jsp","webcam",800,660,"no");
}

function newWindow(mypage,myname,w,h,scroll) {
	var win=null;
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars='+scroll+',';
	settings +='resizable=yes';
	win=window.open(mypage,myname,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

