<!--
 $(document).ready(function(){
	$('#fontsizer').jfontsizer({
		applyTo: '#container',
		changesmall: '2',
		changelarge: '3',
		expire: 30
	});

	$('.swfBbanner').each(function(i){
		var swfInfo = $(this).attr("title").split("|"); //|<?=$width?>|<?=$height?>
		$(this).flash({ src: swfInfo[0], width: swfInfo[1], height: swfInfo[2]}, { version: 8 });
	});

	breadCrumbs($("#pathway"));

	tabs($("#prova_tabs"));

	$("#toggleNormativa").click(function (){
    	$("#slideNormativa").slideToggle("slow");}
   	);

	//$('div.imageContainer a, #main #image-description a').lightBox({fixedNavigation:true});

 	//GESTIONE INPUT "cerca nel sito"
 	function FB_changeBgFg(objInProcess,fgColor, bgColor){
 		objInProcess.css({'color':fgColor,'background-color':bgColor});
 	}
 	var inpSearch = $(".form_cerca");
 	if(inpSearch.val() == "cerca nel sito") FB_changeBgFg(inpSearch,'#AAAAAA','#EEEEEE');
 	else FB_changeBgFg(inpSearch,'#000000','#FFFFFF');
 	inpSearch.focus(function(){
 		inpSearch.val((inpSearch.val() == "cerca nel sito")?"":inpSearch.val());
		FB_changeBgFg(inpSearch,'#000000','#FFFFFF');
 	});
 	//FINE GESTIONE INPUT "cerca nel sito"

	//paginatore di liste per servizi sottocategoria
	$("div.rel-services-pager a").click(function(){
		var divId = "#"+$(this).parent().parent().parent().attr("id");
		$(divId+" ul").css("display","none");
		$("#"+$(this).attr("rel")).css("display","block");
		$(divId + " div.rel-services-pager ul").css("display", "block");
		$(divId + " span a").removeClass("active");
		$(this).addClass("active");
	});

	$("#filter-organigramma input[type='checkbox']").attr('checked', true);

	$('#organigramma p, #regolamenti p, #domandericorrenti p').click(function() {
		$(this).next().toggle('fast');
		return false;
	}).next().hide();

	$('#organigramma li').find("ul").hide();

	/*$(".faq-question").click(function() {
		$(this).next().toggle('fast');
		return false;
	}).next().hide();*/

	$(".faq-expand").click(function(){
		$.scrollTo( $("."+$(this).attr("rel")), 800);
	});

	$(".faq-toTop").click(function(){
		$.scrollTo(0, 800);
	});

	$('#calendar-list-day a').click(function(){
		$('#calendar-list-day li').removeClass("active-day");
		$('.calendar-day').removeClass('calendar-active');
		$($(this).attr('rel')).addClass('calendar-active');
		$(this).parent().parent().addClass("active-day");
		//;
	});

	update_organigramma_count();

	$("#filter-disciplina input").click(function(){
		return qre_tipo_filter($(this), ".tipo_");
	//	return qre_tipo_filter($(this), ".sport_tipo_");
	});

	$("#filter-quartiere input").click(function(){
		return qre_tipo_filter($(this), ".qre_");
	});

	$("#chk-qreall").click(function(){
		var bRet;
		bRet=$(this).attr("checked");

		$(this).parent().parent().parent().find("input").each(function(i){
			$(this).attr("checked", bRet);
			return qre_tipo_filter($(this), ".qre_");
		});
	});

	$("#chk-tipoall").click(function(){
		var bRet;
		bRet=$(this).attr("checked");

		$(this).parent().parent().parent().find("input").each(function(i){
			$(this).attr("checked", bRet);
			//return qre_tipo_filter($(this), ".sport_tipo_");
			return qre_tipo_filter($(this), ".tipo_");
		});
	});

   $(".ocAlt span").click(function(){
     var nowId = $(this).attr("id").split("_")[1];
     if($("#oc_" + nowId).css('display')=='none'){
       $(".ocToggle").slideUp(200);
        $("#oc_" + nowId).slideToggle("slow");}
      }
  );

  $("#HP-node-calendario a.changemonth").click(function (){
	return refreshCalendario($(this));
  });

  //// luoghi nei servizi /////////////////////////
	$(".PS-toggle").click(function(){
		return DI_PS_toggle($(this));
	});//.siblings("div, ul").hide();

	$(".filterZona").click(function(){
		return DI_PS_filterZona($(this))
	});

	$("#PS-tabs-header li").click(function(){
		return DI_PS_header($(this));
	});

	$(".PS-pager span").click(function(){
		return DI_PS_pager($(this));
	});
  /////////////////////////////////////////////////

  /////////////////////////////////////
  //LOADING POPUP
  //Click the button event!
  $("#toggle_sp_filter").click(function(){
    //centering with css
    centerPopup();
    //load popup
    loadPopup();
  });

  //CLOSING POPUP
  //Click the x event!
  $("#sp_filter span, #backgroundPopup").click(function(){
    disablePopup();
  });

  //Press Escape event!
  $(document).keypress(function(e){
    if(e.keyCode==27 && popupStatus==1){
      disablePopup();
    }
  });
  /////////////////////////////////////

  /////////////////////////////////////
  //LOADING OVERLAY
   $("#faq_service a[rel]").overlay({
     effect: 'apple',
	 loadSpeed: 500,
     closeOnClick: false,
     finish: {top: -100, left: -400}
    });

  $("#header-overlay p").click(function(){
    $("#body-overlay").css('cursor','default');
    if($(this).html() != "Domande ricorrenti"){
      $(this).html("Domande ricorrenti");
      $("#body-overlay").css({'display':'block','cursor':'pointer'});
      $(".answer-overlay").css("display","none");
    }
  });

  $("#body-overlay a.body_a_overlay").click(function(){
    $("#header-overlay p").html("&laquo; " + $(this).html());
    var answerH= $("div.overlay").height()-$("#header-overlay p").height()-35;
    $("#body-overlay").css("display","none");
    $($(this).attr("rel")).css({"display":"block", "height": answerH+"px"});
    //alert($("#header-overlay p").height());
  });

  /////////////////////////////////////
  /////////////////// accordion ///////
  $('#sp_container p').click(function() {
    $(this).next().toggle('fast');
    return false;
  }).next().hide();
  /////////////////////////////////////

  $('div.itemContainer ul.ul_servizi li strong, div.itemContainer ul.contact li span').click(function() {
    $(this).next().toggle('fast');
    return false;
  }).next().hide();

  $('.btn').click(function() {
	var ulRef = $(this).attr("rel").split(" ")[0];
   	if($(this).html()=="Visualizza tutti i dettagli"){
  		$(this).html("Nascondi tutti i dettagli");
  	 	$($(this).attr("rel")).slideDown("fast");
  	 	$(ulRef + " .PS-toggle").removeClass('place_expand').addClass('place_collapse');
  	}else{
	  	$(this).html("Visualizza tutti i dettagli");
  		$($(this).attr("rel")).slideUp("fast");
  	 	$(ulRef + " .PS-toggle").removeClass('place_collapse').addClass('place_expand');
  	}
	return false;
  })

  GMload();

});

  function DI_PS_toggle(obj){
  	obj.stop();
	var sibling = obj.siblings("div, ul");
	var sibling2 = obj.find(".PS-toggle-description");
	sibling2.html(((sibling.is(":visible"))?"+":"-"));

	if(sibling.is(":visible")){
		sibling2.html("+");
		sibling2.attr("title","Clicca per Espandere");
		obj.removeClass('place_collapse').addClass('place_expand')

	}else{
		sibling2.html("-");
		sibling2.attr("title","Clicca per Nascondere");
		obj.removeClass('place_expand').addClass('place_collapse');
	}
	sibling.toggle("normal");
	return true;
  }

  function DI_PS_filterZona(obj){
	obj.stop();
	var quartiere = $(obj).attr("name").split("_");
	var quartiereId = quartiere[1];
	$("#PS-body-left").hide();
	$("#PS-loading").show();
	$.ajax({
		url: $("#hdnFz_action").val(),
		global: false,
		type: "POST",
		data: ({"quartiere" : quartiereId, itemId : $("#hdnFz_ItemId").val()}),
		dataType: "html",
		success: function(msg){
			$("#PS-body-left").html(msg).show();
			$(".PS-toggle").click(function(){return DI_PS_toggle($(this));});
			$("#PS-tabs-header li").click(function(){return DI_PS_header($(this));});
			$(".PS-pager span").click(function(){return DI_PS_pager($(this));});
			$("#PS-tabs-header li").removeClass("PS-tabs-attivo");
			$("#PS-tabs-header li:first").addClass("PS-tabs-attivo");
			$("#PS-loading").hide();
		}
	})
	return false;
  }

  function DI_PS_header(obj){
  	$("#PS-tabs-header li").removeClass("PS-tabs-attivo");
  	obj.addClass("PS-tabs-attivo");
	$("#PS-body-left div").removeClass("PS-attivo");
	$("#PS-block-"+obj.find("a").attr("id").split("_")[1]).addClass("PS-attivo");
	return true;
  }

  function DI_PS_pager(obj){
	var nome = obj.attr("id").split("_")[1];
	$("#PS-block-"+nome.split("-")[0] + " ul").removeClass("PS-attivo");
	$("#PS-body-left-ul-"+nome).addClass("PS-attivo");
	obj.parent().find("a").removeClass("active");
	obj.find("a").addClass("active");
  	return true;
  }

  function CountSportPlace(){
   	return true;
  }

