
Fridge = function(){};

Fridge.fbAsyncInit = function() {
  FB.init({
    appId  : Drupal.settings.fridge.client_id,
    xfbml : true
  });
};

/**
 * Drupal behaviors hook.
 *
 * Called when page is loaded, or content added via javascript.
 */
(function ($) {
  Drupal.behaviors.fridge = {
    attach : function(context) {
      if (typeof(FB) == 'undefined') {
        // No other modules have initialed Facebook's javascript, so we can.

        $('body').append('<div id="fb-root"></div>'); // Facebook recommends this tag.

        window.fbAsyncInit = Fridge.fbAsyncInit;

        // http://developers.facebook.com/docs/reference/javascript/
        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);

      }
      else {
        // Render any XFBML markup that may have been added by AJAX.
        $(context).each(function() {
          var elem = $(this).get(0);
          FB.XFBML.parse(elem);
        });
      }
    }
  };

})(jQuery);
;

