// JScript source code
// style switcher - www.stichpunkt.de/css/switch.html -- pro.html.it/
// menu espandibile -  pro.html.it/

// nota: accrocco dei 2 js di cui sopra per farli partire insieme 

var ATCstileDefault = ""; // title del css di default
var ATCstileCookie = "ATClayout"; // nome del cookie 
var ATCstileCookieDurata = 30; // data di scadenza del cookie in giorni

var SonoAllInizio="null"; // variabile per il menu-toggler

// evvai con le danze:

window.onload = loadTutto;  // esegue le funzioni per il toggler e per lo switcher (vedi in fondo)

// parte relativa allo style switcher

function switchStyle(s) 
{
  if (!document.getElementsByTagName) return;
  var el = document.getElementsByTagName("link");
  for (var i = 0; i < el.length; i++ ) 
  {
    if (el[i].getAttribute("rel").indexOf("style") != -1 && el[i].getAttribute("title")) {
      el[i].disabled = true;
      if (el[i].getAttribute("title") == s) el[i].disabled = false;
    }
  }
}

function loadStyle() {
  var c = getStyleCookie();
  // se il cookie non è presente, scrivi il cookie di default
  if(c==null){
	//setStyleCookie();
	//provo a dargli il parametro direttamente da qua anziche chiamare la funzione
	setCookie(ATCstileCookie, "default", ATCstileCookieDurata);
	c = getStyleCookie();
  }
  if (c && c != ATCstileDefault) {
    switchStyle(c);
    style = c;
  }
}

function setStyle(s) {
  if (s != ATCstileDefault) {
    switchStyle(s);
    ATCstileDefault = s;
    setStyleCookie();
  }
}

// funzioni di creazione, lettura e cancellazione del cookie utilizzato dallo switcher

function setCookie(name, value, expdays) {
  var now = new Date();
  var exp = new Date(now.getTime() + (1000*60*60*24*expdays));
  document.cookie = name + "=" + escape(value) + ";" +
                    "expires=" + exp.toGMTString() + ";" +
                    "path=/";
}

function delCookie(name) {   // fa scadere il cookie
  var now = new Date();
  var exp = new Date(now.getTime() - 1);
  document.cookie = name + "=;" +
                    "expires=" + exp.toGMTString() + ";" + 
                    "path=/";
}

function getCookie(name) {   // restituisce il valore del cookie
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    var start = dc.indexOf(cname);
    if (start != -1) {
      start += cname.length;
      var stop = dc.indexOf(";", start);
      if (stop == -1) stop = dc.length;
      return unescape(dc.substring(start,stop));
    }
  }
  return null;
}

function setStyleCookie() {
  setCookie(ATCstileCookie, ATCstileDefault, ATCstileCookieDurata);
}

function getStyleCookie() {
  return getCookie(ATCstileCookie);
}

function delStyleCookie() {
  delCookie(ATCstileCookie);
}

// coda dello switcher - carica un css a parte per Netscape 4 o brausa ugualmente gnonco
if(document.layers)
  document.writeln("<link rel='stylesheet' type='text/css' href='/base.css' />");
  
// parte relativa al menu espandibile

function toggler()
{
if(document.getElementsByTagName && document.getElementById)
  {
  document.getElementById("navi").className="jsenable";
  BuildList();
  }
}

function BuildList()
{
var hs=document.getElementById("navi").getElementsByTagName("h3");
//alert(SonoAllInizio);
for(var r=0;r<hs.length;r++)
  {
  hs[r].onclick=function()
    {
    if(this.parentNode.className!="show")
      {
      this.parentNode.className="show";
      if(SonoAllInizio && SonoAllInizio!=this.parentNode) SonoAllInizio.className="hide";
      SonoAllInizio=this.parentNode;
      }
    else this.parentNode.className="hide";
    }
  }
}

// toggler: controlla l'indice del menu nella sottopagina e parte con il medesimo gia aperto
// nota: l'indice parte da 0 

function OpenCurrentMenu(currIndex) {
   var myHs=document.getElementById("navi").getElementsByTagName("h3");
   myHs[currIndex].parentNode.className="show";
   SonoAllInizio=myHs[currIndex].parentNode;
}

// questa funzione unisce sia lo switcher che il toggler per la chiamata dell'onload (vedi in cima)

function loadTutto()
{
  toggler();
  loadStyle();
}
