/*
	Nested Mootools Accordion
	Requieres Mootools 1.2
	
	2009 Created by:
	Raúl Solana <http;//www.tambaqui.es>
	for CodeFactory  <http://www.codefactory.es>

	Inspired on;
	http://www.medianotions.de
	by Bogdan Günther

*/

var cfAcordeon = {

	init: function(indicesDisplay,checkHash) {
		if (!document.getElementById || !indicesDisplay) return;
		if(window.ie6) var heightValue='100%';
		else var heightValue='';
		
		var togglerName='dt.accordion_toggler_';
		var contentName='dd.accordion_content_';
		
		var counter=1;	
		var toggler=$$(togglerName+counter);
		var content=$$(contentName+counter);
		
		indice=0;
		while(toggler.length>0)
		{
			new Accordion(toggler, content, {
				'opacity': false,
				//'display': indicesDisplay[indice],
				'show': indicesDisplay[indice],
				initialDisplayFx: false,
				'transition': Fx.Transitions.Quad.easeOut,
				alwaysHide: true,
				onComplete: function() { 
					var element=$(this.elements[this.previous]);
					if(element && element.offsetHeight>0) element.setStyle('height', heightValue);			
				},
				onActive: function(toggler, content) {
					toggler.addClass('toggle_active');
				},
				onBackground: function(toggler, content) {
					toggler.removeClass('toggle_active');
				}
			});
			
			indice++;
			counter++;
			toggler=$$(togglerName+counter);
			content=$$(contentName+counter);
		}
		
		/*var terms = $$('a.acc_term');
		
		terms.each(function(link,i){
			link.addEvent('focus', cfAcordeon.focusTerm);
			if(checkHash){
				if(window.location.hash.test(link.hash)){
					link.getParent().fireEvent('click');
				}
			}
		});*/
		
	},
	
	focusTerm: function(event){
	  var dd=this.getParent();
	  if(!dd.hasClass('toggle_active')){
		dd.fireEvent('click');
		//event.stopPropagation();
	  }
	},


	clickTerm: function(event){
		event.stop();
	}

}


