$(document).ready(function() {
    $('.email_signup').click(function() {
        $('#email_popup a').unbind('click');
        $('#email_popup a').click(function() {

            var emailAddr = $('#popup_input').val();
            
            var valid = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            
            // rediculous email validation regex...sweet
            if (valid.test(emailAddr)) {
                $.post('/contact/constant', {email:emailAddr}, onConstantContactComplete, 'text');
            }
            
            return false;
        });
    });
});

function onConstantContactComplete(data)
{
    $('#email_popup input, #email_popup a').remove();
    $('#email_popup span').html("You email address was submitted successfully!");
    setTimeout(function() { $('#email_popup').remove(); }, 5000);
}