jQuery(document).ready(function(){
	//fix png
	jQuery('img').ifixpng(); 
	var t; 

	// ROLLOVER MENU
	$("#mainNav li.parent a").hover(
		function() { //rollover	
			$(this).parent().siblings().children("ul.visible").hide(); 	
			$(this).parent().children("ul").not(".visible").show(); 	
		},
		function() { //rollout
			$(this).parent().siblings().children("ul.visible").show();
			$(this).parent().children("ul").not(".visible").hide();
		}
	);
	$("#mainNav li ul").hover(
		function() { //rollover
		    clearTimeout(t) 

		    var src = $(this).parent().children("a").children("img").attr("src");  
		    $(this).parent().children("a").children("img").attr("src", src.replace("_off","_on"));
			$(this).show();
			$(this).parent().siblings().children("ul.visible").hide();
			$(this).parent().children("a").addClass("rollover");
		},
		function() { //rollout
		    clearTimeout(t) 

		    var src = $(this).parent().children("a").children("img").attr("src");
		    if ($(this).parent().children("a").children("img").attr("id") != "active"){
                $(this).parent().children("a").children("img").attr("src", src.replace("_on","_off"));
			}
			$(this).not(".visible").hide();
			$(this).parent().siblings().children("ul.visible").show();
			$(this).parent().children("a").removeClass("rollover");
		}
	);
	
	//preload menu images
	$("img.menuLevel1").each(function(i){
        jQuery("<img>").attr("src", this.src.replace("_off","_on"));	
	});
	
	// rollover images menu
	$(function(){
		// set up rollover
		$("img.menuLevel1").hover(
			function()
			{
				this.src = this.src.replace("_off","_on");
			},
			function()
			{
				var imgCurrent = this;
				if (this.id != "active"){
				   t = setTimeout(function() { 
                        imgCurrent.src = imgCurrent.src.replace("_on","_off")
                   }, 50);
				}
			}
		);	
	});

}); 

function QueryString( param )	
{
	var begin,end;

	if(self.location.search.length>1)	  
	{
	    begin=self.location.search.indexOf(param) +param.length+1;
	    end=self.location.search.indexOf("&",begin);
	    if(end==(-1)) end=self.location.search.length;
	    return(self.location.search.substring(begin,end));
	 }
	 else if(self.location.hash.length>1)	  
	 {
	    begin=self.location.hash.indexOf(param) +param.length+1;
	    end=self.location.hash.indexOf("&",begin);
	    if(end==(-1)) end=self.location.hash.length;
	    return(self.location.hash.substring(begin,end));
	 }
	 else return("");
}

function AddFrameParam(nameParam)
{
	var param = QueryString(nameParam);
	
	var ServiceFrame = document.getElementById("ServiceFrame");
	
	if (ServiceFrame != null)
	{ 
		if (ServiceFrame.src.indexOf("?",0) == -1)
		{
			ServiceFrame.src = ServiceFrame.src + "?" + nameParam + "=" + param;
		}
	}
}

function popup(popUrl, popWidth, popHeight, popParam){
    var popLeft   = (screen.width  - popWidth)/2;
    var popTop    = (screen.height - popHeight)/2;
    window.open(popUrl,'', 'width=' + popWidth + ', height=' + popHeight + ', top=' + popTop + ', left=' + popLeft + ', ' + popParam);
}

function closeModalPopup(id){
    jQuery("#modal" + id).hide();
}

function openModalPopup(id){
    jQuery("#modal" + id).show();
}

function QueryString(param, _default) 
{
    var res = _default;        
    var begin,end;

    if(self.location.search.length>1)	  
    {
        begin=self.location.search.indexOf(param) +param.length+1;
        end=self.location.search.indexOf("&",begin);
        if(end==(-1)) end=self.location.search.length;
        res = self.location.search.substring(begin,end);
     }
     else if(self.location.hash.length>1)	  
     {
        begin=self.location.hash.indexOf(param) +param.length+1;
        end=self.location.hash.indexOf("&",begin);
        if(end==(-1)) end=self.location.hash.length;
        res = self.location.hash.substring(begin,end);
     } else res = 0;
     
     //controllo se il valore e' numerico o vuoto
     if ( (res == "") || isNaN(res) ) {
        res = _default;
     }
            
     return res;
}

function checkForm(){
  if(document.formRicerca.search.value == ''){
    alert('Inserire il testo della ricerca');
    return false;
   }
}
