(function($) {
  $.extend($.fn, {
    listSelect: function(options) {
      var defaults = {};
      options = $.extend(defaults, options);

      return this.each(function() {
        var select_all = $(this);
        var form = $(this).parents('form');
        var checkboxes = $(form).find(":checkbox").not($(this));
        var buttons = $(form).find("button");

        $(select_all).change(function(){
          toggle = $(this).attr("checked");
          $(checkboxes).each(function(){ $(this).attr("checked", toggle); });
          $(buttons).attr("disabled", !toggle);
        });

        $(checkboxes).change(function(){
          all_checked = true;
          disable_actions = true;
          $(checkboxes).each(function(){
            if (!$(this).attr("checked")) {
              all_checked = false;
            } else {
              disable_actions = false;
            }
          });
          $(select_all).attr("checked", all_checked);
          $(buttons).attr("disabled", disable_actions);
        });

      });
    }
  });
})(jQuery);