$(function(){

	// Contact Tab Slider
	$("div#contact").css("marginTop", "-267px"); // Closes the content tab on page load - graceful degredation
	$("a.contact-tab").click(function(event){
		event.preventDefault();  // Remove the default anchor click event
        if ($("div#contact").is(".closed")){ // If the contact tab is closed...
            $("#contact").animate({	marginTop: "0px" } , 1000);
            $('#contact').removeClass('closed');
            $('input#name').focus();
        }
        else{ // If the contact tab is NOT closed...
            $("#contact").animate({ marginTop: "-267px" } , 1000);
            $('#contact').addClass('closed');
        }
    });
    
    // Form controls
    $(".error").hide();
    $(".button").click(function(){
    	// Field Validation Routines
    	// NAME FIELD
    	$(".error").hide();
    	var name = $("input#name").val();
    	if (name == "") {
    		$("label#name_error").show();
    		$("input#name").focus();
    		return false;
    	}
    	// EMAIL FIELD
    	$(".error").hide();
    	var email = $("input#email").val();
    	if (email == "") {
    		$("label#email_error").show();
    		$("input#email").focus();
    		return false;
    	}
    	// MESSAGE FIELD
    	$(".error").hide();
    	var message = $("textarea#message").val();
    	if (message == "") {
    		$("label#message_error").show();
    		$("textarea#message").focus();
    		return false;
    	}
    	
    	// Form Submission (AJAX)
    	var dataString = "name=" + name + "&email=" + email + "&message=" + message;
    	$.ajax({
    		type: "POST",
    		url: "assets/scripts/processform.php",
    		data: dataString,
    		success: function(){
    			$('#contact_form').html("<div id='sent_message'></div> ");
    			$('#sent_message').html("<h3>Your message has been sent, we will be in touch soon...</h3>")
    			.hide()
    			.fadeIn(1000);
    		}
    	});
    	$('#contact').delay(2000).animate({ marginTop: "-267px" } , 1000);
    	$('#contact').addClass('closed');
    	return false;
    }); 
		
});