/* Variables */
var divid = 0, questions = "", answers = "";
function showAnswer(divid) {
	$("div.answer[set=" + divid + "]").appendTo("div.set[set=" + divid + "]").slideToggle();
}
$(document).ready(function(){ 
	$.ajaxSetup({ cache: false });
	$.get(xmlFile, {}, function(xml){
		/*agentName = $('agentInfo', xml).attr('agentName');*/

		$("C", xml).each(function(i) {
			catName = 	$(this).attr('name');
			lastQuestion = "";
			breakAt = new Array();

			$("S", this).each(function(s) {
				questions += "<div class=\"set\" set=\"" + divid + "\">";

				$("Q", this).each(function(q) {
					currentQuestion = $(this).text().replace(/.*?:/,'');
					if (lastQuestion != currentQuestion) { 
						questions += "<div class=\"question\" set=\"" + divid + "\" onclick=\"showAnswer("+divid+")\">";
						questions += "<p>&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"http://www.aoox.com/question.png\"> " + currentQuestion + "</p>";
						questions += "</div>";
						breakAt.push(s);
					}
					lastQuestion = currentQuestion;
				});
				
				$("A", this).each(function(a) {
					answers += "<div set=\"" + breakAt[breakAt.length-1] + "\" onclick=\"showAnswer("+breakAt[breakAt.length-1]+")\" class=\"answer\" style=\"display:none\"><div style='margin-left: 50px'><img src=\"http://www.aoox.com/answer.png\"> " + $(this).text() + "</div></div>";
				});

				divid++;
				questions += "</div>";

			});
		});

		$("#questions").html(questions);
		$("#answers").html(answers);
		
	});
});

function viewAllTopics() {
	$("div.question").trigger('click');
	$("div.answer").slideDown();
	$(".collapseAllTopics").show();
}

function collapseAllTopics() {
	$("div.question").trigger('click');
	$("div.answer").slideUp();
}

