// initialize the library with the API key
FB.init({ 
        apiKey: '814bb576c606fc0eb42d887c82c1b8af', 
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true });
        
FB.getLoginStatus(function(response) {
  if (response.session) {
    $j('#integrate_with_fb_btn').hide();
    $j('#connected_to_fb').show();
  }
});

$j('#integrate_with_fb_btn').bind('click', function() {
    FB.login(function(response){
        if(response.status == 'connected' && response.session.uid) {
            $j('#integrate_with_fb_btn').hide();
            $j('#connected_to_fb').show();           
        } else {
            return;
        }
    }, {
        perms:'email,publish_stream,offline_access'
    });
});


$j('#fb_login_image').bind('click', function() {
    FB.login(function(response){
        if(response.status == 'connected' && response.session.uid) {
            window.location = encodeURI('/facebook/fb_connect.php');       
        } else {
            return;
        }
    }, {
        perms:'email,publish_stream,offline_access'
    });
});

function fbLogout(){
    if(FB != undefined) {
        FB.logout(function(response){});
    } else {
        return true;
    }
}

FB.XFBML.parse();
