window.fbAsyncInit = function() {
    FB.init({appId: '225347e8ec24eee3cbb01866946ac648', status: true, cookie: true,
             xfbml: true});
    FB.Event.subscribe('auth.login', function(response) {
        FB.login(handleSessionResponse);
    });
    FB.getLoginStatus(function(response) {
      if (response.session) {
        $("#fb-loginbutton").fadeOut("fast");        
      } else {
        $("#fb-comments").fadeOut("fast");
      }
    });

    
};

function handleSessionResponse(response) {
    // if we dont have a session, just hide the user info
    if (!response.session) {
      clearDisplay();
      return;
    }

    // if we have a session, query for the user's profile picture and name
    FB.api(
      {
        method: 'fql.query',
        query: 'SELECT name, pic FROM profile WHERE id=' + FB.getSession().uid
      },
      function(response) {
        var user = response[0];
//        $('#user-info').html('<img src="' + user.pic + '">' + user.name).show('fast');
        $.post("fileadmin/template/fantasy967.de/scripts/facebook/fbfriends_proc.php", { "userid": FB.getSession().uid },
           function(data){
             $("#fb-loginbutton").fadeOut("fast");
             $("#fb-comments").fadeIn("fast");
           });
       }
    );
}

(function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/de_DE/all.js';
    document.getElementById('fb-root').appendChild(e);
}());

