$(document).ready(function() {

	$(".question").css({ textDecoration: "none" }); // get rid of the underlines for the links
	$(".question").addClass("questionNormal"); // format all of the links
	$(".question").toggle(GetAnswer, HideAnswer);

	$(".question").hover(function() {
			$(this).not(".questionClick").not(".questionLoading").removeClass("questionNormal").end(); // remove the 'normal' state
			$(this).not(".questionClick").not(".questionLoading").addClass("questionHover").end(); // change the styling to show the 'hover' state
	}, function() {
			$(this).not(".questionClick").not(".questionLoading").removeClass("questionHover").end(); // remove the 'hover' state
			$(this).not(".questionClick").not(".questionLoading").addClass("questionNormal").end(); // change the styling to show the 'normal' state
	});
});

function GetAnswer()
{
	var qId = this.id.replace(/question_/, ""); // get the faq's answer
	$(this).prepend('<span class="loader"> Loading... </span>'); // show that we are loading the answer
	$(this).removeClass('questionNormal').addClass('questionLoading');

	$.get("/~d-elearn/faq/getFaq.php",{id: qId }, ShowAnswer);
}

function ShowAnswer(xml, textStatus)
{
	var id = "#question_" + $('id',xml).text();
	$(id).children('.loader').remove(); // remove the loader text
	$(id).after('<div class="answer">' + $('answer',xml).text() + '<div class="lastUpdated">Last updated: ' + $('edit_date',xml).text() + '</div></div>'); // create the answer's container
	$(id).siblings(".answer").hide(); // hide so we don't get a "flash" of conent before the animation happens
	//$(id).addClass("questionClick"); // change the answer to show that it was clicked on
	$(id).siblings(".answer").animate(
	{
			height: 'show',
			opacity: 'show'
	},"slow", "", function() {
		$(this).siblings('.questionLoading').removeClass('questionLoading').addClass('questionClick').end();
	}).addClass("answerShow").end(); //show the answer
}

function HideAnswer()
{
	$(this).removeClass("questionClick"); // remove the questionClick class
		$(this).siblings(".answer").animate(
		{// hide the answer
				height: 'hide',
				opacity: 'hide'
		},"slow","" , function() {
			$(this).remove(); // remove the answer
		}).end();
}