var mouseX;
var mouseY;
var openControls = new Object();
var openControlsOrigs = new Object();


function timeouted_remove(id, orig) {
	window.setTimeout("_remove('"+id+"', '"+orig+"')", 200);
}

function display(id, orig) {
    for (var control in openControls) {
	  openControls[control].style.visibility = "hidden";
    }
    for (var control in openControlsOrigs) {
	  openControlsOrigs[control].className = "";
    }
	document.getElementById(id).style.visibility = "visible";
	document.getElementById(orig).className = "active";
	openControls[id] = document.getElementById(id);
	openControlsOrigs[orig] = document.getElementById(orig);
}

function _remove(id, orig) {
	if (!isMouseIn(id) && !isMouseIn(orig)) {
		document.getElementById(id).style.visibility = "hidden";
		document.getElementById(orig).className = "";
	}
}

function setCords(e)
{
    mouseX = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
    mouseY = (document.all) ? window.event.y + document.body.scrollTop : e.pageY;
}

function isMouseIn(id) {
    x = document.getElementById(id).offsetLeft;
    y = document.getElementById(id).offsetTop;
	pos = getRect(id);
	if (mouseX > pos.left && mouseY > pos.top && mouseX < (pos.left+pos.width) && mouseY < (pos.top+pos.height)) {
		return true;
	}
	return false;
}

function getRect (o)
{
    var r = { top:0, left:0, width:0, height:0 };

    if(!o) return r;
    o = document.getElementById(o);

    if(typeof o.offsetTop != 'undefined')
    {
         r.height = o.offsetHeight;
         r.width = o.offsetWidth;
         r.left = r.top = 0;
         while (o && o.tagName != 'BODY')
         {
              r.top  += parseInt( o.offsetTop );
              r.left += parseInt( o.offsetLeft );
              o = o.offsetParent;
         }
    }
    return r;
}

//document.onmousemove = setCords;

function remove(id, orig) {
	if (!isMouseIn(id) && !isMouseIn(orig)) {
		document.getElementById(id).style.visibility = "hidden";
		document.getElementById(orig).className = "";
	}
}
function display(id, orig) {
	document.getElementById(id).style.visibility = "visible";
	document.getElementById(orig).className = "active";
}

