// JQuiz Quiz Javascript
// copyright 12th May 2003,

// THIS CODE IS CREATED BY THE FOLKS AT WEBSITEDESIGNERNC.COM 
// GO VISIT FOR ALL YOUR PROGRAMMING AND WEB DESIGN NEEDS!

jQuery(document).ready(function() {


	function goToByScroll(id){
		//jQuery('html,body').animate({scrollTop: jQuery("#"+id).offset().top},'slow');
	}

	var count = 0;	
	var howmanyquestions = jQuery("#jquiz > li").length;
	
	//the function for a clicked item
	jQuery("#jquiz li ul li").click(function(){
	
		if (!(jQuery(this).parent("ul").hasClass("answered"))) {
		
			// removes unanswered class and adds answered class so they cannot change answer
			jQuery(this).parent("ul").addClass("answered");
			
			// runs if they clicked the incorrect answer
			if (!(jQuery(this).hasClass("correct"))) {
				// puts strike-through wrong answer and makes their answer red for incorrect
				jQuery(this).addClass("wronganswer");
				jQuery(this).siblings(".correct").addClass("realanswer");
				// animate explanation & add styling depending on answer
				jQuery(this).parent().parent().children("div").prepend('<p>INCORRECT</p>');
				jQuery(this).parent().parent().children("div").addClass("wrongbox");
				jQuery(this).parent().parent().children("div").fadeTo(500, 1);
			}
			
			// runs if they clicked the correct answer
			if (jQuery(this).hasClass("correct")) {
				//adds one to quiz total correct tally
				count++;
				// makes correct answer green
				jQuery(this).addClass("correctanswer");
				// animate explanation & add styling depending on answer
				jQuery(this).parent().parent().children("div").prepend('<p>CORRECT</p>');
				jQuery(this).parent().parent().children("div").addClass("rightbox");
				jQuery(this).parent().parent().children("div").fadeTo(750, 1);
			}
			
			if (jQuery('ul.answered').length == howmanyquestions) {
				goToByScroll("quizremarks");
				jQuery('#jquizremarks').fadeIn('slow');
				jQuery('#jquiztotal').html('You got a '+count+' out of '+howmanyquestions+' on the quiz.');
			}
		}
		

		
	});

});
