jQuery(function($) {
	
	var $correctAnswers = 0;
	
	// hide all questions
	$('.hsbcquiz').hide();
	
	// show the first question
	$('#q1').show();
	
	// show the 'check answer' button when a selection is made
	/*$("input:radio").click(function() {
		$(".hsbcquiz:visible > fieldset > .checkAnswer").show();
	});*/

	
	// attach a function to each 'check answer' button click
	$('.check').click(function() {
		
		
		// increment correct answer counter if answer was correct
		if ($("input:checked").val() == "true") {
			$correctAnswers++;
			$("#correctAnswers").empty().append($correctAnswers);
			$(".hsbcquiz:visible > fieldset > .checkAnswer > #error").hide("fast");
			$(".hsbcquiz:visible > fieldset > #quiz_answer_correct").addClass("correctAnswer");
			$(".hsbcquiz:visible > fieldset > #quiz_answer_correct").slideDown("normal");
			
			// disable radio buttons to prevent changing selection
			$("input[@type='radio']").attr("disabled", true);
			// show 'next question' button & hide the 'check answer' button
			$(this).siblings(".next").show();
			$(this).hide();

		}
		else if ($("input:checked").val() == "false1") {
			$(".hsbcquiz:visible > fieldset > .checkAnswer > #error").hide("fast");
			$(".hsbcquiz:visible > fieldset > #quiz_answer_wrong1").addClass("wrongAnswer");
			$(".hsbcquiz:visible > fieldset > #quiz_answer_wrong1").slideDown("normal");
			
			// disable radio buttons to prevent changing selection
			$("input[@type='radio']").attr("disabled", true);
			// show 'next question' button & hide the 'check answer' button
			$(this).siblings(".next").show();
			$(this).hide();
		}
		else if ($("input:checked").val() == "false2") {
			$(".hsbcquiz:visible > fieldset > .checkAnswer > #error").hide("fast");
			$(".hsbcquiz:visible > fieldset > #quiz_answer_wrong2").addClass("wrongAnswer");
			$(".hsbcquiz:visible > fieldset > #quiz_answer_wrong2").slideDown("normal");
			
			// disable radio buttons to prevent changing selection
			$("input[@type='radio']").attr("disabled", true);
			// show 'next question' button & hide the 'check answer' button
			$(this).siblings(".next").show();
			$(this).hide();
		}
		
		else {
			$(".hsbcquiz:visible > fieldset > .checkAnswer > #error").show("fast");
			
		}
		
		
	});
	
	// attach a function to each next button click
	$('.next').click(function() {
		var $currentQuestion = $(".hsbcquiz:visible");
		var $nextQuestion = $(".hsbcquiz:visible").next(".hsbcquiz");
		$("input[@type='radio']").attr("checked", false);
		$("input[@type='radio']").attr("disabled", false);
		
		if ($(this).attr("id") == "finalQuestion") {
			$("#quizHeader").append(" Results");
			$("#summary").show();
			// set summary message display
			if (($correctAnswers <= 1) && ($correctAnswers <= 3)) {
				$("#low").show();
			}
			if (($correctAnswers >= 4) && ($correctAnswers < 6)) {
				$("#medium").show();
			}
			if ($correctAnswers >= 6) {
				$("#high").show();
			}
		} else {
			$nextQuestion.show();
		}
		$currentQuestion.hide();
	});
});

