/* apertura popup */
function calc_left (w) {
   var left = (screen.availWidth / 2) - (w / 2);
   return (left);
}
function calc_top (h) {
   var top = (screen.availHeight / 2) - (h / 2);
   return (top);
}
function popup (url, id, w, h, scrollbars) {
   var top = calc_top (h);
   var left = calc_left (w);

   popupwindow = window.open(url, id, 'width='+w+',height='+h+',scrollbars='+scrollbars+',left='+left+',top='+top+',screenX='+left+',screenY='+top);
   popupwindow.focus();
}
/* help */
function help(url) {
   popup(url,'help_window',600,450,'no');
}
/* credits */
function credits(url) {
   popup(url,'help_window',600,450,'no');
}

/* posiziona il footer a fondo pagina, oppure a fondo finestra se la pagina e' piu' corta */
function adjustFooter() {
 $("#footer").hide();
 var topH       = 200;
 var wrapperH   = $("#wrapper").height() - topH;
 var menuLeftH  = $("#menu_left").height() +30;
 var contenutoH = $("#contenuto").height() +30;
 var spallaH    = $("#spalla").height() +30;
 var maxH       = Math.max( Math.max( wrapperH, menuLeftH ), Math.max( contenutoH, spallaH ) );
 $("#footer").css("top",(maxH+topH)+"px");
 $("#footer").show();
}

var mouseX;
var mouseY;

var autocompleteAjaxURL;

$(document).ready(function() {
   
   $().mousemove(function(e){
      mouseX = e.pageX;
      mouseY = e.pageY;
   }); 
   
   // sIFR
   if(typeof sIFR == "function" && activateSIFR == true) {
      
      sIFR.bHideBrowserText = false;

      // get all .SIFR elements
      $(".SIFR").each(function(i) {
   	     
         // fontnames and colors
         if       ($(this).hasClass("titolo"))        { var fontName = "HelveticaNeue"; }
         else if  ($(this).hasClass("sottotitolo"))   { var fontName = "HelveticaNeue"; }
         else if  ($(this).hasClass("sottotitolo_2")) { var fontName = "HelveticaNeue"; }
         else                                         { var fontName = "HelveticaNeue"; }
         
         if       ($(this).hasClass("black"))         { var color = "#000000"; }
         else if  ($(this).hasClass("red"))           { var color = "#c70702"; }
         else if  ($(this).hasClass("grey"))          { var color = "#8a8a8b"; }
         else if  ($(this).hasClass("lightgrey"))     { var color = "#96abb5"; }
         else                                         { var color = "#000000"; }
         
         if       ($(this).hasClass("ablack"))         { var linkcolor = "#000000"; }
         else if  ($(this).hasClass("ared"))           { var linkcolor = "#c70702"; }
         else if  ($(this).hasClass("agrey"))          { var linkcolor = "#8a8a8b"; }
         else if  ($(this).hasClass("alightgrey"))     { var linkcolor = "#96abb5"; }
         else                                          { var linkcolor = color;     }
         
         // do sIFR
         this.id = "SIFR_"+i;
         
         sIFR.replaceElement(named({
            sSelector:    "#SIFR_"+i,
            sFlashSrc:    "/extension/einaudi/design/standardeinaudi/swf/"+fontName+".swf",
            sColor:       color,
            sLinkColor:   linkcolor
         }));
      
      });

   };
   // end sIFR

   if (autocompleteAjaxURL != undefined) {
      $("#cerca_nel_sito_search_str").focus( function() { $("#cerca_nel_sito_legenda").show(); } );
      $("#cerca_nel_sito_search_str").blur( function() { $("#cerca_nel_sito_legenda").hide(); } );
      $("#cerca_nel_sito_search_str").autocomplete(autocompleteAjaxURL, {
         formatResult: function(item) {
            var item2 = item+'';
            var dati_formattati = item2.split('===');
            var dato = dati_formattati[0];
            return dato;
         }
      });
   }
   
   

   
});

window.onload = function() {
  adjustFooter();
}
window.onresize = function() {
  adjustFooter();   
}


