//timer=setInterval("HideMenu()",1000);
var idOpened = "-";

function ShowGroupMenu(IDGruppo,topPos)
{
	idOpened = "catGrp"+IDGruppo;
	HideAll(idOpened);
	SetVisibility(IDGruppo, "visible",topPos);
}

function HideGroupMenu(IDGruppo)
{
	idOpened = "catGrp"+IDGruppo;
	callback = "SetVisibility(\""+IDGruppo+"\", \"hidden\",0)";
	timer = setTimeout(callback,200);
	idOpened = "-";
}

function SetVisibility(IDGruppo, vis, topPos)
{
	if (vis == "hidden")
	{
		if (idOpened == "-")
		{
			document.getElementById("catGrp"+IDGruppo).style.visibility = vis;
			document.getElementById("grp"+IDGruppo).style.background = "#EEEEEE";
		}
	}
	else
	{
		//alert(getPageCoords(document.getElementById("menuList")).y);
		yoffset = getPageCoords(document.getElementById("menuList")).y;
		document.getElementById("catGrp"+IDGruppo).style.top = (yoffset+topPos+60)+"px";
		document.getElementById("catGrp"+IDGruppo).style.visibility = vis;
		document.getElementById("grp"+IDGruppo).style.background = "#70a09b";
	}
}

function HideAll(obj)
{
	for (i=0; i<100; i++)
	{
		curObj = "catGrp"+i;
		if (curObj != obj)
		{
			var elCat = document.getElementById(curObj)
			if (elCat != null)
			{
				elCat.style.visibility = "hidden";
			}
			var el = document.getElementById("grp"+i)
			if (el != null)
			{
				el.style.background = "#EEEEEE";
			}
		}
	}
}

function getPageCoords (element) { // thanks to 'Martin Honnen' for this idea
var myElement, coords = {x: 0, y: 0};
    // prendo lo scroll del body
    myElement = element; // salvo l'elemento: mi riserve dopo
    while (element) {
        coords.x -= element.scrollLeft;
        coords.y -= element.scrollTop;
        element = element.offsetParent;
    }
    element = myElement; // l'avevo salvato
    // ora prendo l'offset dell'elemento
    while (element) {
        coords.x += element.offsetLeft;
        coords.y += element.offsetTop;
        element = element.offsetParent;
    }
    // ritorno le coordinate dell'angolo in alto a sx
    // dell'elemento considerate rispetto all'angolo
    // in alto a sinistra della finestra visibile
    return coords;
} 
