// Inizio document.ready

$("document").ready(function (){

	//PNGFIX FOR IE6
	if(navigator.userAgent.indexOf("MSIE 6")>-1){
		$(document).pngFix();
	}
						
	// FUNZIONAMENTO MENU
	var w = "";
	var l = $("#subMenu a").css("margin-left");
	var r = $("#mainMenu a").css("margin-right");
	var itsMe = false;
	var itsMeSub = false;
	
	$("#mainMenu a")
	.mouseover(function(){
		itsMe = ($(this).attr("class").match("selected") != null) ? true : false;
		$(this).stop().animate({marginRight:"0"},100).animate({backgroundPosition:"(0 0)"},{duration:100});
	})
	.mouseout(function(){
		if($(this).attr("class").match("selected")==null){
			var wS = "-" + $(this).width() + "px 0";			
			$(this).stop().animate({marginRight: r },100).animate({backgroundPosition:"("+ wS +" 0)"},{duration:100});
		}
	})
	$("#mainMenu a.selected").trigger("mouseover"); //Per primo

	$("#subMenu a")
	.mouseover(function(){
		itsMeSub = ($(this).attr("class").match("selected") != null) ? true : false;
		w = "-" + $(this).width() + "px";			
		$(this).stop().animate({marginLeft:"0"},100).animate({backgroundPosition:"("+ w +" 0)"},{duration:100});
	})
	.mouseout(function(){
		if($(this).attr("class").match("selected")==null){
			$(this).stop().animate({marginLeft: l },100).animate({backgroundPosition:"(0 0)"},{duration:100});
		}
	})
	.click(function(){
		if(!itsMeSub){
			$("#subMenu a.selected").removeClass("selected").trigger("mouseout");	
			$(this).addClass("selected").trigger("mouseover");
			var myFile = $(this).attr("href");
			loadPage(myFile);
		}
		return false;
	});
	$("#subMenu a.selected").trigger("mouseover"); //Per primo
	
});
// Fine document.ready