

$(document).ready(function(){

	//cufon
	Cufon.replace('h1,h2,h3',
		{
		hover: true
		}
	)

	//gallery lightbox
	$("#gallery a").fancybox();

	//hide the ajax confirmation
	$("#processing").hide();
	
	//ajax subscribe
	$("#quikemail input:submit").click(function() {	
		
		// First, disable the form from submitting
		$('form#quikemail').submit(function() { return false; });
		
		// Grab form action
		formAction = $("form#quikemail").attr("action");
		
		// Hacking together id for email field
		// Replace the xxxxx below:
		// If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
		emailId = "tuydkj";
		emailId = emailId.replace("/", "");
		emailId = emailId + "-" + emailId;
		emailIdhash ="#" + emailId;
		
		// Validate email address with regex
		if (!checkEmail(emailId)) 
		{
			alert("Please enter a valid email address");
			return;
		}
		
		// Serialize form values to be submitted with POST
		var str = $("form#quikemail").serialize();
		
		// Add form action to end of serialized data
		final = str + "&action=" + formAction;
		
		//add the spinner
		$("#processing").addClass("processing").append("Processing...").show();
		
		// Submit the form via ajax
		$.ajax({
			url: "/assets/scripts/proxy.php",
			type: "POST",
			data: final,
			success: function(html){
				$("#processing").removeClass("processing").addClass("subscribed").text("").append("Thanks for subscribing.");  // Shows "Thanks for subscribing" div
				$(emailIdhash).val("");
			}
		});
	});

});

//ajax email validate
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);
}