var correct = [1, 1, 1, 1, 1, 1, 1];
var answersLetters = ['А', 'Б', 'В'];
$(function() {
	// png fix for ie6
	$('.hint').supersleight({shim: 'images/blank.gif'});
	
	// submit
	$("#submit").click(function() {
		var answers = [0, 0, 0];
		$("#questions > li").each(function(qIndex, e) {
			e = $(e);
			var checked = e.find("input:checked");
			var aIndex = e.find("input").index(checked);
			if (aIndex > -1) {
				answers[aIndex]++;
			}
			e.find("div:not(.hint)").remove();
			e.find("label").removeClass("true false");
			if (aIndex == correct[qIndex]) {
			} else {
				if (aIndex > -1) {
					checked.after($("<div>").addClass('fail'));
					e.find("label").eq(aIndex).addClass("false");
				}
			}
			e.find("input").eq(correct[qIndex]).after($("<div>").addClass('ok'));
			e.find("label").eq(correct[qIndex]).addClass("true");
			
		});
		var result = '';
		var max = 0, maxIndex = -1, maxCount = 0;
		jQuery.each(answers, function(index, e) {
			result += answersLetters[index] + ': ' + e + ' бр.';
			if (e > max) {
				max = e;
				maxIndex = index;
			}
		});
		jQuery.each(answers, function(index, e) {
			if (max == e) {
				maxCount++;
			}
		});
		$("#stats").html(result);
		$("#text div").removeClass("highlight");
		if (maxIndex > -1 && maxCount == 1) {
			$("#text div").eq(maxIndex).addClass("highlight");
		}
		$(".hint").show();
		$("#results").slideDown();
	});
});

