
/* main.js */

$(document).ready(function() {
  $('#email_address').focus(function() {
    $(this).val('');
  });

  $('#submit_email').click(function(e) {
    e.preventDefault();
  	$(this).attr("disabled", "disabled").fadeOut();
  	var body =  "Email: " + $('#email_address').val() + "";
  	$('#email_address').attr("disabled", "disabled");
  	send_mail( "Newsletter Signup", body,
  		function(mail, status) {
  			if (mail.is_sent) {
  				$('#email_address').effect("highlight",{},1500).val('Mail sent successfully.').css({color: 'green'});
  			}
  		}
  	);


  });

  var send_mail = function(subject, body, callback) {
  	$.getJSON('mailer/index.php?subject='+encodeURIComponent(subject)+'&body='+encodeURIComponent(body)+'',function(mail, status) {
  		if (typeof(callback)=='function' && callback != null) {
  			callback(mail, status);
  		}
  	});
  };  
});

