﻿/////////////////////////////////////////////////////////////////////////////
// http://www.quirksmode.org/blog/archives/2006/01/contains_for_mo.html
// Firefox doesn't support the .contains method because it's not part of the
// standard.
// This will allow firefox code to use "contains".
// IRM uncommented and using, works well.
if (window.Node && Node.prototype && !Node.prototype.contains)
{
	Node.prototype.contains = function (arg) {
		return !!(this.compareDocumentPosition(arg) & 16)
	}
}

//
/////////////////////////////////////////////////////////////////////////////

function window_onLoad()
{
    document.body.onmouseover = navigation.checkMenu;
}

// Javascript-style class definition
function navigationClass()
{
    // var xxx   : acts as a private member
    // this.xxx  : acts as a public member
    
    // private
    var _currentDropDownMenu = null;
        
    // public methods
    this.onMenuMouseOver = priv_onMenuMouseOver;
    this.checkMenu = priv_checkMenu;
    
	
	//----------------------------------------------------------------------------------
	function priv_onMenuMouseOver(e, arg) 
	{
	    var menuLabel = e;

		var dropDownMenu = document.getElementById(arg);
		clearDropDown();
		_currentDropDownMenu = dropDownMenu;
		displayMenu(menuLabel, _currentDropDownMenu, false);
	}
	//----------------------------------------------------------------------------------
	function displayMenu(objElement, objMenu, blnIsSubMenu) 
	{
		objMenu.style.top =  (getElementPosition(objElement, 'top') + objElement.offsetHeight) + 'px';
		objMenu.style.left = (getElementPosition(objElement, 'left') + 0                     ) + 'px';
//		getElementPosition(objElement, 'left') - 100 + 'px';
        objMenu.style.visibility = 'visible';
        objMenu.style.zIndex = '20';
	}
	//----------------------------------------------------------------------------------
	function getElementPosition(objElement, strLeftOrTop)
	{
	/* progrmr: Dominic Van Horn
	'date   : 10/19/2000
	'inputs : objElement is the element whose position is to be discovered
	'         strLeftOrTop Tells the function which plane to work with.
	'         NOTE: VALUE MUST BE EITHER 'Left' OR 'Top'.
	'outputs: returns an integer representing distance from the Left or Top 
	'         of the window and the passed object (objElement).
	'local  : intPosition holds the position of the element.
	'         theOffset phrase evaluated to increment intPosition.
	'purpose: Return an integer representing distance between an object and
	'         the Left or Top edge of the document.
	'logic  : verify that 'left' or 'top' were passed else set strLeftOrTop to null
	'         If objElement and strLeftOrTop are valid then..
	'           set theOffset value to access the correct property of objElement
	'             while objElement is valid
	'               If the current object has the property we're looking for
	'                 increment intPosition by that property's value
	'               set objElement equal to the next container with an offset value
	'             return intPosition plus the width of the document's margin
    */
		var theOffset;
		var objElLocal = objElement;

		var intPosition = 0;
		strLeftOrTop = (strLeftOrTop.toLowerCase() == 'left') ? 'Left' : (strLeftOrTop.toLowerCase() == 'top' ? 'Top' : null);
		if (isObject(objElLocal) && strLeftOrTop != '')
		{
			theOffset = 'objElLocal.offset' + strLeftOrTop;
			while (isObject(objElLocal))
			{
				if (eval(theOffset) > 0)
				{
					intPosition = intPosition + eval(theOffset);
				}
				if (isObject(objElLocal.offsetParent))
				{
					objElLocal = objElLocal.offsetParent;
				}
				else
				{
					objElLocal = NaN;
				}
			}
		}
		
		// IE only
		var clientLeftOrTop = eval('document.body.client' + strLeftOrTop);
		if (clientLeftOrTop)
		{
			intPosition += clientLeftOrTop;
		}
		
		return intPosition;
	}

	//----------------------------------------------------------------------------------
	function clearDropDown() 
	{
		if (isObject(_currentDropDownMenu))
		{
			_currentDropDownMenu.style.visibility = 'hidden'
		}
	}

	//----------------------------------------------------------------------------------
    function isObject(a) {
        try
        {
        return (a && typeof a == 'object') || isFunction(a);
        }
        catch(err)
        {
            return false;
        }
    }

	//----------------------------------------------------------------------------------
	function priv_checkMenu(e)
	{
		if (_currentDropDownMenu != null)
		{		    
			var menuContainer = document.getElementById('divNav');
			var menuDropdownContainer = document.getElementById('divNavMenus');

			if(!menuContainer.contains(util_GetEventSource(e)) && !menuDropdownContainer.contains(util_GetEventSource(e)))
			{
				clearDropDown();
				//AutoShowSelect()
			}
		}
	}

    // Process an event's source element in a way that is compatible with both IE and Mozilla (Firefox)
    // http://www.quirksmode.org/js/events_properties.html
    function util_GetEventSource(e)
    {
    	var targ;
	    if (!e) var e = window.event;
	    if (e.target) targ = e.target;
	    else if (e.srcElement) targ = e.srcElement;
	    return targ;
    }

//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------

}

// Singleton
var navigation = new navigationClass();


// ATLAS calls a method with this name automatically.
// This method should be used for any onPageLoad processing that needs ATLAS
function pageLoad()
{
    document.body.onmouseover = navigation.checkMenu;
}   



