// Document Load Behaviours
$(document).ready(function()
{
	// Image Replacement
	$(".lower .content h1").each(function(Index, Element)
	{
		// Debugging Information
		// console.log($(this).text());
		// console.log($(this).parent().parent().parent().attr("class"));
		
		// Check Page Class
		var Array_Classes = $(this).parent().parent().parent().attr("class").split(" ", 2);
		var String_Class = Array_Classes[1];
		
		// Other Variables
		var String_Title = $(this).text();
		var String_Image = "";
		
		// Determine Image File Name
		String_Image = String_Title.toLowerCase();
		String_Image = String_Image.replace(/ /g, "");
		String_Image = String_Image.replace(/&/g, "and");
		String_Image = "titles/title_" + String_Class + "_" + String_Image + ".gif";
		
		// Load Image
		var Image_Title = new Image();
		$(Image_Title).load(function()
		{
			// Image Found, Replace Element
			$(Element).replaceWith('<img src="' + String_Image + '" alt="' + String_Title + '" class="FSAlbert" />');
			
		}).error(function()
		{
			// Image Missing, Ignore Title
		}).attr("src", String_Image);
	});

	// Attach Main Menu Behaviour
	$(".menu ul").hover(function()
	{
		// Highlight Section Title
		if($(this).find("li:first").contents().find("img").attr("src") != undefined)
		{
			$(this).contents().find("img").attr("src", $(this).find("li:first").contents().find("img").attr("src").replace("_off", "_on"));
		}
	},
	function()
	{
		// De-ighlight Section Title
		if($(this).find("li:first").contents().find("img").attr("src") != undefined)
		{
			$(this).contents().find("img").attr("src", $(this).find("li:first").contents().find("img").attr("src").replace("_on", "_off"));
		}
	});
	
	// Attach Child Menu Behaviour
	$(".menu ul ul li").hover(function()
	{
		// Check Page Class
		var Array_Classes = $(this).parent().parent().parent().parent().parent().attr("class").split(" ", 2);
		var String_Class = Array_Classes[1];
		
		// Highlight Link
		$(this).css("background-image", "url(images/arrow_" + String_Class + "_small.gif)");
	},
	function()
	{
		// Get Page Name And Link Target
		var String_Page = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
		var String_Link = $(this).contents().attr("href");

		// Compare
		if(String_Page != String_Link)
		{
			// De-Highlight Link
			$(this).css("background-image", "");
		}		
	});
	
	// Highlight Current Page
	$(".menu ul ul li").each(function()
	{
		// Check Page Class
		var Array_Classes = $(this).parent().parent().parent().parent().parent().attr("class").split(" ", 2);
		var String_Class = Array_Classes[1];
		
		// Get Page Name And Link Target
		var String_Page = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
		var String_Link = $(this).contents().attr("href");
		
		// Compare
		if(String_Page == String_Link)
		{
			$(this).css("background-image", "url(images/arrow_" + String_Class + "_small.gif)");
		}
	});

	// Attach Range Menu Behaviour
	$(".range img").hover(function()
	{
		// Highlight Range Title
		if($(this).attr("src") != undefined)
		{
			$(this).attr("src", $(this).attr("src").replace("_off", "_on"));
		}
	},
	function()
	{
		// Get Page Name And Link Target
		var String_Page = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
		var String_Link = $(this).parent().attr("href");

		// Compare
		if(String_Page != String_Link)
		{
			$(this).attr("src", $(this).attr("src").replace("_on", "_off"));
		}
	});
	
	// Highlight Current Range
	$(".range img").each(function()
	{
		// Get Page Name And Link Target
		var String_Page = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
		var String_Link = $(this).parent().attr("href");

		// Compare (Accounting For Product Pages)
		if((String_Page == String_Link)||(String_Page.replace("-product.php", ".php") == String_Link))
		{
			$(this).attr("src", $(this).attr("src").replace("_off", "_on"));
		}
	});

	// Attach Tab Behaviour
	$(".tideford .tab").css("cursor", "pointer");
	$(".tideford .tab").click(function()
	{ 
		document.location = 'own-label-food-services.php';
	});
});
