var menuopendelay=300;
var menuclosedelay=400;
var smactive=false;
var tmontimer;
var tmofftimer;
var smofftimer;
var openmenu;
var submenuwidth=158;

// Returns the version of Windows Internet Explorer or a -1
// (indicating the use of another browser).
function getInternetExplorerVersion(){
	var rv=-1; // Return value assumes failure.
	if(navigator.appName=='Microsoft Internet Explorer'){
		var ua=navigator.userAgent;
		var re=new RegExp('MSIE ([0-9]{1,}[\.0-9]{0,})');
		if(re.exec(ua)!=null){
			rv=parseFloat(RegExp.$1);
		}
	}
	return rv;
}
var ie_version=getInternetExplorerVersion();

function tmon(caller_id, menu_name){
	if(document.getElementById('smnu'+menu_name)==null){
		return;
	}

	if(openmenu && openmenu!=menu_name){
		tmactive=false;
		tmclose(openmenu);
	}
	tmactive=true;

	clearTimeout(tmontimer);
	tmontimer=setTimeout("tmopen('"+caller_id+"', '"+menu_name+"')", menuopendelay);
}

function tmopen(caller_id, menu_name){
	if(tmactive){
		tmactive=true;
		openmenu=menu_name;

		submenu=document.getElementById('smnu'+menu_name);

		if(ie_version==-1 || ie_version>=8.0){
			submenu.style.left=(document.getElementById(caller_id).offsetLeft)+'px';
			submenu.style.top=(document.getElementById(caller_id).offsetTop+document.getElementById(caller_id).offsetHeight+2)+'px';
		} else {
			submenu.style.left=(document.getElementById(caller_id).offsetLeft+document.getElementById(caller_id).parentNode.offsetLeft+document.getElementById('fullpage').offsetLeft+2)+'px';
		}

		var submenu_left=parseInt(submenu.style.left.replace('px', ''));
		submenu_right=submenu_left+submenuwidth;

		if(submenu_right>document.body.offsetWidth){
			submenu.style.left=(submenu_left-(submenu_right-document.body.offsetWidth))+'px';
		}

		if(ie_version!=-1 && ie_version<7.0){
			submenu.style.width=submenuwidth+'px';
			submenu.style.height='auto';
			submenu.style.overflow='auto';
		}

		submenu.style.display='block';
	}
}

function tmoff(menu_name){
	if(document.getElementById('smnu'+menu_name)==null){
		return;
	}

	tmactive=false;

	clearTimeout(tmofftimer);
	tmofftimer=setTimeout("tmclose('"+menu_name+"')", menuclosedelay);
}

function tmclose(menu_name){
	if(!tmactive){
		clearTimeout(tmofftimer);
		smclose('smnu'+menu_name);
	}
}

function smclose(submenu){
	if(!tmactive){
		clearTimeout(smofftimer);

		if(ie_version==-1 || ie_version>=7.0){
			document.getElementById(submenu).style.display='none';
		} else {
			document.getElementById(submenu).style.left='';
			document.getElementById(submenu).style.width='1px';
			document.getElementById(submenu).style.height='1px';
			document.getElementById(submenu).style.overflow='hidden';
		}
	}
}

function smon(){
	tmactive=true;
}

function smoff(parent_menu_name){
	tmactive=false;

	submenu='smnu'+parent_menu_name;
	clearTimeout(smofftimer);
	smofftimer=setTimeout("smclose('"+submenu+"')", menuclosedelay);
}
