// JavaScript Document
document.totScore = 0;
document.attempts = 0;
function turnOffButtons(id){
	for (var x=0;x<3;x++){
		var thisObj = document.getElementById("k"+id+"_"+x);
		thisObj.disabled = true;
	}
}
function userClick(obj){
	document.attempts++;
	var kid = obj.id.substring(1,obj.id.lastIndexOf("_"));
	var rid = obj.id.substring(obj.id.lastIndexOf("_")+1, obj.id.length);
	var ansArray = new Array(0,2,1,1,0,2,1,2,1,0,1,0,2,2,2,2,0,1,2,1,1,1,2,2,1,2,0,1,0,2,1,0,1,2,2,0);
	turnOffButtons(kid);
	obj.parentNode.style.background = "#f2c1c1 url(ex.gif) right center no-repeat"; //red
	var correctObj = document.getElementById("k"+kid+"_"+ansArray[kid]);
	if (ansArray[kid] == rid){
		document.totScore++;
		correctObj.parentNode.style.background = "#c5e1c7 url(tick.gif) right center no-repeat"; //green
		document.correctAns = true;
	} else {
		correctObj.parentNode.style.background = "#c5e1c7 url(arrow.gif) right center no-repeat"; //green
		document.correctAns = false;
	}
	document.pcScore = Math.round((Number(document.totScore)/document.attempts)*100);
	document.getElementById("score").innerHTML ="Score: "+document.pcScore+"% ("+document.totScore+" out of "+document.attempts+")";
	if(document.attempts == ansArray.length) finalScore();
	Fat.fade_all();
}
function  finalScore(){
	var feedback;
	document.getElementById("score").style.display = "none";
	if(document.totScore == 36){
		feedback = "Perfect! You really know your celebs.";
	} else if (document.totScore >= 34){
		feedback = "Excellent! Nearly a perfect score";
	} else if (document.totScore >= 28){
		feedback = "Very good score! Got a bit difficult near the end eh?";
	} else if (document.totScore >= 19){
		feedback = "Not bad! Over half right, can do better!";
	} else if (document.totScore >= 5){
		feedback = "You can do better than that!";
	} else {
		feedback = "Hmm. Not your area of expertise eh?";
	}
	var finalFB = "<h2>Final Score: "+document.pcScore+"% ("+document.totScore+" out of "+document.attempts+")</h2>";
	finalFB += "<h3>"+feedback+"</h3>";
	document.getElementById("finalScore").innerHTML = finalFB;
}
