var oldcolor="", el, oldsfondo, sfondo, color, childNews=[], resizenews=1, oldoffset="0px", news;

function init(idpadre) {
	e=document.getElementById(color).firstElementChild;
	if(/IE (\d+\.\d+);/.test(navigator.userAgent)) {
		$("#cerca").css("top", "-3px");
		$("#msopra td span").css("top", "-5px");}
	tool(color, idpadre);
	window.onresize=resizeContent;
	resizeContent();
}

function resizeContent() {
	var news=document.getElementById("news");
	//news.style.cssText="height: "+oldoffset+"; ";
	var textnews=document.getElementById("textnews");
	var h1=document.getElementById("maintitle");
	h1.innerHTML="Liceo Scientifico Innocenzo XII";
	h1.className="";
	if (h1.offsetHeight>130) {
		h1.innerHTML="<div>Liceo Scientifico</div>Innocenzo XII";
		h1.className="titlesmall";
	}
	var a=document.getElementById("contentt");
	news.style.height=a.style.height="auto";
	var oldoffset=news.offsetHeight+"px";
	var b=document.getElementById("footer");
	for (i=0; i<childNews.length; i++) {
		news.appendChild(childNews.pop());
	}
	if (resizenews) {
		textnews.style.display="none";
	}
	if (document.getElementById("all").offsetHeight<=document.documentElement.clientHeight) {
		a.style.height=document.documentElement.clientHeight-a.offsetTop-b.offsetHeight-24+"px";
	}
	else if (resizenews){
		a.style.minHeight=document.documentElement.clientHeight-a.offsetTop-b.offsetHeight-24+"px";
		exit=1;
		while (exit) {
			if (news.offsetHeight<=a.offsetHeight-(news.offsetTop-a.offsetTop)-35) {exit=0;}
			else if (news.childElementCount<6) {
				exit=0;
				a.style.minHeight=document.getElementById("all").offsetHeight-a.offsetTop-b.offsetHeight-24+"px";
			}
			else {childNews.push(news.removeChild(news.lastChild));}
		}
	}
	if (childNews.length>0) {
		textnews.style.display="inherit";
		exit=1;
		while (exit) {
			if (news.offsetHeight<=a.offsetHeight-(news.offsetTop-a.offsetTop)-35) {exit=0;}
			else if (news.childElementCount<6) {
				exit=0;
				a.style.minHeight=document.getElementById("all").offsetHeight-a.offsetTop-b.offsetHeight-24+"px";
			}
			else {childNews.push(news.removeChild(news.lastChild));}
		}
	}
	/*newoffset=news.offsetHeight+"px";
	news.style.height=oldoffset;
	news.style.cssText+="-webkit-transition: height 0.5s linear; ";
	news.style.height=newoffset;
	setTimeout("aggiornaold()", 1000);*/
}

function aggiornaold() {
oldoffset=news.offsetHeight+"px";
}

function moreNews() {
	var textnews=document.getElementById("textnews");
	if (textnews.innerHTML=="+ Novità") {
		resizenews=0;
		var news=document.getElementById("news");
		while (childNews.length>0) {
			news.appendChild(childNews.pop());
		}
		textnews.innerHTML="- Novità";
		resizeContent();
	}
	else if (textnews.innerHTML=="- Novità"){
		textnews.innerHTML="+ Novità";
		resizenews=1;
		resizeContent();
	}
}

function tool(e, idpadre) {
	el=document.getElementById(e);
	oldel=document.getElementById(oldcolor);
	sez2=document.getElementById("msotto").rows[0];
	if (el!=oldel) {
		try {
			oldel.className="";
			oldel.previousSibling.className="hide";
			oldel.nextSibling.className="hide";
		}
		catch(err) {}
		el.className=el.id;
		try {
			el.previousSibling.className="";
			el.nextSibling.className="";
		}
		catch(err) {}
		barra(el.id);
		oldcolor=el.id;
		while (sez2.cells.length-2) {
			sez2.deleteCell(1);
		}
		for (a=sezioni.length-1; a>0; a--) {
			if (sezioni[a][1]==idpadre) {
				b=sez2.insertCell(1);
				b.innerHTML="<a href=\"?sez="+sezioni[a][2]+"\">"+sezioni[a][0]+"</a>"
			}
		}
	}
}

function barra(col) {
	bar=document.getElementById("msotto").className="b"+col;
	}

function colori(colore) {
	if (colore=="orange") {
		sf=[206, 92, 0, 1, 245, 121, 0, 1];}
	else if (colore=="red") {
		sf=[164, 0, 0, 1, 204, 0, 0, 1];}
	else if (colore=="green") {
		sf=[78, 154, 6, 1, 115, 210, 22, 1];}
	else if (colore=="blue") {
		sf=[32, 74, 135, 1, 52, 101, 164, 1];}
	else if (colore=="violet") {
		sf=[92, 53, 102, 1, 117, 80, 123, 1];}
	return sf;
}

