// script.aculo.us sccordeon.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008

// Copyright (c) 2009-2010 Anton BAchmayr (http://netzteil.at)
//           
// Contributors:
// 
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/

Accordeon = Class.create();
Accordeon.prototype = {
	initialize:function(container, options) {
		this.container = $(container);
		this.options = options;
		this.pane = this.options.pane || 'div';
		this.clickpane = this.options.clickpane || '';
		this.bodypane = this.options.bodypane || '';
		this.openpane = this.options.openpane || '';
		this.duration = this.options.duration || 0.5;
		if(this.options.effect && this.options.effect == 'blind')
			this.effect = 'blind';
		else
			this.effect = 'slide';
		this.panels = $A(this.container.getElementsByTagName(this.pane));
		if(this.clickpane == '')
			throw("You must specify the class of the click pane.");
		this.clickpanes = $$('.' + this.clickpane);
		if(this.bodypane == '')
			throw("You must specify the class of the body pane.");
		this.bodypanes = $$('.' + this.bodypane);
		if(this.openpane == '')
			this.openpane = $(this.panels[0]);
		else
			this.openpane = $(this.openpane);
		var accordeon = this;
		this.clickpanes.each(function(s) {
			s.observe('click',accordeon.slideAccordeon.bindAsEventListener(accordeon));
		});
		var effect = this.effect;
		this.bodypanes.each(function(s) {
			s.id = s.up().id + '-body';
			if(effect == 'slide') {
				div = document.createElement('div');
				div.innerHTML = s.innerHTML;
				s.innerHTML = '';
				s.appendChild(div);
			}
		});
		this.openpane.immediateDescendants()[1].show();
	},
	slideAccordeon:function(event) {
		var elem = Event.element(event);
		while(elem.className != this.clickpane) {
			elem = elem.up();
		}
		elem = elem.next();
		var current;
		var bodypane = this.bodypane;
		this.panels.each(function(s) {
			if (s.className == bodypane) {
				if (s.style.display =='block' || s.style.display == '')
					current = s;
			}
		});
		if (elem == current)
				return;
		else if (elem) {
				eldown = elem;
				elup = current;
				if(this.effect == 'blind')
					new Effect.Parallel( [ new Effect.BlindUp(elup, { sync:true}), new Effect.BlindDown(eldown, { sync:true }) ], { duration: this.duration });
				else
					new Effect.Parallel( [ new Effect.SlideUp(elup, { sync:true}), new Effect.SlideDown(eldown, { sync:true }) ], { duration: this.duration });
		}
	}
};

