/*
	copyright 2003, Metin Hassan, All Rights Reserved
*/
var max_matrix = 6629
var black_ones = new Array()
var previous_num_dots = 0

function print_board()
{
	var str = "",i=0

	for(i=0;i<max_matrix;i++)
	{
		str+= "<span id="+i+"class=d></span>"
	}
	document.all.dotsGoHere.innerHTML=str
}

function make_dots(difficulty)
{
    var num_dots = 0
    var i = 0
    var randNum = 0
    var empty_array = new Array()

    document.all.dotsGoHere.style.visibility = "hidden"
    document.all.havealook.value = "Show Me"
    document.all.havealook.disabled = true

    do
    {
	num_dots = getRandNum(difficulty)
    }while(num_dots < .25*difficulty)

    previous_num_dots = num_dots

    for(i=0;i<black_ones.length;i++)
    {
        document.getElementById(black_ones[i]).style.background = '#dddddd'
    }

    black_ones = empty_array

    for(i=0;i<num_dots;i++)
    {
	do
	{
	    randNum = getRandNum(max_matrix)
	}while(document.getElementById(randNum).style.background == '#FF0000')
	
	document.getElementById(randNum).style.background = '#FF0000'
	black_ones[i] = randNum
    }
    move_curtain()
}

function getRandNum(factor)
{
    var num = Math.round(Math.random() * factor)
    return num
}

function move_curtain()
{
    var time = eval(document.all._time.value ) + 2000

    document.all.curtain.innerHTML = "<br><br><br><br><div align = 'center'><font size = '5'><b>Ready!</b></font></div>"
    setTimeout("document.all.dotsGoHere.style.visibility = 'visible'",2000)
    setTimeout("pullcurtain()",time)
    document.all.userAns.disabled = false
}

function pullcurtain()
{
    document.all.dotsGoHere.style.visibility = 'hidden'
    document.all.curtain.innerHTML = ""
}

function correct()
{
    if(document.all.userAns.value == previous_num_dots)
    {
    	document.all.curtain.innerHTML = "<br><br><br><br><div align = 'center'><font size = '4'><b>Well Done! You got it right!  &rarr; " + previous_num_dots +" dots</b></font></div>" 
    }
    else
    {
   	document.all.curtain.innerHTML = "<br><br><br><br><div align = 'center'><font size = '4'><b>WRONG! There were " + previous_num_dots + " dots</b></font></div>"
    }
    document.all.userAns.disabled = true
    document.all.havealook.disabled = false
}

function showme()
{
    if(document.all.dotsGoHere.style.visibility == "hidden")
    {
	document.all.dotsGoHere.style.visibility = "visible"
	document.all.havealook.value = "Hide"
    }
    else
    {
	document.all.dotsGoHere.style.visibility = "hidden"
	document.all.havealook.value = "Show Me"
    }
}
