$(document).ready(function(){
	var answer = $("#defenceAnswer");
	if ($("#defenceQuestion").length) {
		var action = new Array ('+', '-', '*');
		var questionResult = null;
		var firstNum = Math.round(3*Math.random()) + 1;
		var secondNum = Math.round(3*Math.random()) + 1;
		var actionTrigger = Math.round(2*Math.random());

		

		while ((firstNum - secondNum) < 0) {
			firstNum = Math.round(3*Math.random()) + 1;
			secondNum = Math.round(3*Math.random()) + 1;
		}
		
		var quest = firstNum + ' ' + action[actionTrigger] + ' ' + secondNum;
		answer.keyup(checkAnswer);
		
		var questLabel = $("#defenceQuestion").html();
		
		$("#defenceQuestion").html(questLabel.replace(/6\s+\+\s+5/,quest) + ' = ');
		
		$.cookie('defenceNumber', eval(quest),{path: '../../../../default.htm'});
	}
	
});


function checkAnswer() {
	
		if ($(this).val() == $.cookie('defenceNumber')) {
			$(this).addClass("valid").removeClass("invalid");
		}
		else {
			$(this).removeClass("valid").addClass("invalid");

		 }
	}