// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


function start_countdown() {
	remain = 300;
	messages = {
	    300: "Ok, name this tune!",
	    150: "You have 15 seconds left!",
	    100: "What is it? What is it?",
	    50: "5 seconds left, take a guess!",
	    0: "Time is up, you fail."
	  }

	window.setTimeout(function() { new Effect.Appear('choices'); }, 300);

	var timer = setInterval( function () {
		if (remain > 300) remain = 1; // h4x0r!
		$('countdown').innerHTML = "<span>" + remain + "</span> points";
		if (messages[remain]) { $('notifier').innerHTML = messages[remain]; new Effect.Shake('notifier'); }
		$('points').value = remain;
		remain--;
		if (remain < 0) { 
			clearInterval(timer); 
			$('choices').hide();
			window.setTimeout(function() {location.href='/game/timeout'; }, 3000);
		}
	},100);
}



function soundPlay(src) {
//	soundStop();
	soundEmbed = document.createElement("embed");
	soundEmbed.setAttribute("src", src);
	soundEmbed.setAttribute("hidden", true);
	soundEmbed.setAttribute("autostart", true);
	soundEmbed.setAttribute("volume", "25");
	document.body.appendChild(soundEmbed);
}
			
function soundStop() {
	if ( soundEmbed ) {
		document.body.removeChild(soundEmbed);
		soundEmbed = null;
	}
}
