$(document).ready(function() {

	// Hide Loader & Other Stuff
	$('#loader').hide();
	$('#thankyou').hide();
	$('#in_filter').hide();
	
	// Setup Form2Email Options
	var options = {
		beforeSubmit: function() {
		$('#loader').fadeIn(50);
		},
		dataType: 'json',
		success: processJson		
	}
	
	// Form Functions
	function processJson(data) {
		var status = data.status;
		$('#loader').fadeOut(300);
				
		// If Fields are Empty
		if(status == 1) {$('#alert').append("<p>Vous devez completer toute l'information priee.</p>");}
		
		// If Name is Wrong
		if(status == 2) {$('#alert').append("<p>Votre nom doit etre entre 3 et 30 caracteres.</p>");}								
		
		// If Spam Bot
		if(status == 3) {$('#alert').append("<p>Leave the spam field blank please.</p>");}
		
		// If Fields are Empty
		if(status == 4) {$('#alert').append("<p>Votre email address etait inadmissible.</p>");}
		
		// If Probems
		if(status == 6) {$('#alert').append("<p>Il y avait un probleme envoyant la forme.</p>");}
		
		// If Message Sent
		if(status == 5) {			
			$('#contact-form form').hide(300);
			$('#alert').hide();		
			$('#thankyou').show(600);			
			$('#loader').fadeOut(500);
			return false;						
		}// End of Status 5
		
		$('#alert p').animate({opacity: 1.0}, 2000).slideUp(600);
		
	} 
	// End of processJson
	
	$('#contact-form form').ajaxForm(options);	

}); 