jQuery(document).ready(function() {
	
    jQuery("#ajax-contact-form").submit(function() {
        jQuery('#load').append('<center><img src="http://www.idealservices.com/images/ajax-loader.gif" alt="Currently Loading" id="loading" /></center>');

        var fem = jQuery(this).serialize(),
			note = jQuery('#note');
	
        jQuery.ajax({
            type: "POST",
            url: "contact.php",
            data: fem,
            success: function(msg) {
				if ( note.height() ) {			
					note.slideUp(1000, function() { jQuery(this).hide(); });
				} 
				else note.hide();

				jQuery('#loading').fadeOut(300, function() {
					jQuery(this).remove();

					// Message Sent? Show the 'Thank You' message and hide the form
					result = (msg === 'OK') ? '<div class="success">Your message has been sent. Thank you!</div>' : msg;

					var i = setInterval(function() {
						if ( !note.is(':visible') ) {
							note.html(result).slideDown(1000);
							clearInterval(i);
						}
					}, 40);    
				}); // end loading image fadeOut
            }
        });

        return false;
    });
});
