$(document).ready(function() {
	
	$("#subForm input#join").click(function() {	
		
		// First, disable the form from submitting
		$('form#subForm').submit(function() { return false; });
		
		// Grab form action
		formAction = $("form#subForm").attr("action");
		
	
		
		// Serialize form values to be submitted with POST
		var str = $("form#subForm").serialize();
		
		// Add form action to end of serialized data
		final = str + "&action=" + formAction;
		
		// Submit the form via ajax
		$.ajax({
			url: "/js/proxy.php",
			type: "POST",
			data: final,
			success: function(data){
				//Check to make sure that the email was accepted
				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
				{
					$("div#subscribe").hide(); // If successfully submitted hides the form
					$("p#success-message").fadeIn("fast");  // Shows "Thanks for subscribing" div
				}
			}
		});
	});
	
	// Homepage slideshow
	$('div#first').cycle({ timeout: 4000 });
	$('div#second').cycle({ timeout: 4000, delay: 1000 });
	$('div#third').cycle({ timeout: 4000, delay: 2000 });
	
	// Cross Broswer nth-child selectors
	$('div.news-article:first').css('border-top', 'none');
});