var tim;
var tim2;
var tim3;
var previousLayer = "";
var open_sub_layer = "";
var timeout_time = 300;

function showLayer(id) 
{
//	alert("trying to show " + id);
	var div = returnDiv(id);
	div.visibility = "visible";
}

function hideLayer(id) 
{
//	alert("trying to hide " + id);
	var div = returnDiv(id);
	div.visibility = "hidden";
//		previousLayer = "";
}
 
var previousSection = "-1";
var previousSubSection = "-1";

function mouseIntoSection(section)
{
	if(tim)
		clearTimeout(tim);

	if(section != previousSection)
	{
		if(previousSection != "-1")
			hideSection(previousSection);
		for(i=0; i<layerSections[section]; i++)
			showLayer("menu_" + section + "_" + i);
	}
		
	previousSection = section;
}

function mouseIntoSubSection(subSection)
{
	if(tim3)
		clearTimeout(tim3);

	if(subSection != previousSubSection)
	{
		if(previousSubSection != "-1")
			hideSubSection(previousSection);
		for(i=0; i<layerSections[subSection]; i++)
			showLayer("menu_" + subSection + "_" + i);
	}
		
	previousSubSection = subSection;
}

function mouseOutOfSection(section)
{
	func = "hideSection('"+section+"')";
	tim = setTimeout(func, timeout_time);
}

function mouseOutOfSubSection(subSection)
{
	func = "hideSubSection('"+subSection+"')";
	tim3 = setTimeout(func, timeout_time);
}

function hideSection(section)
{
	for(i=0; i<layerSections[section]; i++)
		hideLayer("menu_" + section + "_" + i);
		
	previousSection = "-1";
}

function hideSubSection(subSection)
{
	for(i=0; i<layerSections[subSection]; i++)
		hideLayer("menu_" + subSection + "_" + i);
		
	previousSubSection = "-1";
}

function mouseOverLayer(section,id)
{
	var div = returnDiv("menu_" + section + "_" + id);
	div.bgColor = "#101084";
	div.backgroundColor = "#101084";
	div.color = "#ffffff";
}

function mouseOutOfLayer(section,id)
{
	var div = returnDiv("menu_" + section + "_" + id);
	div.bgColor = "#C6C7C6";
	div.backgroundColor = "#C6C7C6";
	div.color = "#000000";
}

function returnDiv(id) {
	if (document.all) // IE
	{
		var div = document.all(id).style;
	}
	else if (document.layers) // NS4
	{
		var div = document.layers[id];
	}
	else if (document.getElementById) // NS6
	{
		var div = document.getElementById(id).style;
	}
	return div;
}
