//à l'init de la page
$(document).ready(function () {
	$(".answer").show();
	$(".response").hide();
	//start du compteur
	timerStart('counter');
	
	$("#solution").click(function () {
		// stop compteur
		if ($("#results").is(":hidden")) {
			timerStop('counter');
			$("#time_elapsed").text($("#counter").val());
			$("#results").slideDown("slow");
		}
		var errors	= solutionShow();
		$("#errors span").text(errors+'');
		if(errors > 0) $("#errors").show();
		else $("#errors").hide();

	});
	
	$("#solution").mouseout(function () {
		solutionHide();
	});
	
});



function solutionShow() {
	$(".answer").hide();
	$(".response").show();
	
	var tabAnswer	= new Array();
	var tabResponse	= new Array();
	var tabError	= new Array();
	
	$('.answer').each(function(i){		
		var id	= this.id.substring((this.id.length-2));
		tabAnswer[id]	= this.value+'';		
	});
	$('.response').each(function(i){
		var id	= this.id.substring((this.id.length-2));
		tabResponse[id]	= this.innerHTML+'';
	});
	
	for(id in tabResponse) {		
		if(tabResponse[id] != tabAnswer[id]) {
			tabError[id]	= true;
			$('#response' + id).css('color', 'red');
			$('#case' + id).css('color', 'red');
		}
		else $('#case' + id).css('color', 'green');
	}
	var errors	= 0;
	for(id in tabError) errors++;
	return errors;
}

function solutionHide() {
	$(".answer").show();
	$(".response").hide();
}

