function timer()
{
	this.count = 16;
	this.answers = 5;
	this.opacity = 10;
}
timer.prototype.countdown=function()
{
	this.count -= 1;
	
	if (this.count >= 0)
	{
		setTimeout('timer.countdown()',1000);
	}
	else 
	{
		if (typeof ajaxobj != 'undefined' && ajaxobj.isAnswered != true)
		{
			ajaxobj.isAnswered = true;
			timer.hideAllAnswers();
			setTimeout("timer.timeElapsed()",2000);
		}
		return null;
	}
}
timer.prototype.timeElapsed=function()
{
	
}

timer.prototype.hideAllAnswers=function()
{
	var td = document.getElementsByTagName('TD');
	
	this.endGame();
		
	this.answers = new Array();
	
	for (i=0;i<td.length;i++)
	{
		if (td[i].id.toString().match(/A[0-9]+Text$/))
		{
			this.answers.push(td[i].id.replace(/[^0-9]/gi,''));
		}
	}
	
	this.fadeOutAnswers();
}
timer.prototype.fadeOutAnswers=function()
{
	this.opacity = 10;
	
	if (this.answers.length > 0)
	{
		var elm = this.answers.pop();
	
		this.fadeOut('A'+elm+'Text',0,function() { timer.fadeOutAnswers() })
	}
}

timer.prototype.endGame=function()
{
	document.getElementById('flashclock').innerHTML = '';
	document.getElementById('endgame').style.display='block';
}
timer.prototype.closeEndGameWindow=function()
{
	document.getElementById('endgame').style.display='none';
}

timer.prototype.hideAnswers=function( answer, _corr)
{
	this.opacity = 10;
	
	var answer_id = answer.id;

	
	this.fadeOut(answer_id,_corr,function(answer_id,_corr) 
		{
			var topOffset = 0;
			
			var user_answer_id = parseInt(answer_id.match(/[0-9]+/));
			
			 if (answer_id.length > 0)
			 {
			 	 if (_corr === user_answer_id)
			 	 {
			 	 	switch(_corr)
			 	 	{
			 	 		case 1: topOffset = 20;
			 	 			break;
		 	 			case 2: topOffset = 85;
		 	 				break;
		 	 			case 3: topOffset = 148;
			 	 			break;
		 	 			case 4: topOffset = 210;
			 	 			break;
			 	 	}
			 	 	
			 	 	var cbox = document.getElementById('correct');
			 	 	var ctxt = document.getElementById('correct_text');
			 	 	ctxt.innerHTML = document.getElementById('A' + _corr + 'Text').innerHTML;
			 	 	cbox.style.top = topOffset + 'px';
			 	 	cbox.style.display = 'block';
			 	 	
			 	 }
			 	 else 
			 	 {
			 	 	/* Show both correct and incorrect answers */
			 	 	switch(user_answer_id)
			 	 	{
			 	 		case 1: topOffset = 20;
			 	 			break;
		 	 			case 2: topOffset = 85;
		 	 				break;
		 	 			case 3: topOffset = 148;
			 	 			break;
		 	 			case 4: topOffset = 210;
			 	 			break;
			 	 	}
			 	 	
			 	 	var cbox = document.getElementById('wrong');
			 	 	var ctxt = document.getElementById('incorrect_text');
			 	 	ctxt.innerHTML = document.getElementById('A' + user_answer_id + 'Text').innerHTML;
			 	 	cbox.style.top = topOffset + 'px';
			 	 	cbox.style.display = 'block';
			 	 	
			 	 	/* Show the correct answer anyway */
			 	 	
			 	 	switch(_corr)
			 	 	{
			 	 		case 1: topOffset = 20;
			 	 			break;
		 	 			case 2: topOffset = 85;
		 	 				break;
		 	 			case 3: topOffset = 148;
			 	 			break;
		 	 			case 4: topOffset = 210;
			 	 			break;
			 	 	}
			 	 	
			 	 	
			 	 	var cbox = document.getElementById('correct');
			 	 	var ctxt = document.getElementById('correct_text');
			 	 	ctxt.innerHTML = document.getElementById('A' + _corr + 'Text').innerHTML;
			 	 	cbox.style.top = topOffset + 'px';
			 	 	cbox.style.display = 'block';
			 	 	
			 	 	
			 	 }
			 }
		});	
	return false;
}
timer.prototype.fadeOut=function( answer_id, _corr, callback )
{
	this.opacity -= 0.5;
	
	var answer = document.getElementById(answer_id);
	
	answer.style.opacity = this.opacity/10;
	answer.style.filter = 'alpha(opacity=' + this.opacity * 10 + ')';
	
	if (this.opacity > 0) 
	{
		setTimeout('timer.fadeOut("'+ answer_id +'",' + _corr + ',' + callback + ')',10);
	}
	else 
	{
		callback(answer_id,_corr);
	}
	
	return false;
}

var timer = new timer();