jQuery(function($){

    $('div.mailingList .error').hide();       

    $("div.mailingList input[name='submit']").bind("click", function(e){
        var $mailingList = $(this).parents("div.mailingList");
        vto.mailingList.submitForm($mailingList);
        e.preventDefault();
    });

});

vto.mailingList = {
    
    submitForm: function($form){
        var email = $form.find("input[name='email']").val();

        if (email == "") {
            $form.find("label#email_error").show();
            $form.find("input#email").focus();
            return false;
        }
        
         var dataString = '&email=' + email;
         $.ajax({
           type: "POST",
           url: "bin/mailinglist_form_submit.php",
           data: dataString,
           success: function() {
             $form.html("<div class='message'></div>");
             $form.find('.message').html("<h2>You're all signed up</h2>")
             .append("<p>We will be in touch with you at <strong>"+ email + "</strong>. Thanks again.</p>")
             .hide()
             .fadeIn('slow', function() {
              // $('#message').append("<img id='checkmark' src='images/check.png' />");
             });
           }
         });

    }
}
