var Accordion = Class.create();
Accordion.prototype = {

	options:{},
	current:0,
	assocEntry:[],
	assocPanel:[],

	initialize: function(element, opt) {
		if(!$(element)){ return false; }
		Object.extend(this.options, opt || {});
		Element.cleanWhitespace($(element));
		var indice = 1;
		$(element).getElementsBySelector(this.options.entry).each(function(entry){
			this.assocEntry[indice] = entry;
			Event.observe(entry, 'click', this.slide.bindAsEventListener(this, indice));
			indice++;
		}.bind(this));
		indice = 1;
		$(element).getElementsBySelector(this.options.panel).each(function(panel){
			new Insertion.Top(panel, '<div></div>');
			this.assocPanel[indice] = panel;
			indice++;
		}.bind(this));

	},

	slide: function (event, indice){
		if(this.current != indice){
			if(this.current != 0){
				Element.show(this.assocPanel[indice]);
				Element.hide(this.assocPanel[this.current]);
				//new Effect.Parallel([new Effect.SlideDown(this.assocPanel[indice]), new Effect.SlideUp(this.assocPanel[this.current]) ]); //, {'duration': 0.1}
			} else {
				//new Effect.SlideDown(this.assocPanel[indice]);
				Element.show(this.assocPanel[indice]);
			}
			this.current = indice;
		} else {
			//new Effect.SlideUp(this.assocPanel[indice]);
			Element.hide(this.assocPanel[indice])
			this.current = 0;
		}
	}

};

Event.observe(window, 'load', function(){
		var accObj = new Accordion('accordion', {
		'entry':'h3',
		'panel':'div.accordion-panel'
	});
});