Accordian = Class.create();
Accordian.prototype = {
	initialize: function(elem, clickableEntity, expandMode) {
		this.expandMode = expandMode;
		this.container = $(elem);
		var headers = $$('#' + elem + ' .section ' + clickableEntity);
		headers.each(function(header) {
			Event.observe(header,'click',this.sectionClicked.bindAsEventListener(this));
		}.bind(this));
	},
	sectionClicked: function(event) {
		var clickedElm = Event.element(event).parentNode;
		Element.extend(clickedElm); /*needed for Internet Explorer*/
		if (this.expandMode) {
			if (clickedElm.hasClassName("active")) {
				//this.closeSection(clickedElm);
				if($('faq_container')){
					if(clickedElm.descendantOf("faq_container")){
						this.closeSection(clickedElm);
					}
				} else {
					if(clickedElm.descendantOf("faq_container_dir615")){
						this.closeSection(clickedElm);
					}
					else if(clickedElm.descendantOf("faq_container_dir652")){
						this.closeSection(clickedElm);
					}
					else if(clickedElm.descendantOf("faq_container_dwa140")){
						this.closeSection(clickedElm);
					}
					else if(clickedElm.descendantOf("faq_container_fritzbox6360")){
						this.closeSection(clickedElm);
					}
					else if(clickedElm.descendantOf("faq_container_fritzbox7270")){
						this.closeSection(clickedElm);
					}
					else if(clickedElm.descendantOf("faq_container_hitroncve30360")){
						this.closeSection(clickedElm);
					}
                    else if(clickedElm.descendantOf("faq_container_tap2i")){
						this.closeSection(clickedElm);
					}
				}
			} else {
				this.openSection(clickedElm);
			}
		} else {	
			if(clickedElm.id == this.currentSection){
				//this.closeExistingSection();
			}else{
				this.closeExistingSection();
				this.openSection(clickedElm);
			}
		}
	},
	openSection: function(section) {
		var section = $(section);
		this.currentSection = section.id;
		section.addClassName('active');
		section.down('.contents').style.display="block";
	},
	closeExistingSection: function() {
		if(this.currentSection) {
			this.closeSection(this.currentSection);
			this.currentSection = null;
		}
	},
	closeSection: function(section) {
		var section = $(section);
		section.down('.contents').style.display="none";
		section.removeClassName('active');
	}
}

Event.observe(window,'load',init,false);
function init() {
	if($('fast_access_container')){
		accordian = new Accordian('fast_access_container','h2',false);
		accordian.openSection('services');
	}
	if($('fast_access_container_mgm')){
		accordian = new Accordian('fast_access_container_mgm','h2',false);
		accordian.openSection('mgmTab1');
	}
	if($('faq_container')){
		accordian = new Accordian('faq_container','h2',true);
		/*accordian.openSection('first');*/
	}
	if($('faq_container_dir615')){
		accordianDir615 = new Accordian('faq_container_dir615','h2',true);
	}
	if($('faq_container_dir652')){
		accordianDir652 = new Accordian('faq_container_dir652','h2',true);
	}
	if($('faq_container_dwa140')){
		accordianDwa140 = new Accordian('faq_container_dwa140','h2',true);
	}
	if($('faq_container_fritzbox6360')){
		accordianFritzbox6360 = new Accordian('faq_container_fritzbox6360','h2',true);
	}
	if($('faq_container_fritzbox7270')){
		accordianFritzbox7270 = new Accordian('faq_container_fritzbox7270','h2',true);
	}
	if($('faq_container_hitroncve30360')){
		accordianHitronCVE30360 = new Accordian('faq_container_hitroncve30360','h2',true);
	}
    if($('faq_container_tap2i')){
		accordianTAP2I = new Accordian('faq_container_tap2i','h2',true);
	}

}

