
function renderNavMenu() {
	 //alert(siteUrl+wwwRoot)
   var currentUrl = document.location.href.replace(siteUrl,"");
	 //alert(document.location.href+"\n"+currentUrl)
   var currentUrlExploded = currentUrl.split("?");
   currentUrl = currentUrlExploded[0];
   $("#main_nav").find("a").each(function() {
      var item_title = $(this).text();
      var item_label = escape($(this).text());
      //alert(wwwRoot+"/dynamic/img/navmenu/"+item_level+"/"+item_label+".gif");
      var item_level = $(this).parent().parent().attr("class");
      //alert(wwwRoot+"/dynamic/img/navmenu/"+item_level+"/"+item_label);
      $(this).css("background", "transparent url('"+wwwRoot+"/dynamic/img/navmenu/"+item_level+"/"+item_label+".gif') no-repeat 0 0");
      //$(this).text("");
      $(this).attr("title",item_title);
      //alert($(this).attr("href")+" == "+currentUrl);
      if($(this).attr("href") == currentUrl) {
         $(this).addClass("on");
      }
   });
}
function renderFooter() {
	 //alert(siteUrl+wwwRoot)
   var currentUrl = document.location.href.replace(siteUrl,"");
	 //alert(document.location.href+"\n"+currentUrl)
   var currentUrlExploded = currentUrl.split("?");
   currentUrl = currentUrlExploded[0];
   $("#footer").find("a").each(function() {
      var item_title = $(this).text();
      if(item_title)
      {
      var item_label = escape($(this).text());
      //alert(wwwRoot+"/dynamic/img/navmenu/"+item_level+"/"+item_label+".gif");
      var item_level = $(this).parent().parent().attr("class");
      //alert(wwwRoot+"/dynamic/img/navmenu/"+item_level+"/"+item_label);
      //alert(wwwRoot+"/dynamic/img/footer/"+item_level+"/"+item_label+".gif")
      $(this).html("<img src=\""+wwwRoot+"/dynamic/img/footer/"+item_level+"/"+item_label+".gif\" border=\"0\">");
      //$(this).text("");
      $(this).attr("title",item_title);
      //alert($(this).attr("href")+" == "+currentUrl);
      if($(this).attr("href") == currentUrl) {
         $(this).addClass("on");
      }
      }
   });
}

function renderScrollableLayers(parentObj) {
   $(parentObj+" .scroll-pane").jScrollPane({
      scrollbarWidth:7, 
      scrollbarMargin:0,
      dragMinHeight:25,
      dragMaxHeight:25,
      dragMaxWidth:25,
      showArrows:true,
      arrowSize: 3
   });
}

function renderTitles(parentObj) {
   $(parentObj+" h1:not(.alt),"+parentObj+" h2:not(.alt))").each(function(i) {
      var item_title  = $(this).text();
      
      if (item_title != '') {
      
   	   var alternativeStyle  = $(this).attr("class");
   	   if(alternativeStyle){
   	     var item_level  = alternativeStyle;
   	   }
   	   else {
   	     var item_level  = this.tagName;
   	   }
   	      
   	   //alert(item_title);
   	   //alert(item_level);
   	      
          var item_label  = escape($(this).text());
          //alert(item_label);
   	      var item_width  = $(this).css("width");
          //alert(item_width);
   	      if (item_level == 'H1') {
   	         var item_height= '21px';
   	      }
   	      
   	      //var item_height  = $(this).css("height");
   	      var item_id     = item_level+"_"+i;
   	      //alert(item_width+" || "+item_height);
   	      var img_tag = "<img id=\""+item_id+"\" style=\"/*width:"+item_width+";height:"+item_height+"*/\" src=\""+wwwRoot+"/dynamic/img/titles/"+item_level+"/"+item_width+"/"+item_label+".gif\" alt=\""+item_title+"\" />";
   	      //alert(img_tag)
   	      $(this).text("");
   	      $(this).html(img_tag);
      }
   });
   if ($.browser.msie) { $(".png").ifixpng(); }
}

function dialog(content,width,height) {

   $("#ex2").css("width",width+"px");
   $("#ex2").css("height",height+"px");
   $("#ex2").css("top","50%");
   $("#ex2").css("margin-top","-"+(height/2)+"px");
   $("#ex2").css("margin-left","-"+(width/2)+"px");
   $("#ex2").html("<table width=\"100%\" height=\"100%\"><tr><td align=\"center\" valign=\"middle\"><img src=\""+wwwroot+"/comuni/img/loading.gif\" alt=\"loading\" style=\"padding-top: 4px\" /> loading...</td></tr></table>");
   $("#ex2").jqm({overlay:50}).jqmShow();

	   $.ajax({
	      type:     "GET",
	      url:      content,
	      success: function(response){
	         $("#ex2").html(response);
	      }
	   });

}

function popup(url,width,height) {
	 if(width>800)
	 {
	 	 width = 800;
	 }
	 if(height>600)
	 {
	 	 height = 600;
	 }
	 window.open(url,'zoom','width='+width+',height='+height+',resizable=yes');
   /*
   $("#ex2").css("width",width+"px");
   $("#ex2").css("height",height+"px");
   $("#ex2").css("top","5%");
   $("#ex2").css("margin-top","10px");
   $("#ex2").css("margin-left","-"+(width/2)+"px");
   $("#ex2").html("<img src=\""+wwwRoot+"/img/loading.gif\" alt=\"loading\" style=\"padding-top: 4px\" /> loading... ");
   $("#ex2").jqm({overlay:50}).jqmShow();
   $.ajax({
      type:     "GET",
      url:      url,
      data:     "mode=ajax",
      success: function(response){
         $("#ex2").html(response);
         //$(".popup_wrapper").css("height",(height-145)+"px");
      }
   });*/
}



function showHide()
{
    if ($('#lineeList').is(":hidden")) {
      $('#lineeList').slideDown("fast");
    } else {
      $('#lineeList').slideUp("fast");
    }
}

function showHideBox(pref,id)
{
    if ($('#'+pref+id).is(":hidden")) {
    	$('.'+pref).slideUp("fast");
      $('#'+pref+id).slideDown("fast");
    } else {
      $('#'+pref+id).slideUp("fast");
    }
}

function cerca()
{
	if($('#kw').attr('value').length < 2)
	{
		alert('la parola da cercare deve essere di almeno 2 lettere');
	}
	else
	{
    document.location.href = $('#formCerca').attr('action')+'?kw='+$('#kw').attr('value');
	}
}
/*
sleep:function(timeout) {
        var loop = true;
        var current = new Date();
        var now;
        var cTimestamp = current.getTime();

        while(loop) {
                now = new Date();
                nTimestamp = now.getTime();

                if(nTimestamp - cTimestamp > timeout) {
                        loop = false;
                }
        }

} 
*/

/* ------------------------------------------------------------------
// DOCUMENT READY
------------------------------------------------------------------ */
$(document).ready(function() {
   if ($.browser.msie) { $('img[@src$=.png]').ifixpng(); $('.png').ifixpng(); }
   try {
      document.execCommand("BackgroundImageCache", false, true);
   } catch(err) {}
	
	renderTitles(""); 
   
})

function cerca()
{
	if(($('#kw').attr('value').length)>2)
	{
		$('#search').submit();
	}
	else
	{
		alert('Attenzione, la ricerca deve contenere almeno 3 caratteri');
	}
}