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