/*
gbAccordion v1.0 mit MooTools v1.2

von gb media (www.gb-media.biz) 2009
Vielen Dank an die MooTools Entwickler
*/

var gbAccordion = new Class({
	
	Implements: Options,
	
    options: {
		handle			: 'accordion',
		toggler			: 'toggler',
		toggleractive	: 'togglerh',
		content			: 'listcontent',
		anker			: 0,
		opacity			: false
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.getAnker();
	},
	
	getAnker: function (){
		if (!$(this.options.handle)){
			return false;
		}
		this.bound = {};
		if (window.location.hash != ""){
			ankername = window.location.hash.substr(1);
			var anchorAr = $$('.'+this.options.toggler);
			var anchornameAr = [];
			anchorAr.each(function (el, i){
				anchornameAr.include(el.id);
				this.bound.onMouseOver = this.onMouseOver.bindWithEvent(this, i);
				$(el).addEvent('mouseover', this.bound.onMouseOver);
				this.bound.onMouseOut = this.onMouseOut.bindWithEvent(this, i);
				$(el).addEvent('mouseout', this.bound.onMouseOut);
				this.bound.onMouseOut = this.onMouseOut.bindWithEvent(this, i);
				$(el).addEvent('mouseout', this.bound.onMouseOut);
				this.bound.onClick = this.onClick.bindWithEvent(this, i);
				$(el).addEvent('click', this.bound.onClick);
			}.bind(this));
			this.options.anker = anchornameAr.indexOf(ankername);
		}
		this.setAccordion();
	},
	
	onMouseOver: function (event, i){
		el = $(event.target);
		el.className = this.options.toggleractive;
		return false;
	},
	onMouseOut: function (event, i){
		el = $(event.target);
		if (this.options.anker != i){
			el.className = this.options.toggler;
		}
		return false;
	},
	onClick: function (event, i){
		this.options.anker = i;
	},
	
	setAccordion: function (){
		$(this.options.handle).setStyle('display', '');
		var myAccordion = new Accordion($(this.options.handle), '.'+this.options.toggler, '.'+this.options.content, {
			display: this.options.anker,
			opacity: this.options.opacity,
			onActive: function(toggler, element){
				toggler.className = this.options.toggleractive;
				
			}.bind(this),
			onBackground: function(toggler, element){
				toggler.className = this.options.toggler;
			}.bind(this)
		});
		this.injectGbMedia($(this.options.handle));
	},
	
	injectGbMedia: function (el){
		gbmedia = new Element('div', {
			'html': '',
			'styles': {
				'color': '#e1e1e1',
				'font-size': '9px'
			}
		}).injectInside(el);
	}
	
});
gbAccordion.implement(new Options);

window.addEvent('domready', function(){
	if (typeof gbAccordionOpt == 'undefined'){
		gbAccordionOpt = {}; 
	}
	
	gbAccordion = new gbAccordion(gbAccordionOpt);
});
