var doTimeOut = false;
var timeOutID;
var timeOut = 400;
var lastFlyingObj = null;
var lastFlyingColor = null;

//Top Menu: About, Patent...
function topMenuOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	//hideAllMainPageWithoutInitializeLastFlying();
	hideAllMainPage();
	hideAllHumiPage();
	hideAllValvPage();
	topMenuOver(theMenu);
}
function topMenuOutWithTimer(theMenu)
{
	timeOutID = setTimeout('hideAllMainPage()',timeOut);
}

//Top Flying Menus
function topFlyingMenuOverWithTimer(theMenu)
{
	colorBack();
	topFlyingMenuOver(theMenu);
}
function topFlyingMenuOutWithTimer(theMenu)
{
	colorBack();
}

function topFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	topFlyingOver(theMenu);	
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}
function topFlyingOutWithTimer(theMenu)
{
	topFlyingOut(theMenu);
	timeOutID = setTimeout('topFlyingOut("' + theMenu + '");hideAllMainPage()',timeOut);
}

//Keep Highlight of last column
function colorBack()
{
	if (lastFlyingObj != null && lastFlyingColor != null)
	{
		lastFlyingObj.style.backgroundColor = lastFlyingColor;
		lastFlyingObj = null;
		lastFlyingColor = null;
	}
}

//Left Menu: Humidificator, Actuator, Heater...
function leftMenuOverWithTimer(theMenu)
{	
	clearTimeout(timeOutID);
	hideAllMainPage();
	//hideAllMainPageWithoutInitializeLastFlying();
	leftMenuOver(theMenu);
}
function leftMenuOutWithTimer(theMenu)
{
	timeOutID = setTimeout('hideAllMainPage();',timeOut);
}

//Virtual Catalog and Selection Software
function leftFlyingMenuOverWithTimer(theMenu)
{
	setLv3BgColorMainPage();
	
	//Hide lv4 and lv5 flying menus when go back to lv2 flying menus
	hideLv4ValveMainFlyings();
	hideAllLv5ValveMainFlyings();
	
	leftFlyingMenuOver(theMenu);
}
function leftFlyingMenuOutWithTimer(theMenu)
{
	//alert("Hello");
	colorBack();
}

//Lv 3 flying menus
function lv3TableOverWithTimer(theMenu)
{
	//Initial lv4 flying column's background in case the cursor come from lv4 to lv3
	setLv4BgColorMainPage();
	lv3TableOver(theMenu);
}
function lv3TableOutWithTimer(theMenu)
{
	colorBack();
}

//Valve level3 flying menu
function lv3SSFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	lv3SSTableOver(theMenu);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}
function lv3SSTableOverWithTimer(theMenu)
{
	lv3SSTableOver(theMenu);
}
function lv3SSTableOutWithTimer(theMenu)
{
	colorBack();
	timeOutID = setTimeout('lv3SSTableOut("' + theMenu + '");hideAllMainPage()',timeOut);
}
function lv3SSTableOutWithTimer2(theMenu)
{
	colorBack();
	//timeOutID = setTimeout('lv3SSTableOut("' + theMenu + '");hideAllMainPage()',timeOut);
}

function lv4MainTableOverWithTimer(theMenu)
{
	setLv3BgColorMainPage();
	lv4MainTableOver(theMenu);
}
function lv4MainTableOutWithTimer(theMenu)
{
	colorBack();
}

function lv4ValveTableOverWithTimer(theMenu)
{
	lv4ValveTableOver(theMenu);
}
function lv4ValveTableOutWithTimer(theMenu)
{
	colorBack();
}

function lv5MainTableOverWithTimer(theMenu)
{
	lv5MainTableOver(theMenu);
}
function lv5MainTableOutWithTimer(theMenu)
{
	colorBack();
}

function lv5SubTableOverWithTimer(theMenu)
{
	//clearTimeout(timeOutID);
	lv5SubTableOver(theMenu);
}
function lv5SubTableOutWithTimer(theMenu)
{
	colorBack();
}

//TimeOut on Colomuns
function cataFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	cataFlyingOver(theMenu);
	flyingOut(theMenu.substring(0, theMenu.length - lv2Postfix[0].length) + lv2Postfix[1]);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}

function cataFlyingOutWithTimer(theMenu)
{
	//flyingOut(theMenu);
	timeOutID = setTimeout('cataFlyingOut("' + theMenu + '");hideAllMainPage();',timeOut);
}

function lv2SSFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	
	hideLv4ValveMainFlyings();
	hideAllLv5ValveMainFlyings();
	hideSSMenu();
	
	lv2SSFlyingOver(theMenu);
	flyingOut(theMenu.substring(0, theMenu.length - lv2Postfix[1].length) + lv2Postfix[0]);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}
function flyingOutWithTimer(theMenu)
{
	flyingOut(theMenu);
	timeOutID = setTimeout('flyingOut("' + theMenu + '");hideAllMainPage();',timeOut);
}

//For Controls level 2 flying menu
function flyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	flyingOver(theMenu);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}

