/**
 * Inicializando variaveis globais
 */
var tMin;
var tSeg;
var mam;

/**
 * Relógio de tempo que retorna a hora formatada da partida.
 * 
 * @return string
 */
function updateClock(){
	// --------------------------
	// Incrementa minuto/segundo
	// --------------------------
	if (tSeg++ >= 60){
		tMin++;
		tSeg = 0;
	}
	// ------------------------------------------
	// Concatena minuto/segundo no formato mm:ss
	// ------------------------------------------
	var tempSeg = (tSeg < 10) ? "0" + tSeg : tSeg;
	var tempMin = (tMin < 10) ? "0" + tMin : tMin;
	// --------------------------
	// Substitui valor do objeto
	// --------------------------
	$('relogio').value = tempMin + ":" + tempSeg;
}

/**
 *  Inicia/Pausa narração.
 */
function clock(){
	if ($('play').value == "Play") {
		if (confirm('Deseja realmente iniciar o jogo?')) {
			$('play').value = "Pause";
			mam = setInterval("updateClock()", 1000);
		}	
	} else {
		if (confirm('Deseja realmente pausar o jogo?')) {
			$('play').value = "Play";
			mam = clearInterval(mam);
		}
	}
}

/**
 * Seta as informações de um tempo
 * 
 * @param {Object} tempo
 * @return void
 */
function setTempo(tempo){
	if (tempo == 1) {
		$('relogio').value = "00:00";
		$('1t').disabled = true;
		$('2t').disabled = true;
		$('play').disabled = false;
		$('restart').disabled = false;
		$('play').value = "Play";
		tMin = 0;
		tSeg = 0;							
	} else {
		$('relogio').value = "45:00";
		$('1t').disabled = true;
		$('2t').disabled = true;
		$('play').disabled = false;
		$('restart').disabled = false;
		$('play').value = "Play";
		tMin = 45;
		tSeg = 0;				
	}
}

/**
 * Reinicia contador de tempo
 * 
 * @return void
 */
function resetTempo(){
	if (confirm('Deseja realmente reiniciar as configurações de tempo?')) {
		$('relogio').value = "00:00";
		$('1t').disabled = false;
		$('2t').disabled = false;
		$('play').disabled = true;
		$('restart').disabled = true;
		mam = clearInterval(mam);
		tMin = 0;
		tSeg = 0;
	}
}

