(function(c){function b(h,g,i,f){function d(j){function k(m){var n=c("<li/>").attr("id",this.id||"").html("<span>"+this.text+"</span>").appendTo(m);if(this.classes){n.children("span").addClass(this.classes)}if(this.expanded){n.addClass("open")}else{n.addClass("closed")}if(this.hasChildren||this.children&&this.children.length){var l=c("<ul/>").appendTo(n);if(this.hasChildren){n.addClass("hasChildren");k.call({classes:"placeholder",text:"&nbsp;",children:[]},l)}if(this.children&&this.children.length){c.each(this.children,k,[l])}}}i.empty();c.each(j,k,[i]);c(f).treeview({add:i})}if(h.data===undefined){c.getJSON(h.url,{root:g},d)}else{var e=c.extend({root:g},h.data);c.ajax({url:h.url,dataType:"json",type:"POST",data:e,success:d})}}var a=c.fn.treeview;c.fn.treeview=function(f){if(!f.url){return a.apply(this,arguments)}var d=this;if(!d.children().size()){b(f,f.root||"source",this,d)}var e=f.toggle;return a.call(this,c.extend({},f,{collapsed:true,toggle:function(){var h=c(this);if(h.hasClass("hasChildren")){var g=h.removeClass("hasChildren").find("ul");b(f,this.id,g,d)}if(e){e.apply(this,arguments)}}}))}})(jQuery);