//search

function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}

var prevSearch = ""; 

function NUSearchKeyPress(e) {
    if ((e.keyCode || e.which) == 13) {
        NUSearch();
        return false;
    }
    return true;
} 

function NUSearch() {
    var searchString = "";
    
    //determine if it's from keystroke or click
    searchString = $("#searchBox").val();
    
    //search if we've got something to search on.
    if(searchString != null && searchString != "" && searchString != "Please enter search term") {
        window.location = "/search.aspx?searchtext=" + searchString;
    }
}

//cover our document.ready needs
$(document).ready(function() {

    //search box value clearing
    $("#searchBox").focus(function() {
        if(this.value == "Please enter search term") {
            this.value = "";
        }
    });

    $("#searchBox").blur(function() {
        if(this.value == "") {
            this.value = "Please enter search term";
        }
    });

    //IE6 menu hover
    if($.browser.msie && $.browser.version=="6.0") {
        sfHover = function() {
	        var sfEls = document.getElementById("mainNavigationMenu").getElementsByTagName("li");
	        for (var i=0; i<sfEls.length; i++) {
		        sfEls[i].onmouseover=function() {
			        this.className+=" sfhover";
		        }
		        sfEls[i].onmouseout=function() {
			        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		        }
	        }
        }
        if (window.attachEvent) window.attachEvent("onload", sfHover);
    }

    //mega menus
	function addMega() {
		$(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
		    (function($) {
		        jQuery.fn.calcSubWidth = function() {
		            rowWidth = 0;

		            $(this).find("ul").each(function() {
						
		                rowWidth += $(this).width();
		            });
		        };
		    })(jQuery);
		
		    if ( $(this).find(".row").length > 0 ) {
		        var biggestRow = 0;	

		        $(this).find(".row").each(function() {
		            $(this).calcSubWidth();

		            if(rowWidth > biggestRow) {
		                biggestRow = rowWidth;
		            }
		        });
		
		        $(this).find(".sub").css({'width' :biggestRow});
		        $(this).find(".row:last").css({'margin':'0'});
		    } else {
		        $(this).calcSubWidth();
		        $(this).find(".sub").css({'width' : rowWidth});
		    }
	}

	function removeMega() {
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
	      $(this).hide();
	  });
	}
	
	var megaConfig = {
         interval: 50,
         sensitivity: 4,
         over: addMega,
         timeout: 100,
         out: removeMega
    };

    $("li.mega").hoverIntent(megaConfig)
});

