// JavaScript Document
var answerArray = [2,1,1,1,2,1,2,1,2,1];
var numberOfQuestions = 10;
var currentQuestion = 0;
var numberRight = 0;
var numberWrong = 0;

jQuery(".quiz-choice").click(checkAnswer);

jQuery(".quiz-results").hide();
jQuery(".quiz-hint").hide();
jQuery("#quiz-final-results").hide();

function checkAnswer(){
	var questionID = jQuery(this).parent().parent().attr('id');
	var currentQuestion = parseInt(questionID.replace("quiz-question-","")) - 1;
	
	switch(answerArray[currentQuestion]) {
    case 1:
        var correctAnswer = "choice-a";
        break;
    case 2:
        var correctAnswer = "choice-b";
        break;
	case 3:
        var correctAnswer = "choice-c";
        break;
	case 4:
        var correctAnswer = "choice-d";
        break;
}
console.log(correctAnswer);
if(jQuery(this).attr('class').indexOf(correctAnswer) > -1){
	jQuery(this).parent().children().addClass("quiz-locked-choice");
	jQuery(this).parent().parent().addClass("quiz-question-right");
	jQuery(this).addClass("quiz-correct-choice");
	numberRight++;

}
else{
	jQuery(this).parent().children().addClass("quiz-locked-choice");
	jQuery(this).parent().parent().addClass("quiz-question-wrong");
	jQuery(this).addClass("quiz-incorrect-choice");
	jQuery(this).siblings(".quiz-" + correctAnswer).addClass("quiz-correct-choice");
	numberWrong++;
}
jQuery(".quiz-locked-choice").unbind("click");
jQuery(this).parent().siblings(".quiz-hint").show();

if(numberRight + numberWrong == numberOfQuestions){
	jQuery("#quiz-number-right").html(numberRight + " out of " + numberOfQuestions + " right");
	jQuery("#quiz-final-results").show();

	jQuery('html, body').animate({
        scrollTop: jQuery("#quiz-final-results").offset().top -200
    }, 2000);
}
}