var gHoverTimer;
var gCurrentHoverElement;

function OnHoverIn(lCurrentHoverElement)
{
	// If we are hovering into an element we are currently in, clear the hover out timer.
	if (( gCurrentHoverElement != 0 ) && (lCurrentHoverElement.hasClass("HoverTarget")))
	{
		gCurrentHoverElement.removeClass("HoverTarget");
		gCurrentHoverElement = 0;
		clearTimeout(gHoverTimer);
	}
	

	if ( lCurrentHoverElement.hasClass("slidedown") == false )
	{
		lCurrentHoverElement.addClass("slidedown");
		lCurrentHoverElement.slideDown("fast", function(){$(this).removeClass("slidedown")} );
	}
}

function HoverOut()
{
	gCurrentHoverElement.removeClass("HoverTarget");
	gCurrentHoverElement.slideUp("fast");
	gCurrentHoverElement = 0;
}

function OnHoverOut(lCurrentHoverElement)
{
	// If we are hovering out of a different element then is stored hide the old element
	if (( gCurrentHoverElement != 0 ) && (!lCurrentHoverElement.hasClass("HoverTarget")))
		HoverOut();
	
	// reset the timer
	clearTimeout(gHoverTimer);
	
	gCurrentHoverElement = lCurrentHoverElement;
	gCurrentHoverElement.addClass("HoverTarget");
	gHoverTimer = setTimeout(HoverOut, 100);	
}

function AddHighlightMasthead()
{
	var sectionToMasthead = {"about us": "about_link", "solution": "furniture_link", "global-progress": "planning_link", "company": "specialoffers_link", "contact" : "contactus_link" };

	var pathArray = window.location.pathname.split( '/' );
	
	if (sectionToMasthead[pathArray[1]] )
		$('#mainnav li#'+ sectionToMasthead[pathArray[1]] + ' a').addClass('activeSlideShow'); 
}

/***********************************************
*   
*    Document Ready
*
***********************************************/

$(document).ready(function()
{	
	gCurrentHoverElement  = 0;
	
	$('#mainnav').children().hover(
      function () 
      {OnHoverIn($(this).find('ul:first'));}, 
      function () 
      {OnHoverOut($(this).find('ul:first'));}
    );
	
			
   	
    
    AddHighlightMasthead();
    
});

/***********************************************
*   
*    END
*
***********************************************/

