var menuTimers = new Array();
var handle_z_ids = new Array();
function menuSwitch(id, mode, force, col)
{
	var div = document.getElementById(id);
	var debug = document.getElementById('debug');
	if (menuTimers[id] == null)
	{
		menuTimers[id] = 0;
		handle_z_ids.push(id)
	}
	if (mode == 'hide')
	{
		menuTimers[id] = setTimeout(function () {
			hideMenu(div, col);
		},
		500);
		debug.innerHTML = 'Hide: ' + id + ' New ID: ' + menuTimers[id] + '<br />' + debug.innerHTML
	}
	else
	{
		if (div.style.display != 'none' || force == 'open')
		{
			clearTimeout(menuTimers[id]);
			hideOthers(id, col);
			setBoxTop(id)
			showMenu(div, col);
			debug.innerHTML = 'Show: ' + id + ' Cleared ID: ' + menuTimers[id] + '<br />' + debug.innerHTML
		}
	}
}
function hideOthers(id, col)
{
	for (i = 0; i < handle_z_ids.length; i++)
	{
		if (id != handle_z_ids[i])
		{
			hideMenu(_(handle_z_ids[i]), col);
		}
	}
}
function hideMenu(menu, col)
{
	if (menu.style.display != 'none')
	{
		new Effect.Fade(menu, {duration: 0.25});
		document.getElementById(col).className = "menyy1";
	}
}
function showMenu(menu, col)
{
	if (menu.style.display == 'none')
	{
		new Effect.Appear(menu, {duration: 0.25});
		/*document.getElementById('table_col_1').style.backgroundColor = "#E95E0F";*/
		document.getElementById(col).className = "menyy5";
	}
}
function _(id)
{
	return document.getElementById(id);
}
function setBoxTop(target)
{
	if (null == target || 0 == target.length)
	{
		return;
	}

	//	Initialize.
	var z = new Array();
	var ids_relation = new Array();
	var start = 5;

	//	Load.
	for (i = 0; i < handle_z_ids.length; i++)
	{
		var z_index = _(handle_z_ids[i]).style.zIndex;
		z.push(z_index);
		ids_relation[z_index] = handle_z_ids[i];

		_('debug').innerHTML += handle_z_ids[i] + ': ' + z_index + '<br />';
	}
	z.sort(function(a,b){return a - b});

	_('debug').innerHTML += '<br />';

	//	Set.
	for (i = 0; i < z.length; i++)
	{
		if (ids_relation[z[i]] == target)
		{
			ids_relation[z[i]] = null;
			z[i] = z[z.length - 1] * 1 + 1;
			ids_relation[z[i]] = target;
			break;
		}
	}
	z.sort(function(a,b){return a - b});

	//	Save.
	for (i = 0, j = start; i < z.length; i++, j++)
	{
		_(ids_relation[z[i]]).style.zIndex = j;
		_('debug').innerHTML += ids_relation[z[i]] + ': ' + j + '<br />';
	}
	_('debug').innerHTML += '<hr />';
}