﻿var menu_data=
[[1,0,"Trang nhất","/",0],
[2,0,"Chính trị","http://www.bienphong.com.vn/nd5/list/chinh-tri/051.1.html",0],
[3,0,"Quân sự","http://www.bienphong.com.vn/nd5/list/quansu-quocphong/075.1.html",0],
[4,0,"Kinh tế","http://www.bienphong.com.vn/nd5/list/kinh-te/038.1.html",0],
[5,0,"Văn hoá","http://www.bienphong.com.vn/nd5/list/van-hoa/040.1.html",0],
[6,0,"Xã hội","http://www.bienphong.com.vn/nd5/list/xa-hoi/039.1.html",0],
[7,0,"Pháp luật","http://www.bienphong.com.vn/nd5/list/phap-luat/037.1.html",0],
[8,0,"Giáo dục-Đào tạo","http://www.bienphong.com.vn/nd5/list/giao-duc-dao-tao/044.1.html",0],
[9,0,"Khoa học-Công nghệ","http://www.bienphong.com.vn/nd5/list/khoa-hoc-cong-nghe/043.1.html",0],
[10,0,"Quốc tế","http://www.bienphong.com.vn/nd5/list/quoc-te/045.1.html",0],
[11,0,"Thể thao","http://www.bienphong.com.vn/nd5/list/the-thao/042.1.html",0],
[12,0,"Hồ sơ-tư liệu","http://www.bienphong.com.vn/nd5/list/hoso-tulieu/076.1.html",0],
//[13,0,"Phóng sự-ký sự","http://www.bienphong.com.vn/nd5/list/phong-su-ky-su/074.1.html",0],

[-1,2,"Biên phòng toàn dân","http://www.bienphong.com.vn/nd5/list/chinh-tri/bien-phong-toan-dan/051060.1.html",0],
[-1,2,"Đối ngoại biên phòng","http://www.bienphong.com.vn/nd5/list/chinh-tri/doi-ngoai-bien-phong/051061.1.html",0],
[-1,2,"Đạo đức Hồ Chí Minh","http://www.bienphong.com.vn/nd5/list/chinh-tri/dao-duc-ho-chi-minh/051058.1.html",0],
[-1,2,"Chính sách dân tộc","http://www.bienphong.com.vn/nd5/list/chinh-tri/chinh-sach-dan-toc/051062.1.html",0],
[-1,2,"Chính sách tôn giáo","http://www.bienphong.com.vn/nd5/list/chinh-tri/chinh-sach-ton-giao/051063.1.html",0],

[-1,7,"Đời sống pháp luật","http://www.bienphong.com.vn/nd5/list/phap-luat/doi-song-phap-luat/037064.1.html",0],
[-1,7,"Văn bản pháp luật","http://www.bienphong.com.vn/nd5/list/phap-luat/van-ban-phap-luat/037065.1.html",0],
[-1,7,"Giải đáp pháp luật","http://www.bienphong.com.vn/nd5/list/phap-luat/giai-dap-phap-luat/037066.1.html",0],
[-1,6,"Phòng chống thiên tai - Cứu hộ cứu nạn","http://www.bienphong.com.vn/nd5/list/xa-hoi/phong-chong-thien-tai-cuu-ho-cuu-nan/039080.1.html",0],
[-1,11,"Thể thao trong nước","http://www.bienphong.com.vn/nd5/list/the-thao/the-thao-trong-nuoc/042067.1.html",0],
[-1,11,"Thể thao quốc tế","http://www.bienphong.com.vn/nd5/list/the-thao/the-thao-quoc-te/042068.1.html",0],
[-1,12,"Ông cha ta bảo vệ biên giới","http://www.bienphong.com.vn/nd5/list/ho-so-tu-lieu/ong-cha-ta-bao-ve-bien-gioi/076077.1.html",0],
[-1,12,"Tư liệu lịch sử","http://www.bienphong.com.vn/nd5/list/ho-so-tu-lieu/tu-lieu-lich-su/076078.1.html",0],
[-1,12,"Hồ sơ vụ án","http://www.bienphong.com.vn/nd5/list/ho-so-tu-lieu/ho-so-vu-an/076079.1.html",0]];

