(function($){

var ns = "Delete";

window[ns] = function ( options ) {
  this.options = options;
  
  this.buttons = $(options.buttons);
  
  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 ) {
    event.preventDefault();
    var element = $(event.currentTarget);
    
    if ( element.hasClass('loading') ) return false;
    if ( ! window.confirm( LANG.deleteConfirm ) ) return;
    
    var url = element.attr('href');
    element.addClass('loading');
    
    $.ajax({
      url: url,
      success: function( data ){
        if ( data == "wall deleted" || data == "comment deleted" ) {
          element.parent().animate({opacity:0.0}, function() {
            $(this).slideUp();
          });
        } else if ( data == "image deleted" ) {
          element.parent().animate({opacity:0.0}, function() {
            $(this).slideUp();
          });
        }
      }
    });
  }
  
};

})(jQuery);
