$(function () {
	primaryNavDropDowns();
	newsletterEmailAddressField();
});

// Handles the showing and hiding of drop-downs when relevant links are hovered upon in the primary nav.
function primaryNavDropDowns() {

	// get primary nav links (immediate <a>s of immediate <li>s, thus ignoring links in drop-downs) and iterate over them.
	var primaryNavLinks = $('#primaryNav > ul > li > a');
	primaryNavLinks.each(function (i) {

		// if this link doesn't have a corresponding drop-down, return.
		if (!$(this).attr('data-has-drop-down')) return;

		// get reference to parent <li>, whose area will include both the link and its drop-down.
		var li = $(this).parent();

		li.hover(
			
			// on mouseover, get <ul> (drop-down) and show it.
			function () {
				$('ul', $(this)).show();
			},

			// on mouseout, get <ul> and hide it.
			function () {
				$('ul', $(this)).hide();
			});
	});
}

// Handles the showing and hiding of default values in the newsletter email address field.
function newsletterEmailAddressField() {

	// get email address field and its default value.
	var emailAddressField = $('#inputNewsletterEmailAddress');
	var defaultValue = emailAddressField.attr('data-default-value');

	// if, on focus, the field's value is its default value, clear it.
	emailAddressField.focus(function (e) {
		if ($(this).val() == defaultValue) $(this).val('');
	});

	// if, on blur, the field contains no value of worth, reinstate default value.
	emailAddressField.blur(function (e) {
		if (!$(this).val().match(/[a-z0-9]/gi)) $(this).val(defaultValue);
	})
}
