// JavaScript Document

var secs
var timerID = null
var timerRunning = false
var delay = 1000
var bid = 0

// Random number generator

function rnd(max) {
  var rndnum = max * Math.random()
  rndnum = Math.ceil (rndnum)
  return rndnum
} 

function InitializeTimer(timeout)
{
    // Set the length of the timer, in seconds
    secs = timeout
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        boxid = rnd(6)
				if(bid > 0) { Effect.toggle('box' + bid,'appear',{duration:2}); }
				Effect.toggle('box' + boxid,'appear',{duration:2})
				bid = boxid
				secs = 6
				timerRunning = true
				timerID = self.setTimeout("StartTheTimer()", delay)
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}