// JavaScript DocumentAccordion = Class.create();
Accordion = Class.create();
Accordion.prototype = {
	setOptions: function(options) {
		this.options = {
			duration:   0.6,
			onComplete: null
		}
		Object.extend(this.options, options || {});
	},
	initialize: function(togglers, sections, options){
		this.setOptions (options);
		
		this.sections = sections;

		togglers.each(function(tog, i){
			if (typeof tog.onclick == 'function') var exClick = tog.onclick;
			tog.onclick = function(){
				if (exClick) exClick();
				this.toggle(sections[i]);
			}.bind(this);
			tog.style.cursor = "pointer";
		}.bind(this));

		for (i = 0; i < sections.length; i++) {
			sections[i].style.display = 'none';
		}
	},
	toggle: function(el) {
		if (el == this.lastSection) {
			this.hide (el);
			this.lastSection = null;
			return;
		}
		for (i = 0; i < this.sections.length; i++) {
			if (this.sections[i] == el)
				this.show (this.sections[i]);
			else
				this.hide (this.sections[i]);
		}
		this.lastSection = el;
	},
	show: function(el){
		if (el.style.display == 'none') {
			el.show ();
			try {
					this.options.onComplete ({element:el})
			} catch (e) { }
//			new Effect.BlindDown  (el, { duration:this.options.duration,afterFinish:this.options.onComplete });
//			new Effect.Opacity    (el, { duration:this.options.duration });
		}
	},
	hide: function(el){
		if (el.style.display != 'none') {
			el.hide ();
			try {
					this.options.onComplete ({element:el})
			} catch (e) { }
//			new Effect.BlindUp	  (el, { duration:this.options.duration,afterFinish:this.options.onComplete });
//			new Effect.Opacity	  (el, { duration:this.options.duration,from:1,to:0 });
		}
	},
	hideAll: function(){
		for (i = 0; i < this.sections.length; i++)
			this.hide (this.sections[i]);
	}
}

Tab = Class.create();
Tab.prototype = {
	setOptions: function(options) {
		this.options = {
			delay: 0.1
		}
		Object.extend(this.options, options || {});
	},
	
	initialize: function(element, options, show) {
		this.element = element;
		this.setOptions(options);

		if (show == false)
		{
			element.style.display = 'none';
			
			if (this.options.opacity == true)
				Element.setOpacity (element, 0);
		}
	},

	close: function(){
		if (this.element.style.display != 'none')
			this.toggle ();
	},
	show: function(){
		if (this.element.style.display == 'none')
			this.toggle ();
	},
	toggle: function(){
		setTimeout(function(){
			if (this.element.style.display == 'none') {
				new Effect.BlindDown  (this.element, { duration:this.options.duration,afterFinish:this.options.onComplete });
				if (this.options.opacity == true)
					new Effect.Opacity    (this.element, { duration:this.options.duration });
			} else  {
				new Effect.BlindUp	  (this.element, { duration:this.options.duration,afterFinish:this.options.onComplete });
				if (this.options.opacity == true)
					new Effect.Opacity	  (this.element, { duration:this.options.duration,from:1,to:0 });
			}
		}.bind(this), this.options.delay*1000);
	}
}
