xhtml = new WebPage();
window.onload = new Function("xhtml.init();");

function WebPage()
	{
	// Step 1. Define Properties

	this.initialized = 0;

	// Step 2. Define Methods

	/**
	* Sets up the initial page state and event handlers
	*/
	this.init = function()
		{
		this.menuTimeout = null;
		this.menusInit();
		this.processLinks();
		this.initialized = 1;
		}


	/**
	* Adds new window handler to "offsite" links, and hides selection marquee around active links
	*/
	this.processLinks = function()
		{
		var links = document.getElementsByTagName('a');
		for(x=0; x<links.length; x++)
			{
			links[x].onfocus = function()
				{
				this.blur();
				}
			if(/\boffsite\b/.exec(links[x].className))
				{
				links[x].onclick = function()
					{
					window.open(this.href,'_blank');
					return false;
					}
				}
			}
		}

	this.menusInit = function()
		{
		this.menuDivs = document.getElementById('globalHeaderNavigation').getElementsByTagName('div');
		var menus = new Array('globalHeaderCompany', 'globalHeaderProducts', 'globalHeaderPda', 'globalHeaderPartnering', 'globalHeaderInvestor', 'globalHeaderNews');

		for (var x = 0; x < menus.length; x++)
			{
			// Add show menu event handler to heading anchor
			document.getElementById(menus[x]).getElementsByTagName('a')[0].onmouseover = function()
				{
				xhtml.menusHide();
				var parentDiv = xhtml.findParent(this, 'div');
				parentDiv.className = 'active';
				}

			var links = document.getElementsByTagName('li');
			if ( links.length )
				{
				for (var y = 0; y < links.length; y++)
					{
					try
						{
						// Clear timed menu hide on mouseover
						links[y].firstChild.onmouseover = function()
							{
							clearTimeout(xhtml.menuTimeout);
							}

						// Add timed menu hide on mouseout
						links[y].firstChild.onmouseout = function()
							{
							xhtml.menuTimeout = setTimeout("xhtml.menusHide();", 1000);
							}
						}
					catch (err)
						{
						}
					}
				}
			}
		}
	
	this.menusHide = function()
		{
		clearTimeout(xhtml.menuTimeout);
		for (var x = 0; x < xhtml.menuDivs.length; x++)
			{
			xhtml.menuDivs[x].className = 'inactive';
			}
		}


	/**
	* Finds the parent of the element, with of type parentTagName
	*
	* @param		element					The element object to find the parent of
	* @param		parentTagName		The type of parent element to find
	*
	* @return		The element's parent object of the specified type, or null if no parent of that type could be found
	*/
	this.findParent = function(element, parentTagName)
		{
		if (element == null)
			{
			return null;
			}
		else
			{
			if ( element.nodeType == 1 && element.tagName.toLowerCase() == parentTagName.toLowerCase() )
				{
				return element;
				}
			else
				{
				return this.findParent(element.parentNode, parentTagName);
				}
			}
		}
	}
