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(clickedElm.descendantOf("faq_container")){
					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($('faq_container')){
			accordian = new Accordian('faq_container','h2',true);
			/*accordian.openSection('first');*/
		}
	}
