//Funzione che mostra o nasconde elementi
function mostraElemento(cosa) {
	if (document.getElementById){
		current = (document.getElementById(cosa).style.display == 'block') ? 'none' : 'block';
		document.getElementById(cosa).style.display = current;
	}else if (document.all){
		current = (document.all[cosa].style.display == 'block') ? 'none' : 'block'
		document.all[cosa].style.display = current;
	}
	
	var note_menu = xGetElementById("note_menu");
	note_menu.style.marginTop = 0;
	note_menu.style.marginTop = (xHeight("contenuto")-415)+"px";
	var colonna1 = xGetElementById("menu_bar");
	colonna1.style.paddingBottom = 0;
	colonna1.style.paddingBottom = (xHeight("contenuto")-xHeight("menu_bar"))+"px";
	var colonna2 = xGetElementById("options_bar");
	colonna2.style.paddingBottom = 0;
	colonna2.style.paddingBottom = (xHeight("contenuto")-xHeight("options_bar"))+"px";
}

function setActiveStyleSheet(title, reset) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (reset == 1) {
	  createCookie("wstyle", title, 365);
  }
}

function setStyle() {
	var style = readCookie("wstyle");
	if (style != null) {
		if (style=="nessuno") {
			noCss("nessuno", 1);
		}else{
			setActiveStyleSheet(style, 0);
		}
	}
}

//Scrive un cookie
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

//Legge un cookie
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

//Regola le altezze
function adjustLayout(){
	if(xHeight("menu_bar")>xHeight("options_bar")){
		var greatCol=xHeight("menu_bar");
	}else{
		var greatCol=xHeight("options_bar");
	}
	if(xHeight("contenuto")<greatCol){
		var contenuto = xGetElementById("contenuto");
		contenuto.style.paddingBottom = (greatCol-xHeight("contenuto")+20)+"px";
		var colonna1 = xGetElementById("menu_bar");
		colonna1.style.paddingBottom = (xHeight("contenuto")-xHeight("menu_bar"))+"px";
		var colonna2 = xGetElementById("options_bar");
		colonna2.style.paddingBottom = (xHeight("contenuto")-xHeight("options_bar"))+"px";
	}else{
		var note_menu = xGetElementById("note_menu");
		note_menu.style.marginTop = (xHeight("contenuto")-360)+"px";
		var colonna1 = xGetElementById("menu_bar");
		colonna1.style.paddingBottom = (xHeight("contenuto")-xHeight("menu_bar"))+"px";
		var colonna2 = xGetElementById("options_bar");
		colonna2.style.paddingBottom = (xHeight("contenuto")-xHeight("options_bar"))+"px";
	}
}

window.onload = function() {
	setStyle();
	adjustLayout();	
	startscroll();
}

