/* sub nav initialization to set selected class of current page link */

$(document).ready(function()
{
	var pathname = window.location.pathname;
	pathname = "/" + pathname.substr(1);

	if($("ul.subMenu"))
	{
		$("ul.subMenu li").each(function()
		{
			if($(this).children("a").attr("href") == pathname)
			{
				$(this).addClass("selected");
				if($(this).parent().css('display', 'none'))
				{
					$(this).parents(".subMenu").css('display', 'list-item');
					try
					{
						$(this).parents(".inner").css('display', 'list-item');
					}
					catch(e){}
				}
			}
		});
	}
});


/* ================================================================
This copyright notice must be untouched at all times.
Copyright (c) 2009 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */
$(document).ready(function()
{
	closetimer = 0;

	if($("#nav"))
	{
 		$("#nav li div").each(function(i)
		{
			eheight = $(this).height();
			$(this).children().css("top",-eheight+"px");
		});

		$("#nav li.nosub").mouseover(function()
		{
			eheight = $("#nav li.clicked").children("div").children().height()+20;
			$("#nav li.clicked").children("div").children().animate({"top": -eheight+"px"}, {queue:false,duration:(300)}, "swing");
			$("#nav li.clicked").children("div").slideUp(500);
			$("#nav li").removeClass("clicked");

			$(this).addClass("clicked");
		});

		$("#nav li.sub").mouseover(function()
		{
			clearTimeout(closetimer);

			/* moved on to next menu item, close all others */
			if(!$(this).hasClass("clicked"))
			{
				eheight = $("#nav li.clicked").children("div").children().height()+20;
				$("#nav li.clicked").children("div").children().animate({"top": -eheight+"px"}, {queue:false,duration:(300)}, "swing");
				$("#nav li.clicked").children("div").slideUp(500);
				$("#nav li").removeClass("clicked");
			}

			$(this).addClass("clicked");
			$(this).children("div").slideDown(100);
			eheight = $("#nav li.clicked").children("div").children().height();
			$(this).children("div").children().animate({"top":"0px"}, {queue:false,duration:(300)}, "swing");

		});

		$("#nav").mouseover(function()
		{
			clearTimeout(closetimer);
		});

		$("#nav").mouseout(function()
		{
			closetimer = window.setTimeout(function()
			{
				$("#nav li").each(function(i)
				{
					eheight = $(this).children("div").children().height()+20;
					$(this).children("div").children().animate({"top":-eheight+"px"}, {queue:false,duration:(300)}, "swing");
					$(this).children("div").slideUp(500);
					$(this).removeClass("clicked");
					});

			}, 2000);
		});
	}
});