function lv3FlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	//hideSSMenu();
	setLv3BgColorMainPage();
	hideLv4ValveMainFlyings();
	hideAllLv5ValveMainFlyings();
	
	lv3FlyingOver(theMenu);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}
function lv3FlyingOutWithTimer(theMenu)
{
	lv3FlyingOut(theMenu);
	timeOutID = setTimeout('lv3FlyingOut("' + theMenu + '");hideAllMainPage();',timeOut);
}


/* Flying Menu TimeOut function in Humidifiers' subpage */
function humiSubFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	
	inilializeTopLabels();
	hideAllTopFlyings();
	setLv2BgColorHumiPage();
	setLv3BgColorHumiPage();
	humiSubFlyingOver(theMenu);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}
function humiSubFlyingOutWithTimer(theMenu)
{
	document.getElementById(theMenu).style.background = lv2FlyingOutColor;
	//humiSubFlyingOut(theMenu);
	timeOutID = setTimeout('humiSubFlyingOut("' + theMenu + '");hideAllHumiPage();',timeOut);
}

function lv4HumiTableOverWithTimer(theMenu)
{
	//clearTimeout(timeOutID);
	lv4HumiTableOver(theMenu);
}
function lv4HumiTableOutWithTimer(theMenu)
{
	colorBack();
}

function humiSubTableOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	humiSubTableOver(theMenu);
}
function humiSubTableOutWithTimer(theMenu)
{
	colorBack();
}

function lv3HumiFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	setLv3BgColorHumiPage();
	lv3FlyingOver(theMenu);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}
function lv3HumiFlyingOutWithTimer(theMenu)
{
	lv3FlyingOut(theMenu);
	timeOutID = setTimeout('lv3FlyingOut("' + theMenu + '");hideAllHumiPage();',timeOut);
}

function linkHumiOverWithHide(leftId, theMenu)
{
	clearTimeout(timeOutID);
	hideAllHumiPage();
	setLv2BgColorHumiPage();
	linkHumiOver(leftId, theMenu);
}

/* Valves Functions in SubPage */

function lv4SubFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);

	inilializeTopLabels();
	hideAllTopFlyings();	
	setLv2BgColorValvPage();
	setLv3BgColorValvPage();
	hideLv4SubValveFlyings();
	lv4SubFlyingOver(theMenu);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}

function lv4SubFlyingOutWithTimer(theMenu)
{
	//lv4SubFlyingOut(theMenu);
	document.getElementById(theMenu).style.background = lv2FlyingOutColor;
	timeOutID = setTimeout('lv4SubFlyingOut("' + theMenu + '");hideAllValvPage();',timeOut);
}

function linkValveOverWithHide(leftId, theMenu)
{
	clearTimeout(timeOutID);
	hideAllValvPage();
	setLv2BgColorValvPage();
	linkValveOver(leftId, theMenu);
}
function lv3SubValveFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	setLv3BgColorValvPage();
	lv3FlyingOver(theMenu);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}
function lv3SubValveFlyingOutWithTimer(theMenu)
{
	timeOutID = setTimeout('lv3ValveFlyingOut("' + theMenu + '");hideAllValvPage();',timeOut);
}


/* Valve Function in MainPage */
function cataValveFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	
	//hideLv4ValveMainFlyings();
	//hideAllLv5ValveMainFlyings();
	hideSSMenu();
		
	cataValveFlyingOver(theMenu)
}

function lv5ValveFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	lv5ValveFlyingOver(theMenu)
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;	
}
function lv5ValveFlyingOutWithTimer(theMenu)
{
	lv5ValveFlyingOut(theMenu);
	timeOutID = setTimeout('lv5ValveFlyingOut("' + theMenu + '");hideAllMainPage();',timeOut);
}

function lv4MainFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	setLv4BgColorMainPage();
	lv4MainFlyingOver(theMenu);
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;
}
function lv4MainFlyingOutWithTimer(theMenu)
{
	//lv4MainFlyingOut(theMenu);
	document.getElementById(theMenu).style.backgroundColor = lv4FlyingOutColor;
	timeOutID = setTimeout('lv4MainFlyingOut("' + theMenu + '");hideAllMainPage();',timeOut);
}

function lv3ValveFlyingOverWithTimer(theMenu)
{
	clearTimeout(timeOutID);
	
	setLv3BgColorMainPage();
	hideLv4ValveMainFlyings();
	hideAllLv5ValveMainFlyings();
	hideSSMenu();
	lv3ValveFlyingOver(theMenu)
	
	lastFlyingObj = document.getElementById(theMenu);
	lastFlyingColor = lastFlyingObj.style.backgroundColor;	
}
function lv3ValveFlyingOutWithTimer(theMenu)
{
	//lv3ValveFlyingOut(theMenu); //Change flying column's color only, but do not hide extended menu for 2 ways and 3 ways
	document.getElementById(theMenu).style.background = lv3FlyingOutColor;
	timeOutID = setTimeout('lv3ValveFlyingOut("' + theMenu + '");hideAllMainPage();',timeOut);
}