var $timer;

function rollin( $strId )
{
	document.getElementById('menu'+$strId).src = '/images/menu/menu-' + $strId + '-on.jpg';
}

function rollout( $strId )
{
	document.getElementById('menu'+$strId).src = '/images/menu/menu-' + $strId + '-off.jpg';
}

function showMenu( $objCaller, $strMenuName )
{
	$objDiv = document.getElementById( $strMenuName );

	if ( $objDiv )
	{
		$objImage = getParent( $objCaller, 'img' );
		$intX = getXPosition( $objImage );

		$objDiv.style.display = 'block';
		$objDiv.style.left = $intX + 'px';


	}
}

function setTimer()
{
	$timer = setTimeout( hideMenus, 500 );
}

function killTimer()
{
	clearTimeout( $timer );
}

function hideMenus()
{
	var $objDiv = document.getElementById( 'productMenu' );
	rollout( '03' );

	if ( $objDiv )
	{
		$objDiv.style.display = 'none';
	}

	$objDiv = document.getElementById( 'contactUsMenu' );
	rollout( '04' );

	if ( $objDiv )
	{
		$objDiv.style.display = 'none';
	}
}

/**
* Recursively walks the DOM tree until it finds a parent
* node with the tag type specified as the second parameter
*
* @param	object
* @param	string
* @return	object
*/
function getParent( $objChild, $strTagName )
{
	if ( $objChild == null )
	{
		return null;
	}

	else if (    $objChild.nodeType == 1
			  && $objChild.tagName.toLowerCase() == $strTagName.toLowerCase() )
	{
		return $objChild;
	}

	else
	{
		return getParent( $objChild.parentNode, $strTagName );
	}
}

/**
* Finds the "X" position of an element by climbing
* the DOM tree and adding all the offsetLeft coordinates
*
* @access	public
* @author	Michael Bueche <mbueche@satx.rr.com>
*
* @param	object
* @return	integer
*/
function getXPosition( $objToGetX )
{
	var $intLeftTotal = 0;
	if ( $objToGetX.offsetParent )
	{
		while ( $objToGetX.offsetParent )
		{
			$intLeftTotal  += $objToGetX.offsetLeft
			$objToGetX		= $objToGetX.offsetParent;
		}
	}
	else if ( $objToGetX.x )
	{
		$intLeftTotal += $objToGetX.x;
	}

	return $intLeftTotal;
}


/**
* Finds the "Y" position of an element by climbing
* the DOM tree and adding all the offsetTop coordinates
*
* @access	public
* @author	Michael Bueche <mbueche@satx.rr.com>
*
* @param	object
* @return	integer
*/
function getYPosition( $objToGetY )
{
	var $intTopTotal = 0;
	if ( $objToGetY.offsetParent )
	{
		while ( $objToGetY.offsetParent )
		{
			$intTopTotal   += $objToGetY.offsetTop
			$objToGetY		= $objToGetY.offsetParent;
		}
	}
	else if ( $objToGetY.y )
	{
		$intTopTotal += $objToGetY.y;
	}

	return $intTopTotal;
}
