var Accordion=Fx.Elements.extend({options:{onActive:Class.empty,onBackground:Class.empty,display:0,show:false,height:true,width:false,opacity:true,fixedHeight:false,fixedWidth:false,wait:false,alwaysHide:false},initialize:function(){
var _538,togglers,elements,container;
$each(arguments,function(_539,i){
switch($type(_539)){
case "object":
_538=_539;
break;
case "element":
container=$(_539);
break;
default:
var temp=$$(_539);
if(!togglers){
togglers=temp;
}else{
elements=temp;
}
}
});
this.togglers=togglers||[];
this.elements=elements||[];
this.container=$(container);
this.setOptions(_538);
this.previous=-1;
if(this.options.alwaysHide){
this.options.wait=true;
}
if($chk(this.options.show)){
this.options.display=false;
this.previous=this.options.show;
}
if(this.options.start){
this.options.display=false;
this.options.show=false;
}
this.effects={};
if(this.options.opacity){
this.effects.opacity="fullOpacity";
}
if(this.options.width){
this.effects.width=this.options.fixedWidth?"fullWidth":"offsetWidth";
}
if(this.options.height){
this.effects.height=this.options.fixedHeight?"fullHeight":"scrollHeight";
}
for(var i=0,l=this.togglers.length;i<l;i++){
this.addSection(this.togglers[i],this.elements[i]);
}
this.elements.each(function(el,i){
if(this.options.show===i){
this.fireEvent("onActive",[this.togglers[i],el]);
}else{
for(var fx in this.effects){
el.setStyle(fx,0);
}
}
},this);
this.parent(this.elements);
if($chk(this.options.display)){
this.display(this.options.display);
}
},addSection:function(_540,_541,pos){
_540=$(_540);
_541=$(_541);
var test=this.togglers.contains(_540);
var len=this.togglers.length;
this.togglers.include(_540);
this.elements.include(_541);
if(len&&(!test||pos)){
pos=$pick(pos,len-1);
_540.injectBefore(this.togglers[pos]);
_541.injectAfter(_540);
}else{
if(this.container&&!test){
_540.inject(this.container);
_541.inject(this.container);
}
}
var idx=this.togglers.indexOf(_540);
_540.addEvent("click",this.display.bind(this,idx));
if(this.options.height){
_541.setStyles({"padding-top":0,"border-top":"none","padding-bottom":0,"border-bottom":"none"});
}
if(this.options.width){
_541.setStyles({"padding-left":0,"border-left":"none","padding-right":0,"border-right":"none"});
}
_541.fullOpacity=1;
if(this.options.fixedWidth){
_541.fullWidth=this.options.fixedWidth;
}
if(this.options.fixedHeight){
_541.fullHeight=this.options.fixedHeight;
}
_541.setStyle("overflow","hidden");
if(!test){
for(var fx in this.effects){
_541.setStyle(fx,0);
}
}
return this;
},display:function(_547){
_547=($type(_547)=="element")?this.elements.indexOf(_547):_547;
if((this.timer&&this.options.wait)||(_547===this.previous&&!this.options.alwaysHide)){
return this;
}
this.previous=_547;
var obj={};
this.elements.each(function(el,i){
obj[i]={};
var hide=(i!=_547)||(this.options.alwaysHide&&(el.offsetHeight>0));
this.fireEvent(hide?"onBackground":"onActive",[this.togglers[i],el]);
for(var fx in this.effects){
obj[i][fx]=hide?0:el[this.effects[fx]];
}
},this);
return this.start(obj);
},showThisHideOpen:function(_54d){
return this.display(_54d);
}});
Fx.Accordion=Accordion;