var submenu = new Array(menu_data.length);
var activeid;
var delay_hide=500;
var L2Panel;
var L1_ID,L2_INDEX;

function Active(){	
	var i,j;
	for (i=0; i<menu_data.length; i++) {
		if(menu_data[i][0]==L1_ID&& menu_data[i][1]==0) {
			activeid = i;
			break;
		}
		else if(menu_data[i][0]==L1_ID&& menu_data[i][1]!=0) {
			for(j=0; j<menu_data.length; j++) {
				if(menu_data[j][0]==menu_data[i][1]) {
					activeid = j;
					break;
				}
			}
			break;
		}
	}
}

function CreateMenu_L1()
{	var strParent = '';
	var strSep = '<div class="fl" style="width:1px;font-size:1px"><img src="http://nhot.vinasme.vn/img/menu_L1-sep.gif" alt="" /></div>';
	var i;
	var url = '';

	for(i=0; i< menu_data.length; i++) 
	{	//url = (L1_ID >= 9998 && L1_ID != 10000 && L1_ID != 10001) ? 'http://vnexpress.net' + menu_path[i] : menu_path[i];
		url = menu_data[i][3];		
		if(menu_data[i][1] != 0 || menu_data[i][4] != 0)
			continue;
		if(menu_data[i][0]==L1_ID)
		{	strParent = strParent.concat('<div id="l1_').concat(i).concat('" class="fl" onMouseover="activeMenu(').concat(i).concat(');showit(').concat(i).concat(',1);" onMouseout="deactiveMenu(').concat(i).concat(');reWriteMenu();" onClick="goTo(\'').concat(url).concat('\');">');
			strParent = strParent.concat('<div id="mn').concat(i).concat('_l" class="menu_L1-al fl">&nbsp;</div>');
			strParent = strParent.concat('<div id="mn').concat(i).concat('" class="menu_L1-a fl">').concat(menu_data[i][2]).concat('</div>');
			strParent = strParent.concat('<div id="mn').concat(i).concat('_r" class="menu_L1-ar fl">&nbsp;</div>');
			strParent = strParent.concat('</div>');
			strParent = strParent.concat(strSep);
		}			
		else
		{	strParent = strParent.concat('<div id="l1_').concat(i).concat('" class="fl" onMouseover="activeMenu(').concat(i).concat(');showit(').concat(i).concat(',1);" onMouseout="deactiveMenu(').concat(i).concat(');reWriteMenu();" onClick="goTo(\'').concat(url).concat('\');">');
			strParent = strParent.concat('<div id="mn').concat(i).concat('_l" class="menu_L1-il fl">&nbsp;</div>');
			strParent = strParent.concat('<div id="mn').concat(i).concat('" class="menu_L1-i fl">').concat(menu_data[i][2]).concat('</div>');
			strParent = strParent.concat('<div id="mn').concat(i).concat('_r" class="menu_L1-ir fl">&nbsp;</div>');
			strParent = strParent.concat('</div>');
			strParent = strParent.concat(strSep);
		}			
		CreateMenu_L2(menu_data[i][0], i);
	}
	strParent = strParent.substr(0, strParent.length - strSep.length);	
	gmobj("menu_L1-panel").innerHTML = strParent;
}

function CreateMenu_L2(p, k)
{
	var strSubMenu = '';
	var strSep = '&nbsp;&nbsp;&nbsp;<img src="http://nhot.vinasme.vn/img/bullet-2.gif" alt=""/>&nbsp;';
	var i;
	var j = 0;
	var url = '';

	for(i=0; i < menu_data.length; i++) 
	{
		//url = (L1_ID >= 9998 && L1_ID != 10000 && L1_ID != 10001) ? 'http://vnexpress.net' + menu_path[i] : menu_path[i];
		url = menu_data[i][3];		
		if(menu_data[i][1]==p && menu_data[i][4]==0)
		{
			if(j==0) 
				strSubMenu = strSubMenu.concat('<img src="http://nhot.vinasme.vn/img/bullet-2.gif" border="0"/>&nbsp;');				
			if (p==L1_ID && j==L2_INDEX)
				strSubMenu = strSubMenu.concat('<a class="menu_L2-link-a" href="').concat(url).concat('">').concat(menu_data[i][2]).concat('</a>');
			else
				strSubMenu = strSubMenu.concat('<a class="menu_L2-link" href="').concat(url).concat('">').concat(menu_data[i][2]).concat('</a>');
			strSubMenu = strSubMenu.concat(strSep);
			j++;
		}
	}
	strSubMenu = strSubMenu.substr(0, strSubMenu.length - strSep.length);
	submenu[k] = strSubMenu;
}

