// menu_pos.js centers the menu on x and positions absolutly under the logo for y
// developed for the SPORTSCENTER skin package

tryInterval = setInterval ("isReady()", 100); // checks every 100ms to see if solpart has been populated

function isReady()
{
    var iWatch = parseInt(document.getElementById("menu_wrap").offsetWidth);
    if (parseInt(document.getElementById("menu_wrap").offsetWidth) > 26) //26 = width of both menucaps combined
    {
        if (getHeight("logo_div")==0)
	    {
		    clearInterval(tryInterval)
		    setTimeout("run();",2000) //wait 2 seconds incase the logo has not started to loaded yet
	    }
	    else
	    {
		    clearInterval(tryInterval)
		    run();
	    }
    }
}

function run()
{
	centerElementOnXInElement("menu_wrap", "body_wrap");
	placeMenuOffLogoOnY();
	document.getElementById("menu_wrap").style.zIndex = "999"; //unhide menu after proper placement
}

function centerElementOnXInElement(sIDCenter, sIDContainer)
{
	if (sIDCenter != null && sIDContainer != null)
	{
		var iOffset = getWidth(sIDCenter);
		var iCenter = getWidth(sIDContainer);
		if (iOffset > 1 && iCenter > 1) 
		{
			iOffset = iOffset * 0.5;
			iCenter = iCenter * 0.5;
			var iLeft = iCenter - iOffset; 
			iLeft = iLeft.toString().split(".",1) //returns a single entry array
			document.getElementById(sIDCenter).style.left = iLeft[0] +"px";
		}
	}
}

function getWidth(sID) 
{
	var iReturnValue = 0;
	if(sID != null) 
	{
		iReturnValue = parseInt(document.getElementById(sID).offsetWidth); // removes the "px" at the end
	}
	return iReturnValue;
}

function placeMenuOffLogoOnY()
{	
	document.getElementById("menu_wrap").style.top = getHeight("logo_div").toString(); //places menue below logo on Y
}

function getHeight(sID) 
{
	var iReturnValue = 0;
	if(sID != null) 
	{
		iReturnValue = parseInt(document.getElementById(sID).offsetHeight); // removes the "px" at the end
	}
	return iReturnValue;
}
