/*
Accordion UI for Script.aculo.us
Created by Jeremiah Cohick
http://jeremiahlee.com
Copyright 2008 Jeremiah Cohick. Some Rights Reserved under a Creative Commons Attribution 3.0 United States License.
*/

var Accordion = Class.create();
 
Accordion.prototype = {
	initialize: function(titles, panes, options) {
		this.options = this._set_options(options); 	
		this.headers = $$(titles);
		lit = -1;
		inprogress = false;

		for (var i = 0; i < this.headers.length; i++) {  	
			Event.observe(this.headers[i], this.options.event_trigger, this.show.bind(this, i));   		
			this.headers[i].style.backgroundColor = this.options.normalColors[i];
		}
	},
 
	show: function(index) {		
		if ((index != lit) && (inprogress == false)) {
			
			if (lit == -1) {	// init accordion
				// alert();
			} else {
				this.headers[lit].style.backgroundColor = this.options.normalColors[lit];  
			}			
			this.headers[index].style.backgroundColor = this.options.highlightColors[index];
			lit = index;
		}
	},
   
	_default_options: {
		duration: .2,
		event_trigger: 'mouseover',
		normalColors: ["#BBB", "#999", "#777", "#555"],
		highlightColors: ["#900", "#363", "#336", "#C93"]
	},

	_set_options: function(options) {
		if (typeof options != "undefined") {  	
			var result = [];
			for (option in this._default_options) {
				if (typeof options[option] == "undefined") {
					result[option] = this._default_options[option];
				} else {
					result[option] = options[option];
				}
			}
			return result;
		} else {
			return this._default_options;
		}
	}  	
};
 
Effect.Accordion = Accordion;