var shades = new Array();
var g_h, g_w;
var timer_id = 0;
var sq_count = 0;
var MAX_SQUARES = 40;
var MS_GAP = 200;

function BlueSquareStart(w, h) {
    g_h = h;
    g_w = w;
    BlueSquareClearSquares();
    AddSquare();
    timer_id = setInterval("AddSquare()", MS_GAP);
}

function BlueSquareStopTimer() {
    clearInterval(timer_id);
    timer_id = 0;
}

function BlueSquareClearSquares() {
    var container = $("BlueSquareContainer");
    container.innerHTML = "";
    sq_count = 0;
}

function AddSquare()
{
    var container = $("BlueSquareContainer");
    var result = new Element("div");
    var idx;

    if (sq_count > MAX_SQUARES)
        BlueSquareClearSquares();
    
    if (shades.length == 0)
        MakeShades();
    idx = Math.round(shades.length * Math.random());
    if (idx > shades.length)
        idx = 0;    

    result.className = "BlueSquare";
    result.style.left = MakePx( Math.round( g_w * Math.random() ) );
    result.style.top = MakePx(Math.round(g_h * Math.random()));

    result.style.width = MakePx(40 + Math.round(60 * Math.random()));
    result.style.height = result.style.width;
    
    result.style.backgroundColor = shades[idx];
    container.appendChild(result);
    sq_count++;
}

function MakePx( x )
{
	return x + 'px';
}
function MakeShades() {
    var i = 0;
    shades = new Array();
    shades[i++] = "#0000ff";
    shades[i++] = "#1111ff";
    shades[i++] = "#2222ff";
    shades[i++] = "#3333ff";
    shades[i++] = "#4444ff";
    shades[i++] = "#5555ff";
    shades[i++] = "#6666ff";
    shades[i++] = "#7777ff";
    shades[i++] = "#8888ff";
    shades[i++] = "#9999ff";
    shades[i++] = "#aaaaff";
    shades[i++] = "#bbbbff";
    shades[i++] = "#ccccff";
    shades[i++] = "#ddddff";
    shades[i++] = "#eeeeff";
}

function Sayuser(str) {
    $("SayuserMessage").innerHTML = str;
}