(function(c){c.extend(c.fn,{swapClass:function(a,d){var f=this.filter("."+a);this.filter("."+d).removeClass(d).addClass(a);f.removeClass(a).addClass(d);return this},replaceClass:function(a,d){return this.filter("."+a).removeClass(a).addClass(d).end()},hoverClass:function(a){a=a||"hover";return this.hover(function(){c(this).addClass(a)},function(){c(this).removeClass(a)})},heightToggle:function(a,d){a?this.animate({height:"toggle"},a,d):this.each(function(){jQuery(this)[jQuery(this).is(":hidden")?
"show":"hide"]();d&&d.apply(this,arguments)})},heightHide:function(a,d){if(a)this.animate({height:"hide"},a,d);else{this.hide();d&&this.each(d)}},prepareBranches:function(a){if(!a.prerendered){this.filter(":last-child:not(ul)").addClass(b.last);this.filter((a.collapsed?"":"."+b.closed)+":not(."+b.open+")").find(">ul").hide()}this.find("span").hoverClass();return this.filter(":has(>ul)")},repareBranches:function(a){var d={collapsed:true};a&&this.hide();this.find("li").prepareBranches(d).applyClasses(d,
function(){c(this).parent().find(">.hitarea").swapClass(b.collapsableHitarea,b.expandableHitarea).swapClass(b.lastCollapsableHitarea,b.lastExpandableHitarea).end().swapClass(b.collapsable,b.expandable).swapClass(b.lastCollapsable,b.lastExpandable).find(">ul").heightToggle(d.animated,d.toggle)})},applyClasses:function(a,d){this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(){d.apply(c(this).next())});if(!a.prerendered){this.filter(":has(>ul:hidden)").addClass(b.expandable).replaceClass(b.last,
b.lastExpandable);this.not(":has(>ul:hidden)").addClass(b.collapsable).replaceClass(b.last,b.lastCollapsable);this.prepend('<div class="'+b.hitarea+'"/>').find("div."+b.hitarea).each(function(){var f="";c.each(c(this).parent().attr("class").split(" "),function(){f+=this+"-hitarea "});c(this).addClass(f)})}this.find("div."+b.hitarea).click(d)},treeview:function(a){function d(g,e){function h(i){return function(){f.apply(c("div."+b.hitarea,g).filter(function(){return i?c(this).parent("."+i).length:true}));
return false}}c("a:eq(0)",e).click(h(b.collapsable));c("a:eq(1)",e).click(h(b.expandable));c("a:eq(2)",e).click(h())}function f(){c(this).parent().find(">.hitarea").swapClass(b.collapsableHitarea,b.expandableHitarea).swapClass(b.lastCollapsableHitarea,b.lastExpandableHitarea).end().swapClass(b.collapsable,b.expandable).swapClass(b.lastCollapsable,b.lastExpandable).find(">ul").heightToggle(a.animated,a.toggle);a.unique&&c(this).parent().siblings().find(">.hitarea").replaceClass(b.collapsableHitarea,
b.expandableHitarea).replaceClass(b.lastCollapsableHitarea,b.lastExpandableHitarea).end().replaceClass(b.collapsable,b.expandable).replaceClass(b.lastCollapsable,b.lastExpandable).find(">ul").heightHide(a.animated,a.toggle)}function m(){var g=[];j.each(function(e,h){g[e]=c(h).is(":has(>ul:visible)")?1:0});c.cookie(a.cookieId,g.join(""))}function n(){var g=c.cookie(a.cookieId);if(g){var e=g.split("");j.each(function(h,i){c(i).find(">ul")[parseInt(e[h])?"show":"hide"]()})}}a=c.extend({cookieId:"treeview"},
a);if(a.add)return this.trigger("add",[a.add]);if(a.toggle){var o=a.toggle;a.toggle=function(){return o.apply(c(this).parent()[0],arguments)}}this.addClass("treeview");var j=this.find("li").prepareBranches(a);switch(a.persist){case "cookie":var l=a.toggle;a.toggle=function(){m();l&&l.apply(this,arguments)};n();break;case "location":var k=this.find("a").filter(function(){return this.href.toLowerCase()==location.href.toLowerCase()});k.length&&k.addClass("selected").parents("ul, li").add(k.next()).show();
break}j.applyClasses(a,f);if(a.control){d(this,a.control);c(a.control).show()}return this.bind("add",function(g,e){c(e).prev().removeClass(b.last).removeClass(b.lastCollapsable).removeClass(b.lastExpandable).find(">.hitarea").removeClass(b.lastCollapsableHitarea).removeClass(b.lastExpandableHitarea);c(e).find("li").andSelf().prepareBranches(a).applyClasses(a,f)})}});var b=c.fn.treeview.classes={open:"open",closed:"closed",expandable:"expandable",expandableHitarea:"expandable-hitarea",lastExpandableHitarea:"lastExpandable-hitarea",
collapsable:"collapsable",collapsableHitarea:"collapsable-hitarea",lastCollapsableHitarea:"lastCollapsable-hitarea",lastCollapsable:"lastCollapsable",lastExpandable:"lastExpandable",last:"last",hitarea:"hitarea"};c.fn.Treeview=c.fn.treeview})(jQuery);
