/// <summary>The SiteMenu class adds the javascript logic for creating our nested flyout menus.
var SITEMENUTIMEOUT;
var SITEMENUTIMEOUTLENGTH = 250;
var MENUOPENTIMEOUT;
var MENUOPENTIMEOUTLENGTH = 750;
var currentMenuItem;

$(document).ready(function() {			
	$("li.parent ul").hide();
      
   	$("li > a").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		}
	);
    $("li.parent").hover(
		function () {		
			currentMenuItem = $(this);
			MENUOPENTIMEOUT = setTimeout("subSiteMenuOpen(currentMenuItem);", MENUOPENTIMEOUTLENGTH);
		}, 
		function () { return; }
    ); 

    $("div.menu-main").hover(
		function () { return; },
		function () {
			clearTimeout(MENUOPENTIMEOUT);
			SITEMENUTIMEOUT = setTimeout("subSiteMenuClose();", SITEMENUTIMEOUTLENGTH);
		}
    ); 
	
	activateCurrentPage();
	
	$("a.active").parents("ul").attr({
		style: "display:block;"
	});
	$("a.active").parents("li.parent").children("ul:first").attr({
		style: "display:block;"
	});	
		
}); 

function activateCurrentPage()
{
	var currentPage = getName(location + "");
	$("ul.level-one").find("a").each(function(i) {
		if ($(this).attr("href"))
		{
			var currentAnchorPage = getName($(this).attr("href"));
			if (currentAnchorPage == currentPage) $(this).addClass("active");
		}
	});
}
function getName(str)
{
	return (str.substring(str.lastIndexOf("/") + 1, str.lastIndexOf(".")));
}

function subSiteMenuOpen(menu)
{
	clearTimeout(SITEMENUTIMEOUT);
	menu.children("ul").slideDown("slow");
}
function subSiteMenuClose()
{
	clearTimeout(MENUOPENTIMEOUT);
	$(document).find("ul.level-three").each(function(i) {
		if ($(this).find("a.active").length == 0)
		{
			if ($(this).parent("li.parent").find("a.active").length == 0)
			{
				$(this).slideUp("slow");
			}
		}
	});
	$(document).find("ul.level-two").each(function(i) {
		if ($(this).find("a.active").length == 0)
		{
			//if ($(this).parents("li.parent").find("a.active").length == 0)
			//{
				$(this).slideUp("slow");
			//}
		}
	});	
} 