// Document Load Behaviours
$(document).ready(function()
{
	// Preload Main Menu Images
	$(".menu ul li").each(function(Index, Element)
	{
		// Load 'On' Image For This Item
		var Image_Loader = new Image();
		var String_Image = $(Element).find("img").attr("src").replace("-off", "-on");
		$(Image_Loader).load(function(){}).error(function(){}).attr("src", String_Image);
	});
	
	// Attach Main Menu Behaviour
	$(".menu ul li").hover(function()
	{
		// Highlight Menu Item
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace("-off", "-on"));
	},
	function()
	{
		// De-Highlight Menu Item
		$(this).find("img").attr("src", $(this).find("img").attr("src").replace("-on", "-off"));
	});



	// Attach Left Menu Behaviour
	$(".left .open ul li").hover(function()
	{
		// Open Sub Menu (Where Available)
		$(this).find("ul").css("display", "block");
	},
	function()
	{
		// Close Sub Menu
		$(this).find("ul").css("display", "none");
	});
	$(".left .current").hover(function()
	{
		// Open Sub Menu (Where Available)
		$(this).find("ul").css("display", "block");
	},
	function()
	{
		// Close Sub Menu
		$(this).find("ul").css("display", "none");
	});
	
	// Attach Hover Styling
	$(".left li").hover(function()
	{
		// Highlight Menu Item
		$(this).addClass("highlighted");
	},
	function()
	{
		// De-Highlight Menu Item
		$(this).removeClass("highlighted");
	});
	
	
	// Initially Hide Sub Menus
	$(".left ul").each(function(Index, Element)
	{
		var String_Parent = $(this).parent().get(0).tagName;
		var Boolean_Selected = $(this).parent().hasClass("open");

		if((String_Parent == "LI")&&(!Boolean_Selected))
		{
			$(this).css("display", "none");
		}
	});
	
	// Add Arrows To Indicate Sub Menu Availability
	$(".left ul li").each(function(Index, Element)
	{
		// Check For Sub Menu
		if($(this).find("ul").length > 0)
		{
			$(this).addClass("selected");
		}
	});
});