(function(b){b.ui=b.ui||{};b.fn.extend({accordion:function(h,i){var g=Array.prototype.slice.call(arguments,1);return this.each(function(){if(typeof h=="string"){var j=b.data(this,"ui-accordion");j[h].apply(j,g)}else{if(!b(this).is(".ui-accordion")){b.data(this,"ui-accordion",new b.ui.accordion(this,h))}}})},activate:function(g){return this.accordion("activate",g)}});b.ui.accordion=function(i,k){this.options=k=b.extend({},b.ui.accordion.defaults,k);this.element=i;b(i).addClass("ui-accordion");if(k.navigation){var h=b(i).find("a").filter(k.navigationFilter);if(h.length){if(h.filter(k.header).length){k.active=h}else{k.active=h.parent().parent().prev();h.addClass("current")}}}k.headers=b(i).find(k.header);k.active=f(k.headers,k.active);if(k.fillSpace){var g=b(i).parent().height();k.headers.each(function(){g-=b(this).outerHeight()});var j=0;k.headers.next().each(function(){j=Math.max(j,b(this).innerHeight()-b(this).height())}).height(g-j)}else{if(k.autoheight){var g=0;k.headers.next().each(function(){g=Math.max(g,b(this).outerHeight())}).height(g)}}k.headers.not(k.active||"").next().hide();k.active.parent().andSelf().addClass(k.selectedClass);if(k.event){b(i).bind((k.event)+".ui-accordion",d)}};b.ui.accordion.prototype={activate:function(g){d.call(this.element,{target:f(this.options.headers,g)[0]})},enable:function(){this.options.disabled=false},disable:function(){this.options.disabled=true},destroy:function(){this.options.headers.next().css("display","");if(this.options.fillSpace||this.options.autoheight){this.options.headers.next().css("height","")}b.removeData(this.element,"ui-accordion");b(this.element).removeClass("ui-accordion").unbind(".ui-accordion")}};function e(h,g){return function(){return h.apply(g,arguments)}}function c(i){if(!b.data(this,"ui-accordion")){return}var g=b.data(this,"ui-accordion");var h=g.options;h.running=i?0:--h.running;if(h.running){return}if(h.clearStyle){h.toShow.add(h.toHide).css({height:"",overflow:""})}b(this).triggerHandler("change.ui-accordion",[h.data],h.change)}function a(k,h,m,j,i){var l=b.data(this,"ui-accordion").options;l.toShow=k;l.toHide=h;l.data=m;var g=e(c,this);l.running=h.size()==0?k.size():h.size();if(l.animated){if(!l.alwaysOpen&&j){b.ui.accordion.animations[l.animated]({toShow:jQuery([]),toHide:h,complete:g,down:i,autoheight:l.autoheight})}else{b.ui.accordion.animations[l.animated]({toShow:k,toHide:h,complete:g,down:i,autoheight:l.autoheight})}}else{if(!l.alwaysOpen&&j){k.toggle()}else{h.hide();k.show()}g(true)}}function d(i){var g=b.data(this,"ui-accordion").options;if(g.disabled){return false}if(!i.target&&!g.alwaysOpen){g.active.parent().andSelf().toggleClass(g.selectedClass);var n=g.active.next(),j={instance:this,options:g,newHeader:jQuery([]),oldHeader:g.active,newContent:jQuery([]),oldContent:n},h=g.active=b([]);a.call(this,h,n,j);return false}var k=b(i.target);if(k.parents(g.header).length){while(!k.is(g.header)){k=k.parent()}}var l=k[0]==g.active[0];if(g.running||(g.alwaysOpen&&l)){return false}if(!k.is(g.header)){return}g.active.parent().andSelf().toggleClass(g.selectedClass);if(!l){k.parent().andSelf().addClass(g.selectedClass)}var h=k.next(),n=g.active.next(),j={instance:this,options:g,newHeader:k,oldHeader:g.active,newContent:h,oldContent:n},m=g.headers.index(g.active[0])>g.headers.index(k[0]);g.active=l?b([]):k;a.call(this,h,n,j,l,m);return false}function f(h,g){return g!=undefined?typeof g=="number"?h.filter(":eq("+g+")"):h.not(h.not(g)):g===false?b([]):h.filter(":eq(0)")}b.extend(b.ui.accordion,{defaults:{selectedClass:"selected",alwaysOpen:true,animated:"slide",event:"click",header:"a",autoheight:true,running:0,navigationFilter:function(){return this.href.toLowerCase()==location.href.toLowerCase()}},animations:{slide:function(i,g){i=b.extend({easing:"swing",duration:300},i,g);if(!i.toHide.size()){i.toShow.animate({height:"show"},i);return}var k=i.toHide.height(),h=i.toShow.height(),j=h/k;i.toShow.css({height:0,overflow:"hidden"}).show();i.toHide.filter(":hidden").each(i.complete).end().filter(":visible").animate({height:"hide"},{step:function(m){var l=(k-m)*j;if(b.browser.msie||b.browser.opera){l=Math.ceil(l)}i.toShow.height(l)},duration:i.duration,easing:i.easing,complete:function(){if(!i.autoheight){i.toShow.css("height","auto")}i.complete()}})},bounceslide:function(g){this.slide(g,{easing:g.down?"bounceout":"swing",duration:g.down?1000:200})},easeslide:function(g){this.slide(g,{easing:"easeinout",duration:700})}}})})(jQuery);
