$(function(){
	/*INIT MENU*/
	flg=getCookie('menuChange');
	if(flg==1){
		loadCompanyMenu();
		$('#menu .menuhead .company').attr('src','../img-common/menu-switch-company_on.gif');
	}else if(flg==2){
		loadPersonalMenu();
		$('#menu .menuhead .personal').attr('src','../img-common/menu-switch-personal_on.gif');
	}else{
		loadAllMenu();
		$('#menu .menuhead .all').attr('src','../img-common/menu-switch-all_on.gif');
	}
	/*MENU HOVER ACTION*/
	$('#menu .menuhead .company').hover(function(){$(this).attr('src','../img-common/menu-switch-company_over.gif');},function(){
		flg=getCookie('menuChange');
		if(flg==1) $(this).attr('src','../img-common/menu-switch-company_on.gif');
		else $(this).attr('src','../img-common/menu-switch-company_off.gif');
	});
	$('#menu .menuhead .personal').hover(function(){$(this).attr('src','../img-common/menu-switch-personal_over.gif');},function(){
		flg=getCookie('menuChange');
		if(flg==2) $(this).attr('src','../img-common/menu-switch-personal_on.gif');
		else $(this).attr('src','../img-common/menu-switch-personal_off.gif');
	});
	$('#menu .menuhead .all').hover(function(){$(this).attr('src','../img-common/menu-switch-all_over.gif');},function(){
		flg=getCookie('menuChange');
		if(flg!=1 && flg!=2) $(this).attr('src','../img-common/menu-switch-all_on.gif');
		else $(this).attr('src','../img-common/menu-switch-all_off.gif');
	});
	/*MENU HEAD ACTION*/
	$('#menu .menuhead .company').click(function(){
		$(this).attr('src','../img-common/menu-switch-company_on.gif');
		$('#menu .menuhead .personal').attr('src','../img-common/menu-switch-personal_off.gif');
		$('#menu .menuhead .all').attr('src','../img-common/menu-switch-all_off.gif');
		loadCompanyMenu();
		setCookie('menuChange',1);
	});
	$('#menu .menuhead .personal').click(function(){
		$(this).attr('src','../img-common/menu-switch-personal_on.gif');
		$('#menu .menuhead .company').attr('src','../img-common/menu-switch-company_off.gif');
		$('#menu .menuhead .all').attr('src','../img-common/menu-switch-all_off.gif');
		loadPersonalMenu();
		setCookie('menuChange',2);
	});
	$('#menu .menuhead .all').click(function(){
		$(this).attr('src','../img-common/menu-switch-all_on.gif');
		$('#menu .menuhead .personal').attr('src','../img-common/menu-switch-personal_off.gif');
		$('#menu .menuhead .company').attr('src','../img-common/menu-switch-company_off.gif');
		loadAllMenu();
		setCookie('menuChange',0);
	});
});
/*MENU ACTION SETTINGS*/
function menuAction(CLASS){
	$('#menu .menubody .'+CLASS+' .haslist').each(function(){
		key=$(this).text();
		flg=getCookie(key);
		if(flg==0 && flg!=1){
			$(this).next().toggle();
			$(this).css('background','url(../img-common/menu-more1.gif) no-repeat 5px center');
		}
	});
	$('#menu .menubody .'+CLASS+' .haslist').click(function(){
		$(this).next().slideToggle("fast",function(){
			key=$(this).prev().text();
			flg=getCookie(key);
			if(flg==1){
				setCookie(key,0);
				$(this).prev().css('background','url(../img-common/menu-more1.gif) no-repeat 5px center');
			}else{
				setCookie(key,1);
				$(this).prev().css('background','url(../img-common/menu-more.gif) no-repeat 5px center');
			}
		});
	});
}
function loadCompanyMenu(){
	$('#menu .menubody .security .menulist').load('../html/menu_company_security.htm',function(){menuAction('security');});
	$('#menu .menubody .environment .menulist').load('../html/menu_company_environment.htm',function(){menuAction('environment');});
	$('#menu .menubody .health .menulist').load('../html/menu_company_health.htm',function(){menuAction('health');});
	$('#menu .menubody .total .menulist').load('../html/menu_company_total.htm',function(){menuAction('total');});
}
function loadPersonalMenu(){
	$('#menu .menubody .security .menulist').load('../html/menu_personal_security.htm',function(){menuAction('security');});
	$('#menu .menubody .environment .menulist').load('../html/menu_personal_environment.htm',function(){menuAction('environment');});
	$('#menu .menubody .health .menulist').load('../html/menu_personal_health.htm',function(){menuAction('health');});
	$('#menu .menubody .total .menulist').load('../html/menu_personal_total.htm',function(){menuAction('total');});
}
function loadAllMenu(){
	$('#menu .menubody .security .menulist').load('../html/menu_all_security.htm',function(){menuAction('security');});
	$('#menu .menubody .environment .menulist').load('../html/menu_all_environment.htm',function(){menuAction('environment');});
	$('#menu .menubody .health .menulist').load('../html/menu_all_health.htm',function(){menuAction('health');});
	$('#menu .menubody .total .menulist').load('../html/menu_all_total.htm',function(){menuAction('total');});
}
/*COOKIE FUNCTIONS*/
function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
	key=escape(key);
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len) {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
}
function setCookie(key, val, tmp) {
	key=escape(key);
    tmp = key + "=" + escape(val) + "; ";
    tmp += "expires=Tue, 31-Dec-2038 23:59:59; path=/";
    document.cookie = tmp;
}

