function CountDown() {
    var random = Math.floor(Math.random()*11);
    var count = 5, tmID, infobox = document.getElementById("info"),start = document.getElementById("start"),a = document.getElementById("atari"+ random);


    function countDown() {
	if (--count == 0) {
	    infobox.innerHTML = "失敗";
	} else {
	    if (count >= 0){
	    infobox.innerHTML = count + "秒前";
	    tmID = setTimeout(countDown, 1000);
	    }}
    }
    function startCountDown() {
	tmID = setTimeout(countDown, 1000);
	a.removeEventListener("click", startCountDown, false);
	a.addEventListener("click", stopCountDown, false);
    }
    function stopCountDown() {
	clearTimeout(tmID);
	infobox.innerHTML = "あたり!";
	a.removeEventListener("click", stopCountDown, false);
	
    }
    start.addEventListener("click", startCountDown, false);
};
document.addEventListener("DOMContentLoaded", CountDown, false);
