(function($){

var ns = "Like";

window[ns] = function ( options ) {
  this.options = options;
  
  this.area = $(options.area);
  this.buttons = this.area.find('a');
  
  this.observe();
}

window[ns].prototype = {
  
  observe: function () {
    this.buttons.click( $.proxy( this.click, this ) );
  },
  
  register: function ( button ) {
    button.click( $.proxy( this.click, this ) );
  },
  
  click: function ( event ) {
    var element = $(event.currentTarget);
    var href = element.attr('href');
    var $this = this;
    if ( element.hasClass('loading') ) return false;
    element.addClass('loading');
    
    element.parent().load( href, function () {
      $this.register($(this).find('a'));
    } );
    event.preventDefault();
  }
  
};

})(jQuery);
