// ***************************
// *** PAGE LOAD FUNCTIONS ***
// ***************************
$(document).ready( function () {

	// **************************
	// START = FONT SIZE CONTROLS	
	// **************************
	var maxFontSize = 160; // %
	var minFontSize = 100; // %
	var fontSize = GetCookie("font-size");
	var fontIncrement = 8.33; // %

	// Grab Font Size from Cookie
	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
	}
	
	// Increase/Decrease font size
	function incrementFontSize(sizeDelta) {
		var newSize = parseFloat(GetCookie("font-size")) + sizeDelta;
		if (newSize > minFontSize && newSize < maxFontSize) {
			setBodyFontSize(newSize,true);
			SetCookie("font-size", newSize, {path: "/"});
		}
	}
	
	// ATTACH ON_CLICK HANDLERS	
	// attach font down handler
	$("#fontSizeDownControl").click(function() {
		incrementFontSize(-fontIncrement);
	});

	// attach font up handler
	$("#fontSizeUpControl").click(function() {
		incrementFontSize(fontIncrement);
	});
	
	// ************************
	// END = FONT SIZE CONTROLS	
	// ************************
	 
	 
	 
	// **********************
	// START - PAGE FUNCTIONS
	// **********************
	// Check if TOP NAV is being displayed?  If so, display page functions
	if ($("#top_menu").css("display") != "none"){
		$("#mail_print").css("display","block");
		$("#breadCrumbTrail").css("width","527px");
		if (fontSize){
			$("#content p").css("width", "auto");			
			$("#content").css("font-size", fontSize + "%");
			$("#font_size_button").css("display","block");
			$("#breadCrumbTrail").css("width","570px");
		}
	}
	// ********************
	// END - PAGE FUNCTIONS
	// ********************
	
	
	
	// **************************
	// START - PRIMARY NAVIGATION
	// **************************
	$("#main #top #navigation div").css("margin-top","-10px");
	$("a","#main #top #navigation div[class = selected]").click( function (){ return false;} );
	
	$("#main #top #navigation div").each( function () {
		if ( $(this).attr("class") != "selected" ) {
			$(this).bind("mouseover", function(){		
			
				$("img",this).attr("src","/interface/images/navigation/nav_" + $(this).attr("id") + "_o.gif");
				$(this).animate({ 
					marginTop: "0px"
					}, { queue:false, duration:400 } );
				
	
			});
		}
	});
	
	$("#main #top #navigation div").each( function () {
		if ( $(this).attr("class") != "selected" ) {
			$(this).bind("mouseout", function(){		
			
				$("img",this).attr("src","/interface/images/navigation/nav_" + $(this).attr("id") + ".gif");
				$(this).animate({ 
					marginTop: "-10px"
					}, { queue:false, duration:400 } );
				
	
			});
		}
	});
	
	// ************************
	// END - PRIMARY NAVIGATION
	// ************************


	
	// ******************************
	// START - SEARCH FIELD FUNCTIONS
	// ******************************
	var cDEFAULT_VALUE_SEARCH = "";
	
	// TOP RHS SEARCH
	// Check if Search field is empty. If so, populate with default text
	if ($("#frmSiteSearchTop input.field").attr("value") == "")
	{
		$("#frmSiteSearchTop input.field").attr("value", cDEFAULT_VALUE_SEARCH);
	}
	// FOCUS
	$("#frmSiteSearchTop input.field").focus
	(
		function()
		{
			if ($(this).attr("value") == cDEFAULT_VALUE_SEARCH)
			{
				$(this).attr("value","");
			}
		}
	);
	// BLUR
	$("#frmSiteSearchTop input.field").blur
	(
		function()
		{
			if ($(this).attr("value") == "")
			{
				$(this).attr("value", cDEFAULT_VALUE_SEARCH);
			}
		}
	);
	
	
	// BODY SEARCH
	// Check if Search field is empty. If so, populate with default text
	if ($("#frmSiteSearchBody input.field").attr("value") == "")
	{
		$("#frmSiteSearchBody input.field").attr("value", cDEFAULT_VALUE_SEARCH);
	}
	// FOCUS
	$("#frmSiteSearchBody input.field").focus
	(
		function()
		{
			if ($(this).attr("value") == cDEFAULT_VALUE_SEARCH)
			{
				$(this).attr("value","");
			}
		}
	);
	// BLUR
	$("#frmSiteSearchBody input.field").blur
	(
		function()
		{
			if ($(this).attr("value") == "")
			{
				$(this).attr("value", cDEFAULT_VALUE_SEARCH);
			}
		}
	);
	// ****************************
	// END - SEARCH FIELD FUNCTIONS
	// ****************************
	
	
	// *********************
	// START - SEARCH PAGING
	// *********************
	// 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");
	// *******************
	// END - SEARCH PAGING
	// *******************
});
