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