	$(document).ready(function() {
	
	//if submit button is clicked
	$('#submit').click(function () {		
		
		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var comment = $('textarea[name=comment]');
		
		//organize the data properly
		var data = 'name=' + name.val() + '&email=' + email.val() + '&comment='  + encodeURIComponent(comment.val());
		
		//disabled all the text fields
		$('.text').attr('disabled','true');
		
		//show the loading sign
		$('.loading').show();
		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "scripts/process.php",	
			
			//POST method is used
			type: "POST",

			//pass the data			
			data: data,	
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {		
				//if process.php returned 1/true (send mail success)
				if (html==1) {	
					$('input[name=name]').val("");
					$('input[name=email]').val("");
					$('textarea[name=comment]').val("");
					$('.done').fadeIn('slow');	
					$('.loading').fadeOut('slow');
					//hide the form
					$('.form').fadeOut('slow');					
					//show the success message
					$('.done').fadeIn('slow');	
				//if process.php returned 0/false (send mail failed)
				} else 
					$('input[name=name]').val("");
					$('input[name=email]').val("");
					$('textarea[name=comment]').val("");
					$('.done').fadeIn('slow');	
					$('.loading').fadeOut('slow');
					setTimeout(function(){ $(".done").fadeOut('slow') }, 3500);
			}		
		});
		
		//cancel the submit button default behaviours
		return false;
	});	
});	
