/** index_js: Animations for main page. **/

var colors = Array ('#000080', '#000070', '#000060', '#000050', '#000040','#000030','#000020','#000010','#000000');
var count=0;
var loop=false;
var mutex=false;
var willLoop = false;
var currBox = "";


function next_color()
{
	willLoop = false;
	if(!loop)
		return;
	count++;

	for(i=0; i<5; i++)
	{
		document.getElementById('m' + i + '0').style.backgroundColor = colors[(count + i)%9];
		document.getElementById('m' + i + '0').style.visibility="visible";
		document.getElementById('m' + i + '1').style.backgroundColor = colors[(count + i)%9];
		document.getElementById('m' + i + '1').style.visibility="visible";
	}
	window.setTimeout('next_color();', 125);
	willLoop = true;
}

/* Function to turn select the current box. */
function SelectBox(name)
{
	/* If already selected, deselect it. */
	if(name == currBox)
	{
		document.getElementById(currBox).style.display = 'none';
		currBox = "";
		no();
	}
	else
	{
		/* If something else is selected, deselect it. */
		if(currBox != "")
			document.getElementById(currBox).style.display = 'none';
		
		currBox = name;
		document.getElementById(currBox).style.display = 'block';
		SelectiveEnable();
	}
}

/* Function to disable highlights iff no box is selected. */
function SelectiveDisable()
{
	if(currBox == "") no();
}

/* Function to enable highlights iff not already highlit. */
function SelectiveEnable()
{
	if(!loop) yes();
}

function yes()
{
	loop=true;
	count=4;
	if(mutex == false && willLoop == false)
	{
		next_color();
		mutex = true;
	}
}
function nullity(){}
function no()
{
	for(i=0; i<5; i++)
	{
		document.getElementById('m' + i + '0').style.backgroundColor = '#000000';
		document.getElementById('m' + i + '1').style.backgroundColor = '#000000';
		document.getElementById('m' + i + '0').style.visibility="hidden";
		document.getElementById('m' + i + '1').style.visibility="hidden";
	}
	loop = false;
	mutex=false;
	window.setTimeout('nullity();', 1);
}


function initialize()
{
	if(document.getElementById)
	{
		next_color();
	}
}
