$(document).ready(function(){
	$('#contactform').submit(function(){
		action = $(this).attr('action');
		
		$('#submit').after('<img src="img/loading.gif" class="loading">')
					.attr('disabled','disabled');

		$("input,textarea").removeClass("error");

		$.post(action,$("#contactform").serialize(),function(data){
			if(data=='Ok') {
				$('#contactform').slideUp(600,function(){
					$(".success").fadeIn(600)
				});
			} else if(data=='Error_1') {
				$('input#name').animate({opacity:"0"},200).addClass("error").animate({opacity:"1"},200).animate({opacity:"0"},200).animate({opacity:"1"},200);
			} else if(data=='Error_2') {
				$('input#email').animate({opacity:"0"},200).addClass("error").animate({opacity:"1"},200).animate({opacity:"0"},200).animate({opacity:"1"},200);
			} else if(data=='Error_3') {
				$('input#title').animate({opacity:"0"},200).addClass("error").animate({opacity:"1"},200).animate({opacity:"0"},200).animate({opacity:"1"},200);
			} else if(data=='Error_4') {
				$('textarea#message').animate({opacity:"0"},200).addClass("error").animate({opacity:"1"},200).animate({opacity:"0"},200).animate({opacity:"1"},200);
			}
			$('#contactform #submit').attr('disabled','');
			$('#contactform img.loading').fadeOut(500,function(){$(this).remove()});
		});

	return false;
	});
});

