var answerAr = new Array(); // store the answser id
var answerValAr = new Array(); // store the answser value
var questionAr = new Array(); // store the question
var questionsAmount = 3;
$(document).ready(function(){	
	$("#frage_1").hide();
	$("#frage_2").hide();
	
	$("#answer_010").hide();
	$("#answer_101").hide();
	$("#answer_").hide();
	
	$("#ihrErgebnis").hide();
	$("#ihrAntworten").hide();
	

	$("a[id^='q_']").click(function(){
		
		// item clicked
		var idQ = $(this).attr("id").slice(2, 3); // question id
		var idA = $(this).attr("id").slice(3, 4); // answer id
		var idO; // other anwser id
		
		if(idA == "0"){ idO = "1";}
		else{idO = "0";}
		// get the current item color
		var col = $(this).attr("class").split("_");
		// change the color of the other answer 
		$("a[id='q_"+idQ+idO+"']").attr("class", col[0]+"_"+idO);
		if(col[0] == "gelb"){ col[0] = "blau";}
		else{ col[0] = "gelb";}
		$(this).attr("class", col[0]+"_"+col[1]);
		
		// question answer speichern
		answerAr[idQ] 		= idA;
		answerValAr[idQ] 	= $("#frage_"+idQ).find("a[id='q_"+idQ+idA+"']").text();
		questionAr[idQ] 	= $("#frage_"+idQ).find("div[class='frage_hustentest']").text();
		
		// show next question
		var n = Number(idQ)+1;
		$("#frage_"+n).show();
		
		if(n == questionsAmount){
			showAnsers();
		}
					 
	});
	
});

function showAnsers(){
	
	//$(".answer").hide();
	$(".row_hustentest").hide();
	
	var res = answerAr[0]+answerAr[1]+answerAr[2];
	
	if(res != "010" && res != "101"){ res= "";} 
	$("#answer_"+res).show();
	$("#ihrErgebnis").show();
	$("#ihrAntworten").show();
	//alert(res);
	for(var i=questionsAmount-1; i >= 0; i--){
		var aText ="<p><strong>"+questionAr[i]+"</strong></p><p>&gt; "+answerValAr[i]+"</p>";
		$("#ihrAntworten").prepend(aText);
	}
	$("#ihrAntworten").prepend("<h4>Hier nochmal Ihre Antworten</h4>");
	
	
			
}