// Array holding all the dropdown menus
var ids = new Array("products_dd", "technology_dd", "customers_dd", "services_dd", "partners_dd", "resources_dd");

// Drop down properties
var timeout	= 50;
var closetimer	= 0;
var ddmenuitem	= 0;

// Current navigation item holder
var navItem = '';

// Set a timer to hide the dropdown menu
	function closeTime()
	{
		closetimer = window.setTimeout(hideDD, timeout);
	}

// Show the correct dropdown menu
	function showDD(id)
	{
		// Cancel the timer
		cancelTimer();
		// Hide all other drop
		hideDD();
		
		// Remove the string "_dd" from the passed id
		navItem = id.split("_dd");
		navItem = 'nav-' + navItem[0];

		// Activate the current navigation item.
		// Keeps the hover state of the navigation item while on its dropdown menu
		$("#" + navItem).addClass('dd_open');
		
		// Show the dropdown menu according to the id passed
		$("#" + id).addClass('dropdown clearfix show');

		//set the left position of the drop-down menu to start at the left position of the parent/calling element
		//Added 4px to account for margins/padding.
		$("#" + id).css('left', $("#" + navItem).offset().left - $("#" + navItem).parent().offset().left + 4);

	}
	
// Hiding the dropdown menu
	function hideDD()
	{		
		// Remove the "dd_open" class off the current navigation item
		if (navItem != "")
		{
			var nav = document.getElementById(navItem);
			nav.className = '';
		}
		
		// Hide all dropdown menus
		for (i = 0; i < ids.length; i++)
		{
			var elem = document.getElementById(ids[i]);
			elem.className = 'dropdown clearfix hide';
		}
	}
	
// Cancel Timer
	function cancelTimer()
	{
		if(closetimer)
		{
			window.clearTimeout(closetimer);
			closetimer = null;
		}
	}

// Close layer when click-out
document.onclick = closeTime;
