/* Author: 

*/

$(document).ready(function() {

  
	// AJAX FORM
	$("#ajax-news-form").submit(function() {
      $('#load').append('<img src="img/ajax-loader.gif" alt="Enviando datos" id="loading" />');

      var fem = $(this).serialize(),
		note = $('#note');

      $.ajax({
          type: "POST",
          url: "news.php",
          data: fem,
          success: function(msg) {
			if ( note.height() ) {			
				note.slideUp(1000, function() { $(this).hide(); });
			} 
			else note.hide();

			$('#loading').fadeOut(300, function() {
				$(this).remove();

				// Message Sent? Show the 'Thank You' message and hide the form
				result = (msg === 'OK') ? '<div class="success">Gracias por suscribirte a nuestro news!</div>' : msg;

				var i = setInterval(function() {
					if ( !note.is(':visible') ) {
						note.html(result).slideDown(1000);
						clearInterval(i);
					}
				}, 40);    
			}); // end loading image fadeOut
          }
      });

      return false;
      
  });
  	//END

});
