// FLE_NAV.JS

// 
// set div
//

var isMenuOut = false,isMenuDown = false;
var MenuOutTimerID = 1;
var DropDownTimerID = 2;
var fle_floatMenuList = new Array;
var fle_floatMenuHeight = new Array;
var mIndex,mElement;

function FLE_menuInit()
{
	var mItem,mHeight;
	
	fle_floatMenuList.length = 0;
	fle_floatMenuHeight.length = 0;
	if (arguments.length<=0) return;
	for (i=0;i<arguments.length;i++) {
		mItem = arguments[i];
		x = document.getElementById(mItem);
		mHeight = x.offsetHeight-5; // control padding!!! fix this in the future
		
		fle_floatMenuList.push(mItem);
		fle_floatMenuHeight.push(mHeight);
		
//		x.style.height = '0px';
	}
}

// call to show float menu and refresh time
function FLE_menuHideOther(menuID)
{
	for(var i=0; i<fle_floatMenuList.length; i++)
		if (fle_floatMenuList[i] != menuID) {
			x = document.getElementById(fle_floatMenuList[i]);
			x.style.visibility = "hidden";
		} else if (fle_floatMenuList[i] == menuID) {
			x = document.getElementById(fle_floatMenuList[i]);
//			x.style.height = '0px';
			x.style.visibility = "visible";
//			mElement = x;
//			mIndex = i;
//			FLE_dropMenu();
		}
	
	FLE_menuOver(menuID);
}

// hide all pull down menus
function FLE_menuAutoHide()
{
	// hide all menus
	if (isMenuOut) 	{
		for(var i=0; i<fle_floatMenuList.length; i++)	{
			x = document.getElementById(fle_floatMenuList[i]);
			x.style.visibility = "hidden";
		}
	}

	// cancel pulldown
	if (isMenuDown) {
		clearTimeout(DropDownTimerID);
		isMenuDown = false;
	}
}

// call to refresh time
function FLE_menuOver(menuID)
{
	isMenuOut = false;
	clearTimeout(MenuOutTimerID);
} 

// mouse pointer went outside the menu
function FLE_menuOut()
{
	isMenuOut = true;
	MenuOutTimerID = setTimeout("FLE_menuAutoHide();","900");
}

// animate the pulldown menu
// please set global var mElement, mIndex
function FLE_dropMenu()
{
	var s,t;
	
	if (!isMenuDown) {
		isMenuDown = true;
	} else {
		clearTimeout(DropDownTimerID);
	}
	
	x = mElement;
	i = mIndex;
	s = parseInt(x.style.height);// alert(s);
	t = fle_floatMenuHeight[i]-30; // alert(t);
	
	if (x.offsetHeight < t) {
		s = s+30;
		x.style.height = s+"px"; //alert(x.style.height);
		DropDownTimerID = setTimeout("FLE_dropMenu();","20");
	} else {
		x.style.height = fle_floatMenuHeight[i];
		clearTimeout(DropDownTimerID);
		isMenuDown = false;
	}
}

// page jump relative to current language
// used for catalog library items...
function FLE_relCatalogue(relURL)
{
	document.location.href = '../catalogue/'+relURL;
}

function FLE_jumpRel(relURL)
{
	document.location.href = relURL;
}

function FLE_switchLangTo(lang)
{
	s = document.location.pathname;
	if ((s.substr(0,5)=='/zhs/')||(s.substr(0,5)=='/zht/')){
		s = s.substr(4);
	}
	switch (lang) {
		case 'zhs':
			s = '/zhs' + s;
			break;
		case 'zht':
			s = '/zht' + s;
			break;
		default:
			// do nothing
			break;
	}
    document.location.href = s;
}
