var MultipleOpenAccordion
=
Fx.Elements.extend(
	{
		options:
		{
			openAll:true,
			allowMultipleOpen:true,
			firstElementsOpen:[0],
			start:"first-open",
			fixedHeight:false,
			fixedWidth:false,
			alwaysHide:true,
			wait:false,
			onActive:Class.empty,
			onBackground:Class.empty,
			height:true,
			opacity:false,
			width:false
		},
		initialize:function(B,C,A)
		{
			this.parent(C,A);
			this.setOptions(A);
			this.previousClick=null;
			this.elementsVisible=[];
			B.each(
				function(E,D)
				{
					$(E).addEvent(
						"click",
						function()
						{
							this.toggleSection(D)
						}.bind(this)
					)
				},
				this
			);
			this.togglers=B;
			this.h={};
			this.w={};
			this.o={};
			this.now=[];
			this.elements.each(
				function(E,D)
				{
					E=$(E);
					this.now[D]={};
					E.setStyle("overflow","hidden");
					if(!(this.options.openAll&&this.options.allowMultipleOpen)){
						E.setStyle("height",0)
					}
				},
				this
			);
			if(!this.options.openAll||!this.options.allowMultipleOpen){
				switch(this.options.start)
				{
					case"first-open":
						this.showSection(this.options.firstElementsOpen[0]);
						break;
					case"open-first":
						this.toggleSection(this.options.firstElementsOpen[0]);
						break
				}
			}
			if(this.options.openAll&&this.options.allowMultipleOpen){
				this.showAll()
			}
			else{
				if(this.options.allowMultipleOpen){
					this.openSections(this.options.firstElementsOpen)
				}
			}
		},
		hideThis:function(A)
		{
			this.elementsVisible[A]=false;
			if(this.options.height){
				this.h={height:[this.elements[A].offsetHeight,0]}
			}
			if(this.options.width){
				this.w={width:[this.elements[A].offsetWidth,0]}
			}
			if(this.options.opacity){
				this.o={opacity:[this.now[A]["opacity"]||1,0]}
			}
			this.fireEvent("onBackground",[this.togglers[A],this.elements[A]])
		},
		showThis:function(A)
		{
			this.elementsVisible[A]=true;
			if(this.options.height){
				this.h={height:[this.elements[A].offsetHeight,this.options.fixedHeight||this.elements[A].scrollHeight]}
			}
			if(this.options.width){
				this.w={width:[this.elements[A].offsetWidth,this.options.fixedWidth||this.elements[A].scrollWidth]}
			}
			if(this.options.opacity){
				this.o={opacity:[this.now[A]["opacity"]||0,1]}
			}
			this.fireEvent("onActive",[this.togglers[A],this.elements[A]])
		},
		toggleSection:function(C)
		{
			if(C!=this.previousClick||this.options.alwaysHide||this.options.allowMultipleOpen){
				this.previousClick=C;
				var A={};
				var B=false;
				this.elements.each(function(E,D)
									{
										var F=false;
										this.now[D]=this.now[D]||{};
										if(D==C){
											if(this.elementsVisible[D]&&(this.options.allowMultipleOpen||this.options.alwaysHide)){
												if(!(this.options.wait&&this.timer)){
													F=true;
													this.hideThis(D)
												}
												else{
													this.previousClick=null;
													B=true
												}
											}
											else{
												if(!this.elementsVisible[D]){
													if(!(this.options.wait&&this.timer)){
														F=true;
														this.showThis(D)
													}
													else{
														this.previousClick=null;
														B=true
													}
												}
											}
										}
										else{
											if(this.elementsVisible[D]&&!this.options.allowMultipleOpen){
												if(!(this.options.wait&&this.timer)){
													F=true;
													this.hideThis(D)
												}
												else{
													this.previousClick=null;
													B=true
												}
											}
										}
										if(F){
											A[D]=$merge(this.h,$merge(this.o,this.w))
										}
									},
								this);
				if(B){
					return false
				}
				return this.custom(A)
			}
			return false
		},
		showSection:function(A,B)
			{
				if($pick(B,false)){
					if(!this.elementsVisible[A]){
						this.toggleSection(A)
					}
				}
				else if(A != -1 && A != "" && A != null){
					this.setSectionStyle(A,$(this.elements[A]).scrollWidth,$(this.elements[A]).scrollHeight,1);
					this.elementsVisible[A]=true;
					this.fireEvent("onActive",[this.togglers[A],this.elements[A]])
				}
			},
		hideSection:function(A,B)
			{
				if($pick(B,false)){
					if(this.elementsVisible[A]){
						this.toggleSection(A)
					}
				}
				else{
					this.setSectionStyle(A,0,0,0);
					this.elementsVisible[A]=false;
					this.fireEvent("onBackground",[this.togglers[A],this.elements[A]])
				}
			},
		setSectionStyle:function(B,A,C,D)
			{
				if(this.options.opacity){
					$(this.elements[B]).setOpacity(D)
				}
				if(this.options.height){
					$(this.elements[B]).setStyle("height",C+"px")
				}
				if(this.options.width){
					$(this.elements[B]).setStyle("width",A+"px")
				}
			},
		showAll:function()
			{
				if(this.options.allowMultipleOpen){
					this.elements.each(function(B,A){
						this.showSection(A,false)
					},
					this)
				}
			},
		hideAll:function()
			{
				if(this.options.allowMultipleOpen){
					this.elements.each(function(B,A)
										{
											this.hideSection(A,false)
										},
										this)
				}
			},
		openSections:function(A)
			{
				if(this.options.allowMultipleOpen){
					this.elements.each(function(C,B)
										{
											if(A.test(B)){
												this.showSection(B,false)
											}
											else{
												this.hideSection(B,false)
											}
										},
										this)
				}
			}
	}
);
MultipleOpenAccordion.implement(new Options);
MultipleOpenAccordion.implement(new Events);
