/* javascript do menu */

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 = {"opportunity": "opportunity_link", "solution": "solution_link", "global-progress": "progress_link", "company": "company_link", "getinvolved" : "getinvolved_link", "news" : "company_link", "about" : "company_link", "contact" : "contact_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'));}
);


$("#country-select_2").hover(
function () {
var ele = $(this).find('ul:first');
if ( ele.hasClass("slidedown") == false )
{
ele.addClass("slidedown");
$(this).find('ul:first').slideDown("fast", function(){$(this).removeClass("slidedown")} );
}
}, 
function () 
{$(this).find('ul:first').slideUp("fast");}
);

AddHighlightMasthead();

});
