// JavaScript Document
if (Drupal.jsEnabled) {
	$(function(){
		var isCalculating = false;
		var button = $('#btn-quiz-calculate-1');
		var table = $('#truth-exam table');
		button.click(function(){
			button.attr('disabled', true);
			table.fadeTo('fast', .2);
			if (!isCalculating) {
				var pb = new Drupal.progressBar('myProgressBar');
			  $('#result').parent().append(pb.element);
				isCalculating = true;
			}      
			setTimeout(function(){
				$('.question:has(input[value=false]:not(:checked).is-a-correct-answer) span').html('It really is false.');
			  $('.question:has(input[value=true]:not(:checked).is-a-correct-answer) span').html('It really is true.');
			  var score = $('.question:has(:checked.is-a-correct-answer) span').empty().size();
			  $('.question').not(':has(:checked)').find('span').html('Make a selection');
			  var plural = (score > 1) ? 'answers' : 'answer';
			  if (score == 10) {
				  $('#result').addClass('perfect-score');
			  }
			  else {
				  $('#result').removeClass('perfect-score');
			  }
			  $('#result').html('You got ' + score + ' correct ' + plural + '.');
				$('.progress').remove();
				isCalculating = false;
				table.fadeTo('fast', 1);
				button.attr('disabled', false);
			}, 500);
			return false;
		});
	});
}
