jQuery.fn.ajaxSubmit = function(e) {
	jQuery(this).submit(function(){
		var params = {};
		$this = jQuery(this);
		$this.find("input[checked], input[type=text], input[type=hidden], input[type=password], input[type=submit], option[selected], textarea")
		.filter(":enabled")
		.each(function() {
			$me = jQuery(this);
			params[ $me.attr('name') || $me.attr('id') || $me.parent().attr('name') || $me.parent().attr('id') ] = $me.val();
		});
		jQuery('input[type=submit]', this).addClass('busy');
		
		jQuery.post('/index.html', params, function(data){
			jQuery('a[href=#contact]').click();
			setTimeout(function() {
				if (data=='SENT') {
					jQuery('#contact_form input[type=text], #contact_form textarea').val('');
					jQuery('#contact_form input[type=checkbox]').removeAttr('checked').parent().removeClass('checked').addClass('unchecked');
					jQuery('#message').html('Je bericht werd verzonden.<br>Wij zullen ons best doen om u zo snel mogelijk een antwoord te geven.')
					.colorBlend([{colorList:["#9ab336", "#222222"], param:"background-color", cycles:0.5, duration:3500}])
					.colorBlend([{colorList:["#222222", "#FFFFFF"], param:"color", cycles:0.5, duration:3500}]);
					jQuery('input[type=submit].busy').removeClass('busy');
					return;
				}
				
				jQuery('input[type=submit].busy').removeClass('busy');
				jQuery('#message').html(data)
				.colorBlend([{colorList:["#9ab336",  "#222222"], param:"background-color", cycles:0.5, duration:2000}])
				.colorBlend([{colorList:["#222222",  "#FFFFFF"], param:"color", cycles:0.5, duration:2000}]);
			}, 500);
		});
		return false;
	}).find('input[type=submit]').attr('name', 'send_ajax');
	
	return this;
}

jQuery(document).ready(function() {
	jQuery('#date').mask("99/99/9999 om 99u99");
	jQuery('form').ajaxSubmit();
});
