/*
 * JS for opening / closing FAQ questions
 * 
 * @author  Veress Albert - averess@e-scape.ro
 * @version 1.0
 */

//Global variables that store the question / answer, that were previously opened
var old_item;
var old_answer;

/**
 * ShowFAQ
 * 
 * Opens the answer under the question, and adds active class to the question
 * 
 * @param reference string
 * @return void
 */
function showFAQ(reference){
	this.item = $('#faq_item_'+reference);
	this.question = $('#faq_question_'+reference);
	this.answer = $('#faq_answer_'+reference);

	// Add active class
	this.item.toggleClass('faq_active_item');
	// Show answer
	this.answer.toggle();
	
	// Hide the old item
	if (old_item != undefined && old_item != this.item){
		hideFAQ();
	}
	
	// Update the global vars
	old_item = this.item;
	old_answer = this.answer;
	
	// Redirect browser to named anchor of active question
	window.location = '#' + reference;
}

/**
 * hideFAQ
 * Hides the previously opened question/answer, so there is always 
 * only one question opened on the page
 * 
 * @return void
 */
function hideFAQ(){
	if (old_item != undefined && old_item.hasClass('faq_active_item')) {
		old_item.removeClass('faq_active_item');
	}
	
	if (old_answer != undefined){
		old_answer.hide();
	}
}
