PrimeFaces.widget.AccordionPanel=PrimeFaces.widget.BaseWidget.extend({init:function(a){this._super(a);this.tabs=this.jq.children(".ui-collapsible");this.headers=this.tabs.children(".ui-collapsible-heading");this.contents=this.tabs.children(".ui-collapsible-content");this.stateHolder=$(this.jqId+"_active");this.initActive();this.bindEvents();if(this.cfg.dynamic&&this.cfg.cache){this.markLoadedPanels()}},initActive:function(){if(this.cfg.multiple){var a=this.stateHolder.val().split(",");for(var b=0;b<a.length;b++){a[b]=parseInt(a[b])}this.cfg.active=a}else{this.cfg.active=parseInt(this.stateHolder.val())}},bindEvents:function(){var a=this;this.headers.on("click.accordionPanel",function(d){var c=$(this);if(!c.hasClass("ui-state-disabled")){var b=c.parent().index();if(c.hasClass("ui-collapsible-heading-collapsed")){a.select(b)}else{a.unselect(b)}}d.preventDefault()})},markLoadedPanels:function(){if(this.cfg.multiple){for(var a=0;a<this.cfg.active.length;a++){if(this.cfg.active[a]>=0){this.markAsLoaded(this.tabs.eq(this.cfg.active[a]))}}}else{if(this.cfg.active>=0){this.markAsLoaded(this.tabs.eq(this.cfg.active))}}},select:function(b){var c=this.tabs.eq(b);if(this.cfg.onTabChange){var a=this.cfg.onTabChange.call(this,c);if(a===false){return false}}var d=this.cfg.dynamic&&!this.isLoaded(c);if(this.cfg.multiple){this.addToSelection(b)}else{this.cfg.active=b}this.saveState();if(d){this.loadDynamicTab(c)}else{this.show(c);this.fireTabChangeEvent(c)}return true},show:function(a){var c=a.children(".ui-collapsible-heading"),b=a.children(".ui-collapsible-content");if(!this.cfg.multiple){this.close(this.tabs.filter(":not(.ui-collapsible-collapsed)"))}a.removeClass("ui-collapsible-collapsed").attr("aria-expanded",true);c.removeClass("ui-collapsible-heading-collapsed").children(".ui-collapsible-heading-toggle").removeClass("ui-icon-plus").addClass("ui-icon-minus");b.removeClass("ui-collapsible-content-collapsed").attr("aria-hidden",false).show()},close:function(a){a.addClass("ui-collapsible-collapsed").attr("aria-expanded",false);a.children(".ui-collapsible-heading").addClass("ui-collapsible-heading-collapsed").children(".ui-collapsible-heading-toggle").addClass("ui-collapsible-heading-collapsed").removeClass("ui-icon-minus").addClass("ui-icon-plus");a.children(".ui-collapsible-content").attr("aria-hidden",true).addClass("ui-collapsible-content-collapsed").attr("aria-hidden",true).hide()},unselect:function(a){this.close(this.tabs.eq(a));this.removeFromSelection(a);this.saveState();if(this.hasBehavior("tabClose")){this.fireTabCloseEvent(tab)}},addToSelection:function(a){this.cfg.active.push(a)},removeFromSelection:function(a){this.cfg.active=$.grep(this.cfg.active,function(b){return(b!==a)})},saveState:function(){if(this.cfg.multiple){this.stateHolder.val(this.cfg.active.join(","))}else{this.stateHolder.val(this.cfg.active)}},loadDynamicTab:function(b){var c=this,a={source:this.id,process:this.id,update:this.id,params:[{name:this.id+"_contentLoad",value:true},{name:this.id+"_newTab",value:b.attr("id")},{name:this.id+"_tabindex",value:b.index()}],onsuccess:function(f,d,e){PrimeFaces.ajax.Response.handle(f,d,e,{widget:c,handle:function(g){b.find("> .ui-collapsible-content > p").html(g);if(this.cfg.cache){this.markAsLoaded(b)}}});return true},oncomplete:function(){c.show(b)}};if(this.hasBehavior("tabChange")){this.cfg.behaviors.tabChange.call(this,a)}else{PrimeFaces.ajax.AjaxRequest(a)}},fireTabChangeEvent:function(b){if(this.hasBehavior("tabChange")){var c=this.cfg.behaviors.tabChange,a={params:[{name:this.id+"_newTab",value:b.attr("id")},{name:this.id+"_tabindex",value:parseInt(b.index())}]};c.call(this,a)}},fireTabCloseEvent:function(b){var c=this.cfg.behaviors.tabClose,a={params:[{name:this.id+"_tabId",value:b.attr("id")},{name:this.id+"_tabindex",value:parseInt(b.index())}]};c.call(this,a)},markAsLoaded:function(a){a.data("loaded",true)},isLoaded:function(a){return a.data("loaded")===true},hasBehavior:function(a){if(this.cfg.behaviors){return this.cfg.behaviors[a]!=undefined}return false}});