var isSubMenuClose = false;
var handelTimeIdx = 0;
var default_focus = -1;
var current_focus = -1;

function init_top_menu() {
	$('.right_button2 .menuAboutUs').mouseover(function(){
		menuMouseOverHandler(0, mAboutUs);
	});
	$('.right_button2 .menuAboutUs').mouseout(function(){
		menuMouseOutHandler(0, mAboutUs);
	});
	$('.right_button2 .menuAboutUs').click(function(){
		menuClickHandler(0, mAboutUs);
	});
	$('.right_button2 .menuProducts').mouseover(function(){
		menuMouseOverHandler(1, mProducts);
	});
	$('.right_button2 .menuProducts').mouseout(function(){
		menuMouseOutHandler(1, mProducts);
	});
	$('.right_button2 .menuProducts').click(function(){
		menuClickHandler(1, mProducts);
	});
	$('.right_button2 .menuNews').mouseover(function(){
		menuMouseOverHandler(2, mNews);
	});
	$('.right_button2 .menuNews').mouseout(function(){
		menuMouseOutHandler(2, mNews);
	});
	$('.right_button2 .menuNews').click(function(){
		menuClickHandler(2, mNews);
	});
	$('.right_button2 .menuOurPartner').mouseover(function(){
		menuMouseOverHandler(3, mOurPartner);
	});
	$('.right_button2 .menuOurPartner').mouseout(function(){
		menuMouseOutHandler(3, mOurPartner);
	});
	$('.right_button2 .menuOurPartner').click(function(){
		menuClickHandler(3, mOurPartner);
	});
	$('.right_button2 .menuEmployment').mouseover(function(){
		menuMouseOverHandler(4, mEmployment);
	});
	$('.right_button2 .menuEmployment').mouseout(function(){
		menuMouseOutHandler(4, mEmployment);
	});
	$('.right_button2 .menuEmployment').click(function(){
		menuClickHandler(4, mEmployment);
	});
	$('.right_button2 .menuInvestment').mouseover(function(){
		menuMouseOverHandler(5, mInvestment);
	});
	$('.right_button2 .menuInvestment').mouseout(function(){
		menuMouseOutHandler(5, mInvestment);
	});
	$('.right_button2 .menuInvestment').click(function(){
		menuClickHandler(5, mInvestment);
	});
	$('.right_button2 .menuWebsite').mouseover(function(){
		menuMouseOverHandler(6, mWebsite);
	});
	$('.right_button2 .menuWebsite').mouseout(function(){
		menuMouseOutHandler(6, mWebsite);
	});
	$('.right_button2 .menuWebsite').click(function(){
		menuClickHandler(6, mWebsite);
	});
	$('.right_button2 .menuContactUs').mouseover(function(){
		menuMouseOverHandler(7, mContactUs);
	});
	$('.right_button2 .menuContactUs').mouseout(function(){
		menuMouseOutHandler(7, mContactUs);
	});
	$('.right_button2 .menuContactUs').click(function(){
		menuClickHandler(7, mContactUs);
	});
	$('#subMenuDiv').mousemove(function(){
		isSubMenuClose = false;
	});
	$('#subMenuDiv').mouseout(function(){
		isSubMenuClose = true;
	});
	$('#subMenuDiv').click(function(){
		isSubMenuClose = true;
	});
	checkHideSubMenu();
}

function checkHideSubMenu() {
	if(handelTimeIdx > 3){
		if(isSubMenuClose){
			var n = $('.right_button2 div').length;
			for(var i=0; i<n; i++) {
				$('.right_button2 div:eq(' + i + ')').removeClass('isfocus');
			}
			$('#subMenuDiv').css('display', 'none');
			if(default_focus >= 0) {
				$('.right_button2 div:eq(' + default_focus+ ')').addClass('on');
				default_focus=-1;
			}
			handelTimeIdx = 0;
			isSubMenuClose = false;
		}
	}
	handelTimeIdx ++;
	if(handelTimeIdx > 10000) handelTimeIdx = 0;
	window.setTimeout('checkHideSubMenu()', 300);
}
function menuMouseOutHandler(menuIdx, subMenu) {
	if(subMenu.length > 1) return ;
	isSubMenuClose = true;
}
function menuMouseOverHandler(menuIdx, subMenu) {
	var xx = $('.right_button2 div:eq(' + menuIdx+ ')').x();
	var n = $('.right_button2 div').length;
	var i;
	var htm = '<table border="0" cellpadding="1" cellspacing="1" bgcolor="#EFEFEF">\n';
	$('#subMenuDiv').css('display', 'none');
	for(i=0; i<n; i++) {
		$('.right_button2 div:eq(' + i + ')').removeClass('isfocus');
		if(default_focus < 0) {
			if($('.right_button2 div:eq(' + i+ ')').hasClass('on')){
				default_focus = i;
				$('.right_button2 div:eq(' + i+ ')').removeClass('on');
				break;
			}
		}
	}
	isSubMenuClose = false;
	if(subMenu.length <= 1) return ;
	current_focus = menuIdx;
	for(i=0; i<subMenu.length; i++) {
		htm += '<tr>\n';
		htm += '<td nowrap><label>&nbsp;．<a href="' + subMenu[i].link + '">' + subMenu[i].label + '</a>&nbsp;&nbsp;</label></td>\n';
		htm += '</tr>\n';
	}
	htm += '</table><br />\n';
	
	$('#subMenuDiv').html(htm);
	$('#subMenuDiv').css('left', xx+'px');
	$('#subMenuDiv').animate({opacity: 'show'}, 200, function(){
		$('.right_button2 div:eq(' + current_focus+ ')').addClass('isfocus');
		$(this).css({opacity: 0.8});
	});
}

function menuClickHandler(menuIdx, subMenu) {
	if(subMenu.length > 1) return ;
	if(subMenu[0].link == 'javascript' || subMenu[0].link == '') return ;
	document.location.href=subMenu[0].link;
}

