/* MooTools Accordion extension
   ============================ 
*/
var MultipleOpenAccordion = new Class({
	Extends: Accordion,
	options: {
		allowMultipleOpen: true,
		openClass: ''
	},
	initialize: function(togglers,togglees,options){
		this.parent(togglers,togglees,options);
		if (this.options.openClass != '') {
			this.elements.each(function(el, index) {
				if (!el.hasClass(this.options.openClass)) return;
				for (var fx in this.effects) el.setStyle(fx, el[this.effects[fx]]);
			}.bind(this));			
		}
	},
	expand: function() {
		this.elements.each(function(el, index) {
			for (var fx in this.effects) el.setStyle(fx, el[this.effects[fx]]);
		}.bind(this));
	},
	collapse: function() {
		this.elements.each(function(el, index) {
			for (var fx in this.effects) el.setStyle(fx, 0);
		}.bind(this));
	},
	display: function(index, forceDisplay){
		index = ($type(index) == 'element') ? this.elements.indexOf(index) : index;
		if ((this.timer && this.options.wait) || (index === this.previous && !this.options.alwaysHide)) return this;
 
		var obj = {};
		if(this.options.allowMultipleOpen){
			var el = this.elements[index];
			obj[index] = {};
			var hide = (el.offsetHeight > 0) && !forceDisplay;
			this.fireEvent(hide ? 'onBackground' : 'onActive', [this.togglers[index], el]);
			for (var fx in this.effects) obj[index][fx] = hide ? 0 : el[this.effects[fx]];
		}else{
			this.previous = index;
			this.elements.each(function(el, i){
				obj[i] = {};
				var hide = (i != index) || (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);
	}
});
