var HROW = 90;
var DELTA_SPACE = 20;
var DELTA_TIME = 10;
var ERRORE = 43;
var PIU = 135;

var STATUS_OPENED = 0;
var STATUS_CLOSED = 1;
var status = STATUS_CLOSED;

var objToMove = null;
var YSTART = 120;
var idTimer = null;

function init(id)
{
	objToMove = find(id);
	YSTART = parseInt(objToMove.style.top);
}

function find(id)
{
	if (document.getElementById)
	{
	  	return(document.getElementById(id));
	}
	else if (document.all)
	{
		return(document.all[id]);
	}
	else if (document.layers)
	{
		return(document.layers[id]);
	}
	return(null);	
}

function letsMove(nrows)
{

	if(idTimer == null)
	{
		if(status == STATUS_OPENED)
			idTimer = setInterval("move_close()",DELTA_TIME)
		else
			idTimer = setInterval("move_open("+((nrows*HROW)-ERRORE+PIU)+")",DELTA_TIME);
	}
}

var ccc = 0;

function move_open(stopAt)
{
		//alert(objToMove.style.top);
		//alert(parseInt(objToMove.style.top));
	var y = parseInt(objToMove.style.top) + DELTA_SPACE;
	if(y >= stopAt )
	{
		y = stopAt;
		clearInterval(idTimer);
		status = STATUS_OPENED;
		idTimer = null;
	}
	//alert("PRIMA objToMove.style.top="+objToMove.style.top+"  y="+y);
	objToMove.style.top = y+"px";
	//alert("DOPO objToMove.style.top="+objToMove.style.top+"  y="+y);
}

function move_close()
{
	var y = parseInt(objToMove.style.top) - DELTA_SPACE;
	if(y <= YSTART)
	{
		y = YSTART;
		clearInterval(idTimer);
		status = STATUS_CLOSED;
		idTimer = null;
	}
	objToMove.style.top = y + "px";
}
