var EZLogin = {
    FB_APP_ID: "211250705575033"
};

EZLogin.initFB = function() {
    // app id
    if(location.hostname == "zac.eztable.com.tw") {
        EZLogin.FB_APP_ID = "123013947760541";
    } else if(location.hostname == "localhost") {
        if(location.host == "localhost:8888") {
            EZLogin.FB_APP_ID = "139500256120282";
        } else if(location.host == "localhost:8889") {
            EZLogin.FB_APP_ID = "208509142516135";
        } else {
            EZLogin.FB_APP_ID = "139500256120282";
        }
    }
    // load script
    window.fbAsyncInit = function() {
        FB.init({
          appId: EZLogin.FB_APP_ID, 
          cookie: true, 
          xfbml: true,
          oauth: true
        });
    };
    (function() {
        var e = document.createElement('script');
        e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
};

EZLogin.loginFacebook = function(config) {
    FB.login(function(response) {
        if (response.authResponse) {
            // call ajax login
            $.ajax({
                type: "POST",
                url: './ajax/kernel/ezlogin_by_facebook.php',
                dataType: 'json',
                data: config.params,
                success: config.success
            }); 
        } else {
            config.fail();
        }
    }, {scope: 'user_birthday,email,offline_access,publish_stream'});
};

$(document).ready(function() {
    EZLogin.initFB();
});

