var faq = Class.create();

faq.prototype = {

	initialize: function (question, answer){
		this.answer = answer;
		Event.observe(question, 'click', this.activate.bindAsEventListener(this), false);
	},

	activate: function () {
		if (this.answer.style.display == 'block') {
			this.hide(true);
		} else {
			this.show(true);
		}
	},

	show: function (height) {
		this.answer.style.display = 'block';
		if (height) {
			equalHeight();
		}
	},

	hide: function (height) {
		this.answer.style.display = 'none';
		if (height) {
			equalHeight();
		}
	}
}

var faqs = Class.create();

faqs.prototype = {

	initialize: function (){

		this.questions =	$$('.question');
		this.answers =		$$('.answer');
		this.showAlls =		$$('.showAll');
		this.valids =		new Array();

		if (this.questions.length > 0) {
			for (x = 0; x < this.questions.length; x++) {
				if (browser != 'Internet Explorer'){
					Event.observe(this.questions[x], 'click', this.hideAll.bindAsEventListener(this), false);
				}
				this.valids[x] = new faq(this.questions[x], this.answers[x]);
				if (browser == 'Internet Explorer'){
					Event.observe(this.questions[x], 'click', this.hideAll.bindAsEventListener(this), false);
				}
			}
			Event.observe(this.showAlls[0], 'click', this.flipFlopShowAll.bindAsEventListener(this), false);
		}
		this.hideAll();
	},

	showAll: function(){
		for (x = 0; x < this.valids.length; x++){
			this.valids[x].show(false);
		}
		equalHeight();
	},

	hideAll: function(){
		for (x = 0; x < this.valids.length; x++){
			this.valids[x].hide(false);
		}
		equalHeight();
	},

	flipFlopShowAll: function () {
		if (this.showAlls[0].checked){
			this.showAll();
		} else {
			this.hideAll();
		}
	}
}


Event.observe(window, 'load',
	function() {
		faqs = new faqs();
	}
);
