/*
*	Accordion Effect Plugin for MooBot
*
* Version History:
* 1.0 - Initiale Release
* 1.1 - Added support for Options
*/

var MooBotAccordion = Accordion.extend({
	initialize: function(handles, drawers, options) {
		// run parent initializer
		this.parent.apply(this, arguments);
		
		// this next part adds the automatic opening magic to each “Handle”
		this.togglers.each(function(handle, index, array) {
			handle.addEvents({
				mouseover: function(thisHandle) {
					thisHandle.setStyles({cursor: 'pointer'});
				}.bind(this, handle),
				focus: this.display.pass(index, this) // supports tab based keyboard navigation
			});
		}.bind(this));
	}
});

window.addEvent('domready', function(){

	$each($$('div[id^="mootools_accordion-container"]'), function(container){

		var id = container.getProperty('id').substr(container.getProperty('id').lastIndexOf('-')+1,13);
		var params = new Object();

		if ( moobot_global_vars[id]!=undefined && moobot_global_vars[id]!='' ) {
			var option = new String(moobot_global_vars[id]);
			option = option.replace(/^\,/,'');
			option = option.replace(/\&quot;/gi,'"');
			var params = Json.evaluate('{'+option+'}');
		}

		params = Object.extend({
			onActive: function(toggler, element){
				toggler.setProperty('class','toggler-active accordion');
			},
		 
			onBackground: function(toggler, element){
				toggler.setProperty('class','toggler accordion');
			}
		}, params || {});

		var accordion = new MooBotAccordion(
			container.getElements('h3[id=mootools_accordion-toggler]'),
			container.getElements('div[id=mootools_accordion-element]'),
			params, container);

	});

});

