// console.log('accordion v1.01');
var accordion = Class.create();
accordion.prototype = {
	showAccordion : null,
	currentAccordion : null,
	animating : false,
	accordions: null,
	initialize: function(container, options) {
		// console.log('test');
		if (!$(container)) {console.log(container+" doesn't exist!");return false;}
				// console.log('test1');
				$(container).cleanWhitespace();
				// console.log('test2');
		this.options = Object.extend({
			classNames : {
				toggle : 'accordion_toggle',
				toggleActive : 'accordion_toggle_active',
				content : 'accordion_content'
			},
			direction : 'vertical',
			onEvent : 'click',
			speed : 1
		}, options || {});
				// console.log('test3');
				// console.log('test4');
		// console.log(accordions);
				// console.log('test5');
		this.accordions = $$('#'+container+' .'+this.options.classNames.toggle);
		this.accordions.each(function(accordion) {
			Event.observe(accordion, this.options.onEvent, this.rolldown.bind(this, accordion), false);
			if (this.options.onEvent == 'click') {accordion.onclick = function() {return false;};}
/*			if (this.options.direction == 'horizontal') {
				var options = $H({width: '0px'});
			} else {
				var options = $H({height: '0px'});			
			}
			options.merge({display: 'none'});	*/
//			this.currentAccordion = $(accordion.next(0)).setStyle(options);
//			this.accordion.hide();
			$(accordion.next(0)).hide();
			// console.log($(accordion.next(0)));
		}.bind(this));
		this.rolldown(this.accordions[0]);
	},
	rolldown: function(accordion) {
		if (this.animating) {return false;};
		if ($(accordion.next(0)) == this.currentAccordion) return;
		this.currentAccordion = $(accordion.next(0));
		// console.log(this.currentAccordion);
		this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);
//		new Effect.SlideDown(this.currentAccordion);
//		this.currentAccordion.show();

//		// console.log(this.showAccordion);
		if (this.showAccordion != null) {
		    this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
//			new Effect.BlindDown(this.currentAccordion);
//			new Effect.BlindUp(this.showAccordion);
		new Effect.Parallel([
		  new Effect.BlindDown(this.currentAccordion, { sync: true}),
		  new Effect.BlindUp(this.showAccordion, { sync: true})
		], { 
		  duration: this.options.speed,
		  transition: Effect.Transitions.linear,
		  queue: { position: 'end', scope: 'accordion' }
		});

		} else {
			this.currentAccordion.show();
		};
		this.showAccordion = this.currentAccordion;
/*		if (this.currentAccordion == this.showAccordion) {
		  this.rollup();
		} else {
		  this._animate();
		}
*/

	}
};
