

var dormantColor  = ['#ffffff', '', '', ''];
var activeColor   = ['#00a4a6', '', '', ''];
var colorRange    = new Array(3);
var colorFrames   = new Array(30);
var menuBList     = [];
for(var c = 0; c < 30; c++)
	colorFrames[c] = new Array(3);

function initIndex()
{
	if(dormantColor[0].length == 4)
	{
		dormantColor[1] = '0x' + dormantColor[0].substr(1, 1) + dormantColor[0].substr(1, 1);
		dormantColor[2] = '0x' + dormantColor[0].substr(2, 1) + dormantColor[0].substr(2, 1);
		dormantColor[3] = '0x' + dormantColor[0].substr(3, 1) + dormantColor[0].substr(3, 1);
	}
	else if(dormantColor[0].length == 7)
	{
		dormantColor[1] = '0x' + dormantColor[0].substr(1, 2);
		dormantColor[2] = '0x' + dormantColor[0].substr(3, 2);
		dormantColor[3] = '0x' + dormantColor[0].substr(5, 2);
	}
	if(activeColor[0].length == 4)
	{
		activeColor[1] = '0x' + activeColor[0].substr(1, 1) + activeColor[0].substr(1, 1);
		activeColor[2] = '0x' + activeColor[0].substr(2, 1) + activeColor[0].substr(2, 1);
		activeColor[3] = '0x' + activeColor[0].substr(3, 1) + activeColor[0].substr(3, 1);
	}
	else if(activeColor[0].length == 7)
	{
		activeColor[1] = '0x' + activeColor[0].substr(1, 2);
		activeColor[2] = '0x' + activeColor[0].substr(3, 2);
		activeColor[3] = '0x' + activeColor[0].substr(5, 2);
	}
	if(dormantColor[1] != '' && activeColor[1] != '')
	{
		colorRange[0] = parseInt(dormantColor[1]) - parseInt(activeColor[1]);
		colorRange[1] = parseInt(dormantColor[2]) - parseInt(activeColor[2]);
		colorRange[2] = parseInt(dormantColor[3]) - parseInt(activeColor[3]);
		for(var c = 0; c < 30; c++)
		{
			if(colorRange[0] > 0)
				colorFrames[c][0] = Math.round((parseInt(dormantColor[1], 16) - ((colorRange[0] / 30) * c)));
			else if(colorRange[0] < 0)
				colorFrames[c][0] = Math.round((parseInt(dormantColor[1], 16) + (((colorRange[0] * -1) / 30) * c)));
			else
				colorFrames[c][0] = parseInt(activeColor[1].substr(2, 2), 16);
			if(colorRange[1] > 0)
				colorFrames[c][1] = Math.round((parseInt(dormantColor[2], 16) - ((colorRange[1] / 30) * c)));
			else if(colorRange[1] < 0)
				colorFrames[c][1] = Math.round((parseInt(dormantColor[2], 16) + (((colorRange[1] * -1) / 30) * c)));
			else
				colorFrames[c][1] = parseInt(activeColor[2].substr(2, 2), 16);
			if(colorRange[2] > 0)
				colorFrames[c][2] = Math.round((parseInt(dormantColor[3], 16) - ((colorRange[2] / 30) * c)));
			else if(colorRange[2] < 0)
				colorFrames[c][2] = Math.round((parseInt(dormantColor[3], 16) + (((colorRange[2] * -1) / 30) * c)));
			else
				colorFrames[c][2] = parseInt(activeColor[3].substr(2, 2), 16);
			colorFrames[c][0] = colorFrames[c][0] < 16 ? '0' + colorFrames[c][0].toString(16) : colorFrames[c][0].toString(16);
			colorFrames[c][1] = colorFrames[c][1] < 16 ? '0' + colorFrames[c][1].toString(16) : colorFrames[c][1].toString(16);
			colorFrames[c][2] = colorFrames[c][2] < 16 ? '0' + colorFrames[c][2].toString(16) : colorFrames[c][2].toString(16);
		}
	}
}

function menuBOver(menuBID)
{
	var menuBLoc = -1;	// Holds the location in the array that is associated with the current button.
	for(var c = 0; c < menuBList.length; c++)
	{
		if(menuBList[c][0] == menuBID)
			menuBLoc = c;
	}
	if(menuBLoc == -1)
		menuBLoc = menuBList.push([menuBID, 1, 0, document.getElementById(menuBID), 0]) - 1;
	if(menuBList[menuBLoc][1] == 2)
		clearTimeout(menuBList[menuBLoc][4]);
	menuBList[menuBLoc][1] = 1;

	menuBOverAnimate(menuBLoc);
}

function menuBOut(menuBID)
{
	var menuBLoc = -1;	// Holds the location in the array that is associated with the current button.
	for(var c = 0; c < menuBList.length; c++)
	{
		if(menuBList[c][0] == menuBID)
			menuBLoc = c;
	}
	if(menuBLoc == -1)
		menuBLoc = menuBList.push([menuBID, 2, 0, document.getElementById(menuBID), 0]) - 1;
	if(menuBList[menuBLoc][1] == 1)
		clearTimeout(menuBList[menuBLoc][4]);
	menuBList[menuBLoc][1] = 2;
	
	menuBOutAnimate(menuBLoc);
}

function menuBOverAnimate(menuBLoc)
{
	if(menuBList[menuBLoc][1] == 1 && menuBList[menuBLoc][2] < 29)
	{
		menuBList[menuBLoc][3].style.color = '#' + colorFrames[(menuBList[menuBLoc][2] + 1)][0] + colorFrames[(menuBList[menuBLoc][2] + 1)][1] + colorFrames[(menuBList[menuBLoc][2] + 1)][2];
		menuBList[menuBLoc][2] += 1;
		if(menuBList[menuBLoc][2] < 29)
			menuBList[menuBLoc][4] = setTimeout('menuBOverAnimate("' + menuBLoc + '")', 33);
		else
			menuBList[menuBLoc][1] = 0;
	}
}

function menuBOutAnimate(menuBLoc)
{
	if(menuBList[menuBLoc][1] == 2 && menuBList[menuBLoc][2] > 0)
	{
		menuBList[menuBLoc][3].style.color = '#' + colorFrames[(menuBList[menuBLoc][2] - 1)][0] + colorFrames[(menuBList[menuBLoc][2] - 1)][1] + colorFrames[(menuBList[menuBLoc][2] - 1)][2];
		menuBList[menuBLoc][2] -= 1;
		if(menuBList[menuBLoc][2] > 0)
			menuBList[menuBLoc][4] = setTimeout('menuBOutAnimate("' + menuBLoc + '")', 33);
		else
			menuBList[menuBLoc][1] = 0;
	}
}