/* Gestion des questions */

function startTests() {
	courant = 1;
	total = $$('#test fieldset.question').length;
	if (total == 0) return;
	score = 0;
	redraw(courant, total);
	$('score').setProperty('value', appreciations[score]+ ' ('+score + '/'+total+')');
	$$('#test fieldset input[type=radio]').each( function(choix) {
		choix.addEvent('click', function() {
			//Afficher l'erreur
			eff = new Fx.Style(choix.parentNode, 'background-color', { duration: 200 });
			reponse = $(choix.name.replace('q','r')).getValue();
			if (choix.getValue() != reponse) {
				color = '#FF4700';//'#F00';
			} else {
				color = '#90EE90'; //'#0F0';
			}
			eff.start('#FFF', color).chain(
					function () {
						if (courant <= total) {
							if (choix.getValue() == reponse) { score++; }
							$('score').setProperty('value', appreciations[score]+ ' ('+score + '/'+total+')');
							courant++;
							redraw(courant, total);
						}
					} );
		});
	} );
}

function redraw(courant, total) {
	$$('#test fieldset.question').each( function(f) {
		if ((courant > total) || (f.getProperty('id') == 'question_'+courant)) {
			f.setStyle('display','block');
		} else {
			f.setStyle('display','none');
		}
	} );
	if (courant > total) location.hash = '#question_'+courant;
}

window.addEvent('domready', startTests);

