var current = "";
var offset = 0;
var divs = new Array('data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data8', 'data9', 'data10', 'data11', 'data12', 'data13', 'data14', 'data15', 'data16');
var done = false;
var tornapposto = true;

function test(divname) {
	for (var i = 0; i < divs.length; i++) {
		if (divname == divs[i]) document.getElementById(divs[i] + "_mp3").style.visibility = "visible";
	}
	//menu in posizione iniziale
	if (!done) {	
		openMenu(divname);
	}
	//tutti a destra tranne uno
	else {
		if (divname == current) {
			document.getElementById(divname + "_mp3").style.visibility = "hidden";
			closeMenu(divname);
		}
		else {
			document.getElementById(current + "_mp3").style.visibility = "hidden";
			swappamelo(divname);
		}
	}
	
}


//apre una casella di testo e sposta gli altri elementi sulla destra
function openMenu(divname) {
	current = divname;
	YAHOO.util.Dom.setStyle("infobox", "visibility", "hidden");
	YAHOO.util.Dom.setStyle("footer", "visibility", "hidden");
	for (var i = 0; i < divs.length; i++) {
		if (!(divname == divs[i])) {
			if (!done) offset += 60;
			new YAHOO.util.Motion(divs[i], {points: { to: [365, ]}}, 0.4).animate();
		}
		else {
			var burp = new YAHOO.util.Anim(divs[i], {height: { to: (YAHOO.util.Dom.getViewportHeight() - 26)}, top: { to: 0 }}, 0.3);
			YAHOO.util.Dom.setStyle(divs[i] + "_text", "height", (YAHOO.util.Dom.getViewportHeight() - 90) + "px");
			YAHOO.util.Dom.setStyle(divs[i], "border-bottom", "3px solid black");
			burp.onComplete.subscribe(setStyleScroll);
			burp.animate();
			done = true;
		}
	}
}

function swappamelo(divname) {
	var qualestoconsiderando = 0;
	for (var i = 1; i <= 16; i++) {
		if (current == ("data" + i)) qualestoconsiderando = i;
	}
	document.getElementById(current + "_text").style.overflow = "hidden";
	new YAHOO.util.Anim(current, {height: { to: 35}, top: { to: ((qualestoconsiderando * 60) - 60) }}, 0.3).animate();
	new YAHOO.util.Scroll(current, { scroll: { to: [0, ] }}, 0.1).animate();
	YAHOO.util.Dom.setStyle(current, "border-bottom", "none");
	new YAHOO.util.Motion(current, {points: { to: [365, ]}}, 0.4).animate();
	
	new YAHOO.util.Motion(divname, {points: { to: [15, ]}}, 0.3).animate();
	var burp = new YAHOO.util.Anim(divname, {height: { to: (YAHOO.util.Dom.getViewportHeight() - 26)}, top: { to: 0 }}, 0.3);
	YAHOO.util.Dom.setStyle(divname + "_text", "height", (YAHOO.util.Dom.getViewportHeight() - 90) + "px");
	YAHOO.util.Dom.setStyle(divname, "border-bottom", "3px solid black");
	burp.onComplete.subscribe(setStyleScroll);
	burp.animate();
	current = divname;
	tornapposto = false;
}

function closeMenu(divname) {
	//torna allo stato iniziale
	for (var i = 0; i < divs.length; i++) {
		if (!(current == divs[i])) {
			new YAHOO.util.Motion(divs[i], {points: { to: [15, ]}}, 0.3).animate();
		}
		else {
			if (!tornapposto) {
				offset = i * 60;
				tornapposto = true;
			}
			document.getElementById(divs[i] + "_text").style.overflow = "hidden";
			new YAHOO.util.Anim(current, {height: { to: 35}, top: { to: offset }}, 0.3).animate();
			new YAHOO.util.Scroll(current, { scroll: { to: [0, ] }}, 0.1).animate();
			YAHOO.util.Dom.setStyle(divs[i], "border-bottom", "none");
		}
	}
	YAHOO.util.Dom.setStyle("infobox", "visibility", "visible");
	YAHOO.util.Dom.setStyle("footer", "visibility", "visible");
	offset = 0;
	current = "";
	done = false;
}


//imposta la casella di testo a scroll automatico
function setStyleScroll() {
	if (current != "") document.getElementById(current + "_text").style.overflow = "auto";
}

//aggiusta gli elementi in caso di resize della pagina
function adjust() {
	var height = YAHOO.util.Dom.getViewportHeight();
	new YAHOO.util.Anim(current, {height: { to: (height - 26)}, top: { to: 0 }}, 0).animate();
	if (height < 940) {
		YAHOO.util.Dom.setStyle("content", "height", "940px");
		YAHOO.util.Dom.setStyle("right", "height", "960px");
		YAHOO.util.Dom.setStyle("blacco", "height", "960px");
	}
	else {
		YAHOO.util.Dom.setStyle("content", "height", (height - 20) + "px");
		YAHOO.util.Dom.setStyle("right", "height", height + "px");
		YAHOO.util.Dom.setStyle("blacco", "height", height + "px");
	}
}

window.onload = adjust;
window.onresize = adjust;
