$(document).ready( function ()
{
	// Display PAGE FUNCTIONS
	$("#mailPrintFontTools").css("visibility","visible");

	// Setup Font-Size controls
	initFontSizeControls();
	
	// HOME PAGE - put rollover on home page puffs
	$("#puffs .puff").hover(
		function(){
			$(this).addClass("puffHover");
		},
		function(){
			$(this).removeClass("puffHover");								
		}
	); 
	
	// HOME PAGE - add click event to home page puff roll overs
	$("#puffs .puff").click(
		function() {
			document.location.href = $("a",this).attr("href");
		}
	);
		
	// LHS NAVIGATION - add functionality to make the whole nav item block clickable
	$("#left_frame dt").hover(
		function(){
			if ( $("a",this).size()  ) {
				$(this).addClass("hover");		
				$("a",this).addClass("hover");		
			}
		},
		function(){
			if ( $("a",this).size()  ) {
				$(this).removeClass("hover");		
				$("a",this).removeClass("hover");		
			}									
		}
	); 
	
	$("#left_frame dt").click(
		function(){

		 	if ( $("a",this).size()  && $("a",this).attr("href").search("http://") == -1) {
				document.location.href = $("a",this).attr("href");		
			}
		}
	);
	
	// SEARCH box - display default text, remove when input field has the focus
	// TOP LHS SEARCH BOX
	var cSEARCH_DEFAULT_TEXT = "";
	
	$("#searchFieldLeft").focus
	(
		function()
		{
		 	if ($(this).attr("value") == cSEARCH_DEFAULT_TEXT)
		 	{
				$(this).attr("value","");
			}
		}
	);
	
	$("#searchFieldLeft").blur
	(
		function()
		{
		 	if (!$(this).attr("value"))
		 	{
				$(this).attr("value",cSEARCH_DEFAULT_TEXT);
			}
		}
	);
	// RHS CONTENT SEARCH BOX
	$("#searchFieldRight").focus
	(
		function()
		{
		 	if ($(this).attr("value") == cSEARCH_DEFAULT_TEXT)
		 	{
				$(this).attr("value","");
			}
		}
	);
	
	$("#searchFieldRight").blur
	(
		function()
		{
		 	if (!$(this).attr("value"))
		 	{
				$(this).attr("value",cSEARCH_DEFAULT_TEXT);
			}
		}
	);
	
	// SEARCH paging buttons - add hover effect
	$(".SearchSummaryBottom .SearchSummaryBottomItem").hover(
		function(){
			if ( $("a",this).size()  ) {
				$(this).addClass("hover");		
				$("a",this).addClass("hover");		
			}
		},
		function(){
			if ( $("a",this).size()  ) {
				$(this).removeClass("hover");		
				$("a",this).removeClass("hover");		
			}									
		}
	); 
	
	// Make whole button clickable
	$(".SearchSummaryBottom .SearchSummaryBottomItem").click(
		function(){
		 	if ( $("a",this).size()  && $("a",this).attr("href").search("http://") == -1) {
				document.location.href = $("a",this).attr("href");		
			}
		}
	);
	
	// Remove UNDERLINE and ADD CURSOR = HAND on paging links if JQuery is active
	$(".SearchSummaryBottom .SearchSummaryBottomItem").css("cursor","pointer").css("text-decoration","none");
	// Remove CURSOR = HAND on currently selected page link
	$(".SearchSummaryBottom .selected").css("cursor","default");
	
	// FUNCTIONS
	function initFontSizeControls() {
		var maxFontSize = 140; // %
		var minFontSize = 80; // %
		function incrementFontSize(sizeDelta)
		{
			var newSize = parseFloat(GetCookie("font-size")) + sizeDelta;
			if (newSize > minFontSize && newSize < maxFontSize)
			{
				setBodyFontSize(newSize);
				SetCookie("font-size", newSize, {path: "/"});
			}
		}

		function setBodyFontSize(size)
		{
 			$("#main #right_frame #content").css("font-size", size + "%");
		}

		var fontSize = GetCookie("font-size");
		var fontIncrement = 8.33; // %
	 
		if (!fontSize)
		{
			SetCookie("font-size", "100", {path: "/"}); // set the default if there' no value
			fontSize = GetCookie("font-size"); // read it back to make sure cookies are supported
		}

		// check we can support this functionality
		if (window.print && fontSize)
		{
			// Display FONT controls
			$("#fontSizeDownControl").css("visibility","visible");
			$("#fontSizeUpControl").css("visibility","visible");
			setBodyFontSize(fontSize);
	 
			// attach font down handler
			$("#fontSizeDownControl").click(function()
			{
				incrementFontSize(-fontIncrement);
			});

			// attach font up handler
			$("#fontSizeUpControl").click(function()
			{
				incrementFontSize(fontIncrement);
			});

			// attach hover handler so we can style cursor with a hand on mouseover
			$("#font_size_button img").hover(
				function() { AddClass(this, "hover"); },
				function() { RemoveClass(this, "hover"); }
			);
		}
	}
});