///////////////////////////////

  var geocoder;
  var place_name;
  var geocoord = ", Bologna, Bologna (Emilia Romagna), Italy";
  var latitudine = 44.493833;
  var longitudine = 11.342402;
  var zoom=13;
  var sHtml;
  var map;

  function GMload() {
  	if($('#hdn_address').length>0){
	    var indirizzo = $('#hdn_address').attr('value');
	    place_name = $('#hdn_name_address').attr('value');
	    if (GBrowserIsCompatible()) {
	      map = new GMap2(document.getElementById("gm_map"));
	      gdir = new GDirections(map, document.getElementById("directions"));
	      map.addControl(new GLargeMapControl ());
	      map.addControl(new GMapTypeControl());
	      map.addControl(new GScaleControl());
	      map.clearOverlays();
	      geocoder = new GClientGeocoder();
	      geocoder.getLocations(indirizzo + geocoord, addAddressToMap)
	    }

	    GEvent.addListener(gdir, "error", handleErrors);
	}
  }

  function addAddressToMap(response) {
    if (!response || response.Status.code != 200) {
    //alert("Indirizzo non trovato.");
    	$('#gm_map').css("display", "none");
    } else {
		place = response.Placemark[0];

		latitudine = place.Point.coordinates[1];
		longitudine = place.Point.coordinates[0];
		point = new GLatLng(place.Point.coordinates[1],
		                        place.Point.coordinates[0]);
		marker = new GMarker(point);
		sHtml = "<b>" + place_name + "</b>";
		createMarker(marker, sHtml);
		map.addOverlay(marker);
		map.setCenter(new GLatLng(latitudine, longitudine), zoom);
    }
  }

  function createMarker(point,html) {
    GEvent.addListener(point, "click", function() {
      point.openInfoWindowHtml(html);
    });
    return point;
  }

  function handleErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
	else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	else alert("An unknown error occurred.");
  }


  //SETTING UP OUR POPUP
  //0 means disabled; 1 means enabled;
  var popupStatus = 0;

  //loading popup with jQuery magic!
  function loadPopup(){
    //loads popup only if it is disabled
    if(popupStatus==0){
      $("#backgroundPopup").css({
        "opacity": "0.7"
      });
      $("#backgroundPopup").fadeIn("slow");
      $("#sp_filter").fadeIn("slow");
      popupStatus = 1;
    }
  }

  //disabling popup with jQuery magic!
  function disablePopup(){
    //disables popup only if it is enabled
    if(popupStatus==1){
      $("#backgroundPopup").fadeOut("slow");
      $("#sp_filter").fadeOut("slow");
      popupStatus = 0;
    }
  }

  //centering popup
  function centerPopup(){
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#sp_filter").height();
    var popupWidth = $("#sp_filter").width();
    //centering
    $("#sp_filter").css({
      "position": "absolute",
      /*"top": windowHeight/2-popupHeight/2,*/
      "left": windowWidth/2-popupWidth/2
    });
    //only need force for IE6
    $("#backgroundPopup").css({
      "height": windowHeight
    });

  }

  function update_organigramma_count(){
	$("#organigramma").find("span.counter").each(function(i) {
		var cnt;
    	if($(this).parent().is("li")){
    		cnt = $(this).parent().find("li.cnt-active").size();
    		if(cnt==0){
				$(this).parent().hide();
	    	}else{
				$(this).parent().show();
	    	}
    	}else{
    		cnt = $(this).parent().next().find("li.cnt-active").size();
    		if(cnt==0){
				$(this).parent().hide();
	    	}else {
				$(this).parent().show();
	    	}
    	}
    	$(this).html("("+cnt+")");
	});
	return true;
  }

  function qre_tipo_filter(obj, classname){ //.tipo_ --  .qre_
  	var tipo = classname + obj.attr("id").split("_")[1];
  	var qre;
  	var tpo;
	$(tipo).each(function(i){
		if(classname==".tipo_"){ //click su tipologia
			var re = /qre_[0-9]*/;
			qre = $(this).attr("class").match(re);
			qre = qre[0].split("_")[1];
			if($("#chkqre_"+qre).is(':checked')){
				if(obj.is(':checked')){
					$(this).show().addClass("cnt-active");
				}else{
					$(this).hide().removeClass("cnt-active");
				}
			}else{
				$(this).hide().removeClass("cnt-active");
			}
		}else{ //click su quartiere
			if(!obj.is(':checked')){
				$(this).hide().removeClass("cnt-active");
			}else{
				var totTipo = 0;
				var totChecked = 0
				var tpo = $(this).attr("class").split(" ");
				var bFlag = true;
				for(i=0;i<=tpo.length;i++){
					if(tpo[i]!=undefined){
						var item = tpo[i].split("_");
						if(item[0] == "tipo"){
							totTipo = totTipo + 1;
							if($("#chktipo_"+item[1]).is(':checked')){
								totChecked = totChecked + 1;
							}
						}
					}
				}

				if(totTipo == totChecked){
					$(this).show().addClass("cnt-active");
				}else{
					$(this).hide().removeClass("cnt-active");
				}
			}
		}
	});
  	update_organigramma_count();
	return true;
  }

  function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}

  function breadCrumbs(obj){
  	var sBC = "#" + obj.attr("id") + " li";
  	var sBCfirst = sBC+":first";
  	var sBClast = sBC+":last";

  	$(sBC).each(function (i) {
		$(this).stop();
		if($(this).html() != $(sBClast).html()){
			$(this).attr("orWidth", $(this).width());
			$(this).animate({width: "20"}, "slow");
		}else{
			$(sBClast).addClass('last');
			$(sBCfirst).addClass('first').width("16");
		}
	}).mouseover(function(){
		$(this).stop();
		if($(this).html() != $(sBClast).html()){
			$(this).animate({width: $(this).attr("orWidth")}, "slow");
		}
	}).mouseout(function(){
		$(this).stop();
		if($(this).html() != $(sBClast).html()){
			$(this).animate({width: "20"}, "slow");
		}
	});
  }

  function tabs(obj){
  	if(obj){
  		$("#"+obj.attr("id")+" ul:first").addClass("tabs-menu");
  		$("#"+obj.attr("id")+" ul:first li:first").addClass("item-tab-selected");
  		$("#"+obj.attr("id")+" ul:first a").click(function (){
			$("#"+obj.attr("id")+" div").css("display", "none");
			$("#"+obj.attr("id")+" ul:first li").removeClass("item-tab-selected");
			$(this).parent().addClass("item-tab-selected");
			$("#"+obj.attr("id")+" div").slideUp("slow");
			$($(this).attr("rel")).slideDown("fast");
			return false;
		});
		$(".item-tab-selected a").click(function(){
			return false;}
		);
		$("#"+obj.attr("id")+" div").css("display", "none");
		$("#"+obj.attr("id")+" div:first").css("display", "block");
		$("#"+obj.attr("id")+" div:first div.place-tabs-pager").css("display", "block");
  	}
  }

  function refreshCalendario(obj){
	$.ajax({
	      type: "POST",
	      url: obj.attr("rel"),
	      data: "nodeId="+nodeId,
	      success: function(msg){
		   $('#HP-node-calendario').fadeOut(10).html(msg);
	   	  },
	   	  complete: function(){
	   	  	$('#HP-node-calendario').fadeIn(500);
			$('#HP-node-calendario a.changemonth').click(function (){
				return refreshCalendario($(this));
			 });
	   	  }
	   });
	 return false;
  }
 //-->

