
function open_comunicato(n, height)
{
	var active = $("comunicato" + n);
	var inactive_1 = null, inactive_2 = null;
	if (n == 1)
	{
		inactive_1 = $("comunicato2");
		inactive_2 = $("comunicato3");
	}
	else if (n == 2)
	{
		inactive_1 = $("comunicato1");
		inactive_2 = $("comunicato3");
	}
	else if (n == 3)
	{
		inactive_1 = $("comunicato1");
		inactive_2 = $("comunicato2");
	}

	active.style.height = soft_transition_up(0, height, active.getHeight()) + "px";
	inactive_1.style.height = soft_transition_down(height, 0, inactive_1.getHeight()) + "px";
	inactive_2.style.height = soft_transition_down(height, 0, inactive_2.getHeight()) + "px";
	
	if (active.getHeight() < height || inactive_1.getHeight() > 0 || inactive_2.getHeight() > 0)
	{
		clearTimeout($("comunicati").timer);
		$("comunicati").timer = setTimeout("open_comunicato(" + n + ", " + height + ")", 30);
	}
}

function soft_transition_up(from, to, actual)
{
	if (actual >= to)
	{
		return to;
	}
	
	var r = (to - actual) / 3;
	r = r < 1 ? 1 : r;
	
	return actual + r;
}

function soft_transition_down(from, to, actual)
{
	if (actual <= to)
	{
		return to;
	}
	
	var r = (actual - to) / 3;
	r = r < 1 ? 1 : r;
	
	return actual - r;
}

