(function(b){var a=b.treeview.classes,c=b.fn.treeview;b.fn.treeview=function(d){d=b.extend({},d);return d.add?this.trigger("add",[d.add]):d.remove?this.trigger("remove",[d.remove]):c.apply(this,arguments).bind("add",function(e,c){b(c).prev().removeClass(a.last).removeClass(a.lastCollapsable).removeClass(a.lastExpandable).find(">.hitarea").removeClass(a.lastCollapsableHitarea).removeClass(a.lastExpandableHitarea);b(c).find("li").andSelf().prepareBranches(d).applyClasses(d,b(this).data("toggler"))}).bind("remove",function(f,d){var e=b(d).prev(),c=b(d).parent();b(d).remove();e.filter(":last-child").addClass(a.last).filter("."+a.expandable).replaceClass(a.last,a.lastExpandable).end().find(">.hitarea").replaceClass(a.expandableHitarea,a.lastExpandableHitarea).end().filter("."+a.collapsable).replaceClass(a.last,a.lastCollapsable).end().find(">.hitarea").replaceClass(a.collapsableHitarea,a.lastCollapsableHitarea);if(c.is(":not(:has(>))")&&c[0]!=this){c.parent().removeClass(a.collapsable).removeClass(a.expandable);c.siblings(".hitarea").andSelf().remove()}})}})(jQuery)