// JavaScript Document
/*
  CAMBIA DOMINIO!!!!!!!!!!
*/
var dominio = "www.nsi.it"
var infonsi = new Array()
infonsi[0]=new Array("105","110","102","111","64");

jQuery(document).ready(function(){

  var h = document.location.toString();
  var i = 4;
  var c = "#FFCE03";
  if(h.indexOf("/software")!=-1){ i = 0; c = "#D8E02B"; }
  if(h.indexOf("/infrastrutture")!=-1){ i = 1; c = "#9ECD5D"; }
  if(h.indexOf("/sicurezza")!=-1){ i = 2; c = "#8F92C9"; }
  if(h.indexOf("/ricerca")!=-1){ i = 3; c = "#006599"; }
  if(h.indexOf("/sw/")!=-1){ i = 0; c = "#D8E02B"; }
  if(h.indexOf("/in/")!=-1){ i = 1; c = "#9ECD5D"; }
  if(h.indexOf("/sc/")!=-1){ i = 2; c = "#8F92C9"; }
  if(h.indexOf("/rs/")!=-1){ i = 3; c = "#006599"; }
  
	jQuery("#accordion").accordion({
    active: i,
    header: 'a.sezione',
    event: 'click',
    autoHeight: false
    });
  var paginacorrente;
  if(location.href.indexOf("journal_content") == -1){
    jQuery("#accordion a").each(function(){
      if(this.href == location.href){
        this.style.fontWeight = "bold";
        this.style.color = c;
      }
    });  
  }
  /*home page*/
  if((location.href == "http://"+dominio+"/web/guest/") || (location.href == "http://"+dominio+"/web/guest")){
    jQuery("#accordion a").each(function(){
      if(this.href == "http://"+dominio+"/web/guest/home"){
        this.style.fontWeight = "bold";
        this.style.color = c;
      }
    });  
  }
  /*chi siamo*/
  if((location.href == "http://"+dominio+"/web/guest/la-nostra-storia") || (location.href == "http://"+dominio+"/web/guest/il-gruppo-nier") || (location.href == "http://"+dominio+"/web/guest/lo-staff")){
    jQuery("#accordion a").each(function(){
      if(this.href == "http://"+dominio+"/web/guest/chisiamo"){
        this.style.fontWeight = "bold";
        this.style.color = c;
      }
    });
  }
  /*news*/
    if((location.href.indexOf("/news/")!=-1) ){
    jQuery("#accordion a").each(function(){
      if(this.href == "http://"+dominio+"/web/guest/news"){
        this.style.fontWeight = "bold";
        this.style.color = c;
      }
    });
  }  
  for(i=0;i<jQuery("#accordion a.sottoelemento").length;i++){

    if("http://"+dominio+jQuery("#accordion a.sottoelemento").eq(i).attr("href") == location.href ){
      jQuery("#accordion a.sottoelemento").eq(i).addClass("navsfondoattivo");
      jQuery("#accordion a.sottoelemento").eq(i).css("padding-left","20px");
      paginacorrente = i;
    }
  }

  jQuery("#infonsi").html(nome(infonsi));
  jQuery("#infoprint").html(nome(infonsi));
  
  /*Link esterni*/
  jQuery("a").each(function(){
    if((this.href != "") && (this.href.indexOf("javascript:") == -1) && (this.href.indexOf("mailto:") == -1) && (this.href.indexOf(dominio) == -1)){
      this.innerHTML = this.innerHTML + "&nbsp;<img border=\"0\" src=\"/NSI-theme/images/wiki/external.png\"/>";
      this.setAttribute('target', '_blank');
    }
  });
  
});
function nome(codice){
  var output = "";
  
  var nome = "";
  for(i=0;i<codice.length;i++){
    nome = "";
    for(j=0;j<codice[i].length;j++){
      nome += String.fromCharCode(codice[i][j]);
    }
    output += "<a href='mailto:"+nome+"nsi-mail.it'>"+nome+"nsi-mail.it</a>";
  }
  
  return output;
}
/*Funzioni utilizzate da template xsl*/
function chars(str){
  return str.replace("'", "&#39;")
}

function newsItem(id, testoXML){
  var n = '<li><xsl:element name="a"><xsl:attribute name="href">/web/guest/news/-/journal_content/56_INSTANCE_lR5b/11417/'+id+'</xsl:attribute>'+chars(testoXML)+'</xsl:element></li>';
  return n;
}

function menusecondario(elemento, listalink, colore){
  jQuery("#ac_"+elemento).after(listalink);
  jQuery("#ac_"+elemento).css({'font-weight' : 'bold', 'color' : colore});
  if(elemento.indexOf("contatti") != -1){
    jQuery("#sottoelemento_wrapper").css({'margin-bottom' : '5px', 'border-bottom' : '1px dotted #CCC'});
  }
}
function setFSize(i){
  var j = jQuery(".journalItem");
  var fs = parseFloat(j.css("font-size").replace("px","")) +i;
  if(fs > 10 && fs < 17){
    j.css("font-size", fs.toString()+"px");
  }
}

function loginToggle(){
  jQuery('.testo_gestione_wrapper').toggle();
  jQuery('.lr_ricerca').toggle();
  jQuery('#_58_INSTANCE_MAIN_fm').toggle();
}
