var divs = new Array();
var index = new Array();
var positions = new Array();
var heights = new Array();
var directions = new Array();
var timeId;

var timeout = 20;
var speed = 3;

function editBoxOn(o, what, height) {
	var i;
	if (typeof index[what] == 'undefined') {
		i = divs.length;
		index[what] = i
		divs[i] = document.getElementById(what);
		positions[i] = 0;
		directions[i] = 1;
		heights[i] = height;
		divs[i].style.visibility = 'visible'; /* not needed */
	} else {
		i = index[what];
		directions[i] = 1;
	}
	if (!timeId) timeId = setTimeout('moveBoxes()', timeout);
}

function editBoxOff(o, what, height) {
	i = index[what];
	directions[i] = -1;
	if (!timeId) timeId = setTimeout('moveBoxes()', timeout);
}

function moveBoxes() {
	cont = 0;
	for(i = 0; i < divs.length; i++) {
		div = divs[i];
		h = heights[i];
		pos = positions[i];
		d = directions[i];
		var newpos;
		if ((pos < h && d > 0) || (pos > 0 && d < 0)) {
			newpos = pos + directions[i]*speed;
			var c;
			c = -(Math.cos((newpos/h)*(Math.PI/2)+ Math.PI/2));
			div.style.top = ((c*h - h) + 'px');
			positions[i] = newpos;
		}

		if ((newpos <= 0 && directions[i] < 0) ||
		    (newpos >= heights[i] && directions[i] > 0)) {
			directions[i] = 0;
		} else {
			cont = 1;
		}
	}
	if (cont) timeId = setTimeout('moveBoxes()', timeout);
	else timeId = 0;
}


function calcHeight(id)
{
    var elem = document.getElementById(id);
    //find the height of the internal page
    var the_height = elem.contentDocument.body.scrollHeight;
 
    //change the height of the iframe
    elem.height = the_height;
}
