/* attach a submit handler to the form */
$("#mailForm").submit(function (event) {

    $("button.signup_button").addClass("signup_button_busy").removeClass("signup_button");
    /* stop form from submitting normally */
    event.preventDefault();

    /* get some values from elements on the page: */
    var data = { "email":$(this).find('input[name="mailField"]').val(), "type":"form" };
    var dataString = JSON.stringify(data);

    $.post('addToList.php', { data:dataString}, function (res) {
        $("button.signup_button_busy").addClass("signup_button").removeClass("signup_button_busy");
        var obj = $.parseJSON(res);
        if (obj.success) {
            document.getElementById('preRegister').style.display = "none";
            document.getElementById('postRegister').style.display = "block";
            log('Successfully transmitted mail...');
        }
        else {
            log('Problem transmitting mail...');
        }
    });
});

loginFB = function () {
    $("a.facebook_button").addClass("facebook_button_busy").removeClass("facebook_button");

    FB.login(function (response) {
        if (response.authResponse) {
            register_FBMail();

            log('Welcome!  Fetching your information.... ');
        } else {
            log('User cancelled login or did not fully authorize.');
            $("a.facebook_button_busy").addClass("facebook_button").removeClass("facebook_button_busy");
        }

    }, {scope:'email'});
};


alreadyRegistered = function () {
    //do something if user is already logged in with Facebook
};


register_FBMail = function () {
    FB.api('/me', function (response) {
        var data = { "id":response.id, "type":"fb" };
        var dataString = JSON.stringify(data);
        $.post('addToList.php', { data:dataString}, function (res) {
            $("a.facebook_button_busy").addClass("facebook_button").removeClass("facebook_button_busy");
            var obj = $.parseJSON(res);
            if (obj.success) {
                document.getElementById('preRegister').style.display = "none";
                document.getElementById('postRegister').style.display = "block";
                log('Successfully transmitted mail...');
            }
            else {
                log('Problem transmitting mail...');
            }


        });

    });
};

function logout() {
    document.getElementById('login').style.display = "none";
}

$(document).ready(function () {
    //  $('a.lightbox').colorbox({inline:true, href:"#lightbox_about", html:"<p>Hello</p>"});
    $('a.lightbox').colorbox({maxWidth:940, html:function () {
        return $('#lightbox_about').html();
    }});


});







