var proprieta;
var regole;

var obiettivo;
var lamiachi;
var direzione;
var valore;
var id = 0;

var livello = [1, 1, 1, 1, 1];
var livelli = [5, 5, 5, 5, 5];
var visibili= [1, 1, 1, 1, 1];
var nomiDettagli = ["Riassunto", "Minimalista", "Comprensibile",
			"Lievemente logorroico", "Da paura!"];
var dimDettagli = [10, 10, 10, 10, 10];

function mostra (chi)
{
	document.getElementById("dettaglio"+chi).innerHTML = "Livello di dettaglio: " + nomiDettagli[livello[chi]];
	for ( var i = 1; i <= livello[chi]; i++ )
		regole[chi*5+i].style.display = "inline";
	for ( var i = livello[chi]+1; i < livelli[chi]; i++ ) {
		regole[chi*5+i].style.display = "none";
		regole[chi*5+i].style.fontSize = "1%";
	}
	if ( livello[chi] >= livelli[chi]-1 ) {
		document.getElementById("dipiu"+chi).style.color = "#a0a0a0";
	}
	if ( livello[chi] == 0 ) {
		document.getElementById("dimeno"+chi).style.color = "#a0a0a0";
	}
}

function cambiainsu ()
{
	valore += direzione;
	if ( valore > 100 ) {
		valore = 100;
		window.clearInterval (id);
		id = 0;
	}
	regole[obiettivo].style.fontSize = valore+"%";
}

function cambiaingiu ()
{
	valore += direzione;
	if ( valore < 10 ) {
		valore = 100;
		window.clearInterval (id);
		id = 0;
		livello[lamiachi]--;
		if ( livello[lamiachi] < 0 )
			livello[lamiachi] = 0;
		mostra (lamiachi);
	}
	regole[obiettivo].style.fontSize = valore+"%";
}

function dipiu (chi)
{
	if ( id )
	   return;
	if ( livello[chi] >= livelli[chi]-1 )
		return;
	livello[chi]++;
	document.getElementById("dimeno"+chi).style.color = "#303030";
	if ( livello[chi] >= livelli[chi]-1 ) {
		document.getElementById("dipiu"+chi).style.color = "#a0a0a0";
	}
	obiettivo = chi*5 + livello[chi];
	valore = 10;
	direzione = 10;
	regole[obiettivo].style.fontSize = "1%";
	mostra (chi);
	id = window.setInterval ("cambiainsu()", 100);
}

function dimeno (chi)
{
	if ( id )
	   return;
	if ( livello[chi] == 0 )
		return;
	document.getElementById("dipiu"+chi).style.color = "#303030";
	if ( livello[chi] == 1 ) {
		document.getElementById("dimeno"+chi).style.color = "#a0a0a0";
	}
	lamiachi = chi;
	valore = 100;
	obiettivo = chi*5 + livello[chi];
	direzione = -10;
	id = window.setInterval ("cambiaingiu()", 100);
}

function nascondi (chi)
{
	if ( visibili[chi] ) {
		document.getElementById("corpo"+chi).style.display = "none";
		var a = document.getElementById ("nascondi"+chi);
		a.innerHTML = "Mostra";
		visibili[chi] = 0;
	}
	else {
		document.getElementById("corpo"+chi).style.display = "block";
		var a = document.getElementById ("nascondi"+chi);
		a.innerHTML = "Nascondi";
		visibili[chi] = 1;
	}
}

function inizia ()
{
	proprieta = document.styleSheets[1];
	regole = proprieta.cssRules ? proprieta.cssRules : proprieta.rules;

/*
	for ( var i = 0; i < livello.length; i++ ) {
		if ( !visibili[i] ) {
			visibili[i] = 1;
			nascondi(i);
		}
		mostra (i);
	}
*/
}


