/*
 * Ensure Facebook app is initialized and call callback afterward
 *
 */
function fb_connect_ensure(callback) {
  if(window.is_initialized) {
    callback();
  } else {
    FB_RequireFeatures(["XFBML", "CanvasUtil"], function() {
        FB.FBDebug.logLevel = 4;
        FB.FBDebug.isEnabled = true;
        // xd_receiver.php is a relative path here, because The Run Around
        // could be installed in a subdirectory
        // you should prefer an absolute URL (like "/xd_receiver.php") for more accuracy
        //FB.Facebook.init('d99e3c48d2424951bff65e76e379c725', '/connect/xd_receiver.htm'); /*dev*/
		FB.Facebook.init('6a9fa6ba83a00118b4dcdfe9e7368df3', '/connect/xd_receiver.htm');

        window.is_initialized = true;
        callback();
      });
  }
}

function fb_connect_ping_auth(return_to,fave_it) {
  fb_connect_ensure(function(){
    var auth_url = '/connect/authenticate';
    if (return_to && fave_it) auth_url = auth_url + '?return=' + escape(return_to) + '&fave_it=' + String(fave_it);
	else if (return_to) auth_url = auth_url + '?return=' + escape(return_to);
	else if (fave_it) auth_url = auth_url + '?fave_it=' + String(fave_it);
    FB.Connect.ifUserConnected(auth_url, null); 
  });
}

