$(document).ready(function(){

	slideTopNavDD('appsNav');
	slideTopNavDD('aboutNav');
	
	clearDefault('clearDefault');
	
	
$(function() {
	$("#emailForm button").click(function() {
		$('form#emailForm').submit(function() { return false; });
		formAction = $("form#emailForm").attr("action");
		emailID = "#tjljhr-tjljhr";
		if (!checkEmail(emailID)) {
			alert("Please enter a valid email address.");
			return;
		}
		var str = $("form#emailForm").serialize();
		final = str + "&action=" + formAction;
		$.ajax({
			url: "/wordpress/happytapper/wp-content/themes/happytapper/proxy.php",
			type: "POST",
			data: final,
			success: function(data) {
								// Server-side validation
					if (data.search(/invalid/i) != -1) {
						alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
					}
					else
					{
						$("#emailForm").hide(); // If successfully submitted hides the form
						$("#confirmation").slideDown("slow"); // Shows "Thanks for subscribing" div
					}
				}
		});
	});
});

	
});


function checkEmail(email) {
	var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var emailVal = $(email).val();
	return pattern.test(emailVal);
} 

// Clear the default value of an input item when clicked on
function clearDefault(defaultClass)
{
	$('.'+defaultClass).each(function() {
		var default_value = this.value;
		
		$(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
			}
		});
		
		$(this).blur(function() {
			if(this.value == '') {
				this.value = default_value;
			}
		});
	});
}

// Drop down the secondary navigation when clicking on a specific item.  Also slide up the other items before doing that.
function slideTopNavDD(navName)
{
	$('a.'+navName).click(function() {
	var _this = this;
	if ($('#'+navName+':visible').length == 0) {
		$('.navDDWrapper').each(function(){
			if($(this).is(':visible'))
			{
				$(this).hide("slide", { direction: "up" });
			}
		});
		$('.topNav ul li').each(function(){
			$(this).removeClass('selected');
		});
		$('#'+navName).show("slide", { direction: "up" });
		$(_this).parent().addClass('selected');
	} else {
		$('#'+navName).hide("slide", { direction: "up" });
		$(_this).parent().removeClass('selected');
	}
	return false;
	}); 

}