var rootURL = "http://" + document.location.hostname;

$(document).ready(function () {

    window.fbAsyncInit = function () {
        FB.init({ appId: appId, status: true, cookie: true,
            xfbml: true
        });

        FB.Event.subscribe('auth.login', function (response) {
            jQuery.ajax({
                url: rootURL + '/Server/Login',
                success: function (data) {
                    window.location = rootURL + data;
                }
            });
        });

        FB.Event.subscribe('auth.logout', function (response) {
            jQuery.ajax({
                url: rootURL + '/Server/Logout',
                success: function (data) {
                    window.location = rootURL + data;
                }
            });
        });
    };

    (function () {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/nl_NL/all.js';
        document.getElementById('fb-root').appendChild(e);
    } ());


});