function writeCurrentMenu() 
{	var strSubMenu = '';
	var i, j;
	
	for(i=0; i < menu_data.length; i++) 
	{	if(menu_data[i][0]==L1_ID && menu_data[i][1]==0) 
		{	activeMenu(i);
			//gmobj('submenu').innerHTML = submenu[i];
			showit(i,0);
			break;
		}
		else if(menu_data[i][0]==L1_ID && menu_data[i][1]!=0) 
		{
			var flag = false;
			for(j=0; j<menu_data.length; j++) 
			{	if(menu_data[j][0]==menu_data[i][1]) 
				{	activeMenu(j);
					//gmobj('submenu').innerHTML = submenu[j];
					showit(j,0);
					break;
				}
			}
			if(j<menu_data.length) 
				break;
		}	
		else 
		{	deactiveMenu(activeid);
			L2Panel.innerHTML = '';
		}
	}	
}
function activeMenu(i) 
{	if (i<0 || isNaN(i))
		return;

	if(i != activeid && activeid != -1) 
	{	deactiveMenu(activeid);
		activeid = i;
	}		
	gmobj('mn' + i).className = 'menu_L1-a fl';
	gmobj('mn' + i + '_l').className = 'menu_L1-al fl';
	gmobj('mn' + i + '_r').className = 'menu_L1-ar fl';		
}

function deactiveMenu(i) 
{	
	if(i >= 0 && !isNaN(i)) 
	{	gmobj('mn' + i).className = 'menu_L1-i fl';
		gmobj('mn' + i + '_l').className = 'menu_L1-il fl';
		gmobj('mn' + i + '_r').className = 'menu_L1-ir fl';				
	}	
}

function activeMenuParent() 
{	activeMenu(activeid);
}

function showit(which, type)
{	
	clear_delayhide();
	
	thecontent=(which==-1)? "" : submenu[which];
	if (thecontent=="")
	{	L2Panel.style.display="none";
		gmobj("menu_L2_home").style.display="";
		gmobj("L2_gap").style.width="20px";
		return;
	}
	L2Panel.style.display="";
	L2Panel.className = 'menu_L2-panel fl';
	gmobj("menu_L2_home").style.display="none";
	
	if (document.getElementById||document.all)
		L2Panel.innerHTML=thecontent;
	else if (document.layers)
	{	L2Panel.document.write(thecontent);
		L2Panel.document.close();
	}
	//-------- position it --------
	L1_Item=gmobj("l1_"+which);
	L2=gmobj("menu_L2");
	//alert(""+L1_Item.offsetLeft+","+L1_Item.offsetWidth/2+","+L2Panel.offsetWidth/2);
	/*
	var a=L1_Item.offsetLeft;
	var b=L1_Item.offsetWidth/2;
	var c=L2Panel.offsetWidth/2;
	
	alert(""+L1_Item.id+", "+a+", "+b+","+c);
	var left=a+b-c;
	*/
	var left=L1_Item.offsetLeft + L1_Item.offsetWidth/2 - L2Panel.offsetWidth/2;
	if (left<0)
		left=0;
	if (left+L2Panel.offsetWidth > L2.offsetWidth)
		left=L2.offsetWidth-L2Panel.offsetWidth-2;
	gmobj("L2_gap").style.width=left+"px";
}

function clear_delayhide()
{	if (window.delayhide)
		clearTimeout(delayhide);
}

function reWriteMenu() 
{	delayhide=setTimeout("writeCurrentMenu()",delay_hide);	
}
//---------------------
function goTo(url)
{	//document.location.href = i;
	//alert(i);
	window.location=url;
}

function gmobj(o)
{	if(document.getElementById)
	{	m=document.getElementById(o); 
	}
	else if(document.all)
	{ m=document.all[o]; 
	}
	else if(document.layers)
	{ m=document[o]; 
	}
	return m;
}
