$(document).ready(function(){
	
	var isOpen = true;
	
	$("#xxcontent-top").click(function(){
		
		if (isOpen) {
			
			isOpen = true;
			
			$("#xxcontent-bottom").animate({
			    marginTop: 0
			  }, 500, function() {
		
			    // Animation complete.
				
			  });
			
		} else {
			
			isOpen = true;
			
			$("#xxcontent-bottom").animate({
			    marginTop: 100
			  }, 500, function() {
		
			    // Animation complete.
				
			  });
		}
		
	});
	
});


$(document).ready(function(){
	
	$("form#new").submit(submitNewEntry);
});

function submitNewEntry(){
	
	// disable the submit button
	$('input[type=submit]', this).attr('disabled', 'disabled');
	$('input[type=text]', this).attr('readonly', 'readonly');
	
	
	// Roll up all values into a string
	var values = $('form#new').serialize();
	
	
	if (values == "" || $("form#new [name=email]").val() == "") {
		
		alert("The form needs to be filled in");
		
		return;
	}
	
	console.log(values);
	
	$.ajax({  
	  type: "POST",
	  url: "/includes/ajax.php",
	  data:values,
	  success: function(data) {
		
		// enable the submit button
		$('input[type=submit]').removeAttr('disabled');
		$('input[type=text]').removeAttr('readonly');
		
		if (data != null) {
			data = jQuery.parseJSON(data);
        	
        	// result was successful
        	if (data.result == true) {
				
				$("#contactForm").fadeOut(800, function(){
					$("#success").fadeIn(800);
				});
				
				// clear the form
				$("form#new")[0].reset();
			}
		}
		}
	
	});
	
	return false;
}

