$(function () {
	function randomise(a, b) {
		return 0.5 - Math.random();
	}
	function makeArrayOfNumbers(length) {
		var output = [];
		for (var i = 0; i < length; i += 1) {
			output.push(i);
		}
		return output;
	}
	function showFact() {
		$("#fact img").hide();
		$("#fact img:eq(" + facts[fact] + ")").fadeIn("slow");
		fact += 1;
		if (fact === $("#fact img").length) {
			fact = 0;	
		}
		setTimeout(showFact, 10000);
	}
	
	function printClipping() {
		window.print();
		$("link[title=clipping]").attr("disabled", "disabled");	
	}
	var fact = 0;
	var facts = makeArrayOfNumbers($("#fact img").length).sort(randomise);
	showFact();
	$("#quiz #content input:radio").click(function () {
		if ($("#quiz #content input:radio:checked").length === 10) {
			$("#quiz #content input:submit").attr("disabled", false);
		}
	});
	$("#print-clipping").click(function () {
		window.open("/questions.asp","questions","scrollbars=1,width=800,height=600,toolbar=0,menu=0,status=1");
	});
	$("#game").click(function () {
		window.open(this.href, "game", "width=468,height=350,menu=0,scrollbars=0,statusbar=0");
		return false;
	});
});