//Facebook Connect
function auth_using_fb() {
  //get the users data from FB
  var viewer  = FB.Facebook.apiClient.fql_query(
  
      'SELECT name, pic_square_with_logo,profile_url FROM user WHERE uid='+FB.Facebook.apiClient.get_session().uid,
      
      function(results) {
        update_userbox( results[0].name,
                        results[0].pic_square_with_logo,
                        results[0].profile_url,
                        'FB.Connect.logoutAndRedirect("http://www.capsittelle.com/' + logout_url + ' ");return false;')
      }
  );
}


//Generic updates #userbox with info retrieved
//from services
function update_userbox(name, image, url, logout) {

  //populate the data in #userbox and show it
  $('#userbox').html( "<a href='"+url+"'>"
                    + "<img alt='"+name+"' border='0' align='left' style='margin-right:5px;' src='"+image+"' /> </a><br>"
                    + "Bienvenue " + name + " ! (<a href='http://www.capsittelle.com/" + logout_url + "' onclick='" + logout + "'>logout</a>) <br />"
                    + "Vous êtes maintenant connecté avec votre compte Facebook." ).show();
  
  //hide name input and service
  //login buttons
  $('#userinfo').hide();
  
  
  //populate the values of the inputs
  //using data from serivce
  $('#pseudo').val(name);
  $('#url').val(url);
  $('#image').val(image);

}