//Global Variables
var int_id;
var currentTime=0;
var numWords = 618;
var started = false;

function toggleTimer(){
	if(started == true){
		stopTimer();	
	}
	//This initiates the start timer if its not already running
	else{ 
		document.getElementById('startButton').value = 'Stop';
		document.getElementById('endButton').value = 'Stop';
		int_id = window.setInterval("updateTime()", 1000);
		started = true;
		timeStr = '00:00';
		document.getElementById('startBox').value = timeStr;
		document.getElementById('timeBox').value = timeStr;
	}
}

function updateTime(){
	//works out the wpm by counting
	currentTime+=1;
	mins = "0"+Math.floor(currentTime/60);
	secs = "0"+(currentTime%60);
	timeStr = mins.substr(mins.length-2) + ":" + secs.substr(secs.length-2);
	document.getElementById('startBox').value = timeStr;
	document.getElementById('timeBox').value = timeStr;
}

function stopTimer(){
	//Stops the clock and resets the timing and button values
	document.getElementById('startButton').value = 'Restart';
	document.getElementById('endButton').value = 'Restart';
	window.clearInterval(int_id);
	wpm = Math.round(numWords / currentTime * 60);
	document.getElementById('wpmBox').value = wpm;
	started = false;
	currentTime = 0;
}
