// Create jQuery function initSearchField to handle explanatory default text in search text fields
jQuery.fn.initSearchField = function() {
	return this.each(function() { // Return the original jQuery object
		var target = $(this);
		// First, check that the node is a text field
		if (target.get(0).nodeName.toLowerCase() == "input" && target.attr("type").toLowerCase() == "text") {
			if (typeof(target.data("search_text")) == "undefined") {
				// Save the original text
				target.data("search_text", target.val());
			}
			target.focus(function() {
				if (target.val() == target.data("search_text")) {
					// On focus, blank out text field if it contains the default text
					target.val("");
					// Add class to text field that can be styled if desired
					target.addClass("search-focus");
				}
			});
			target.blur(function() {
				if (target.val() == "") {
					// On blur, restore default text if field is left blank
					target.val(target.data("search_text"));
					// Remove the styling class
					target.removeClass("search-focus");
				}
			});
		}
	});
};

// Initiate all search fields on the page
$(".search-field").initSearchField();

// Set all print links to use javascript
$(".print-link").click(function(e) {
    e.preventDefault();
    window.print();
});

// Fix active menu link for article pages
var baseHref = $("#breadcrumbs > li:eq(1) > a").attr("href").toLowerCase();
if (document.location.href.toLowerCase().indexOf(baseHref) == -1) {
    // If the breadcrumb trail indicates a different location than the current page, set the active flag
    // in the menus to reflect what's in the breadcrumbs
    $("#header-nav > ul > li")
        .removeClass("active")
        .filter(":has(a[href*=" + baseHref + "])")
        .addClass("active");
}