// JavaScript Document
//-------------------------------------菜单与全局变量设定------------------------------------
function leftmenustyle (s_style, i_boldcurrent, i_border, s_icon, s_iconcurrent, s_bgcolor)
{
	this.style = s_style;
	this.boldcurrent = i_boldcurrent;
	this.border = i_border;
	this.icon = s_icon;
	this.iconcurrent = s_iconcurrent;
	this.bgcolor = s_bgcolor;
}

o_leftmenustyle = new Array();
o_leftmenustyle[0] = new leftmenustyle ("leftmenu0", 1, 1, "rightgreyarrow.gif", "downgreenarrow.gif", "#DEDCD8");
o_leftmenustyle[1] = new leftmenustyle ("leftmenu1", 1, 1, "rightgreytriangle.gif", "downgreentriangle.gif", "#FFFFFF");
o_leftmenustyle[2] = new leftmenustyle ("leftmenu2", 0, 0, "", "", "#FFFFFF");

function menuitem (s_itemtext, s_link, i_menuid, i_parentid, i_menudepth, i_showitem)
{
	this.itemtext = s_itemtext;
	this.hyperlink = s_link;
	this.id = i_menuid;
	this.pid = i_parentid;
	this.depth = i_menudepth;
	this.show = i_showitem;
	
	this.linktext = function ()
	{
		var s_s = "";
		var s_link = (this.hyperlink.substring(0, 4) == 'http'? this.hyperlink : s_path + this.hyperlink);
		if (this.show == 2)  // current menuitem
		{
			if (this.id > m && o_leftmenustyle[this.depth].boldcurrent == 1) s_s += '<strong>';
			s_s += '<a href="' + s_link + '"><font color="#009460">' + this.itemtext + '</font></a>';
			if (this.id > m && o_leftmenustyle[this.depth].boldcurrent == 1) s_s += '</strong>';
		}
		else
			s_s += '<a href="' + s_link + '">' + this.itemtext + '</a>';
		return s_s;
	}
	
	this.icon = function ()
	{
		var o_style = o_leftmenustyle[this.depth];
		if (o_style.icon != "")
		{
			var s_s = '<img src="' + s_path + 'style/images/';
			if (this.show == 1)
				s_s += o_style.icon;
			else
				s_s += o_style.iconcurrent;
			s_s += '">';
			return s_s;
		}
		else
			return "";
	}
}

o_topmenu = new Array();
o_leftmenu = new Array();
if (i_language == 0)
{
	o_topmenu[0] = new menuitem("首页", "index.html", c_index, c_root, 0, 1);
	o_topmenu[1] = new menuitem("关于", "about.html", c_about, c_root, 0, 1);
	o_topmenu[2] = new menuitem("链接", "links.html", c_links, c_root, 0, 1);
	o_topmenu[3] = new menuitem("捐助", "donate.html", c_donate, c_root, 0, 1);
	o_topmenu[4] = new menuitem("English", "index_en.html", c_index_en, c_root, 0, 1);

	o_leftmenu[0] = new menuitem("minipad2", "minipad2/minipad2.html", c_minipad2, c_root, 0, 1);
		o_leftmenu[1] = new menuitem("屏幕截图", "minipad2/screenshots.html", c_minipad2_screenshots, c_minipad2, 1, 0);
		o_leftmenu[2] = new menuitem("版本历史", "minipad2/versionhistory.html", c_minipad2_versionhistory, c_minipad2, 1, 0);
		o_leftmenu[3] = new menuitem("软件下载", "minipad2/downloads.html", c_minipad2_downloads, c_minipad2, 1, 0);
	o_leftmenu[4] = new menuitem("云影单词", "dailyword/dailyword.html", c_dailyword, c_root, 0, 1);
		o_leftmenu[5] = new menuitem("功能特色", "dailyword/description.html", c_dailyword_description, c_dailyword, 1, 0);	
		o_leftmenu[6] = new menuitem("屏幕截图", "dailyword/screenshots.html", c_dailyword_screenshots, c_dailyword, 1, 0);
		o_leftmenu[7] = new menuitem("版本历史", "dailyword/versionhistory.html", c_dailyword_versionhistory, c_dailyword, 1, 0);
		o_leftmenu[8] = new menuitem("软件下载", "dailyword/downloads.html", c_dailyword_downloads, c_dailyword, 1, 0);	
	o_leftmenu[9] = new menuitem("其它软件", "programs/programs.html", c_programs, c_root, 0, 1);
		o_leftmenu[10] = new menuitem("minitools", "programs/minitools.html", c_minitools, c_programs, 1, 0);
		o_leftmenu[11] = new menuitem("AHK 程序", "programs/ahk_programs.html", c_ahk_programs, c_programs, 1, 0);
		o_leftmenu[12] = new menuitem("取名字", "programs/autoname.html", c_autoname, c_programs, 1, 0);
	o_leftmenu[13] = new menuitem("论坛", "bbs/index.php", c_bbs, c_root, 0, 1);
}
else
{
	o_topmenu[0] = new menuitem("Home", "index_en.html", c_index_en, c_root, 0, 1);
	o_topmenu[1] = new menuitem("About", "about_en.html", c_about_en, c_root, 0, 1);
	o_topmenu[2] = new menuitem("Links", "links_en.html", c_links_en, c_root, 0, 1);
	o_topmenu[3] = new menuitem("Donate", "donate_en.html", c_donate_en, c_root, 0, 1);
	o_topmenu[4] = new menuitem("中文", "index.html", c_index, c_root, 0, 1);

	o_leftmenu[0] = new menuitem("minipad2", "minipad2/minipad2_en.html", c_minipad2_en, c_root, 0, 1);
		o_leftmenu[1] = new menuitem("Screenshots", "minipad2/screenshots_en.html", c_minipad2_screenshots_en, c_minipad2_en, 1, 1);
		o_leftmenu[2] = new menuitem("VersionHistory", "minipad2/versionhistory_en.html", c_minipad2_versionhistory_en, c_minipad2_en, 1, 1);
		o_leftmenu[3] = new menuitem("Downloads", "minipad2/downloads_en.html", c_minipad2_downloads_en, c_minipad2_en, 1, 1);
	o_leftmenu[4] = new menuitem("Forum", "forum/index.php", c_forum, c_root, 0, 1);
}

var m = o_topmenu.length - 1;
var n = o_leftmenu.length - 1;

var s_path = "";
if (i_pathdepth > 0)
{
	for (var i = 1; i <= i_pathdepth; i++)
		s_path = s_path + "../";
}

if (i_id != 0) { //对于id==0的站点地图或其他脚本文件不出现导航栏

function f_find(i_tid)
{
	for (var i = 0; i <=n; i++)
		if (o_leftmenu[i].id == i_tid) break;
	return i;
}

if (i_id > m + 1)
{
	var i_no = f_find(i_id);
	if (i_no <= n)
	{
		if (s_page === "") s_page = o_leftmenu[i_no].itemtext;

		var i_pid = o_leftmenu[i_no].pid;
		var i_depth = o_leftmenu[i_no].depth;
		for (var j = 0; j <= n; j++)
			if ( (o_leftmenu[j].depth == i_depth && o_leftmenu[j].pid == i_pid) || (o_leftmenu[j].depth == i_depth - 1 && o_leftmenu[j].pid == o_leftmenu[f_find(i_pid)].pid) || o_leftmenu[j].pid == i_id) o_leftmenu[j].show = 1;
		
		o_leftmenu[i_no].show = 2;
		while (i_depth >0)
		{
			i_no = f_find(i_pid);
			o_leftmenu[i_no].show = 2;
			i_pid = o_leftmenu[i_no].pid;
			i_depth --;
		}
	}
}
else
{
	for (var i = 0; i <= m; i++)
	{
		if (o_topmenu[i].id == i_id) break;
	}
	if (i <= m) 
	{
		o_topmenu[i].show = 2;
		if (s_page === "") s_page = o_topmenu[i].itemtext;
	}
}

document.write ('<img src="' + s_path + 'script/count.php?page=' + s_page + '&referrer=' + document.referrer + '" width=0 height=0>');

//-------------------------------------创建顶部导航栏------------------------------------
var s_bgcolor="EFEDEC";

var s_content = '<table border=0 width =100% cellpadding=0 cellspacing=0>'
	+ '<tr bgcolor=#FFFFFF>'
	+ ' <td width=9%></td>'
	+ '	<td width=155 height=80 align=left valign=middle><img src="' + s_path + 'style/images/logo.gif"></td>'
	+ ' <td width=2%></td>'
//	+ '	<td height=80 align=right valign=bottom><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" width="288" height="63"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + s_path + 'images/topflash.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /></object></td>'
	+ '	<td height=80 align=right valign=bottom></td>'  //temporarily placed here to replace the flash
	+ '	<td width=9%></td>'
	+ '</tr>'
	+ '<tr bgcolor=#' + s_bgcolor + '>'  //CAD8FF,EFEDEC
	+ '	<td colspan=3>'
	+ '	<td align=right height=36 class="topmenu"><div id="menu">';
for (var i = 0; i <= m; i++)
	s_content += '&nbsp;&nbsp;' + o_topmenu[i].linktext();
document.write (s_content + '</div></td><td></td></tr>');

//-------------------------------------创建左导航栏------------------------------------
function f_findnextshow(k)
{
	if (k < n)
	{
		for (var j = k+1; j <=n; j++)
		{ 
			if (o_leftmenu[j].show >= 1) break;
		}
		return j;
	}
	else
		return n + 1;
}

s_content = '<tr bgcolor=#' + s_bgcolor + '><td></td>'
	+ 	'<td valign=top><div id="menu"><table width=100% border=0 align=center cellspacing=0 cellpadding=0>';

for (var i = 0; i <=n; i++)
{
	var i_show = o_leftmenu[i].show;
	if ( i_show > 0)
	{
		var i_depth = o_leftmenu[i].depth;
		var o_style = o_leftmenustyle[i_depth];
		var i_nextshow = f_findnextshow(i);
		var s_line = "";
		if (i_nextshow <= n && o_style.bgcolor == o_leftmenustyle[o_leftmenu[i_nextshow].depth].bgcolor && !( i_depth == o_leftmenu[i_nextshow].depth && o_style.border == 0))
			 s_line = ' style="border-bottom:solid; border-width: 1px; border-color:#' + s_bgcolor + ';"';
		
		s_content += '<tr><td class="' + o_style.style + '"' + s_line + ' align="left" width=20>' + o_leftmenu[i].icon() + '</td>'
			+ '<td align="left" class="' + o_style.style + '"' + s_line + '>' + o_leftmenu[i].linktext() + '</td></tr>';
	}
}
document.write (s_content + '</table></div></td><td></td>');

//-------------------------------------设定主内容区------------------------------------
if ((i_id == c_index) || (i_id == c_index_en))
	document.write ('<td align="left" valign="top" bgcolor="#' + s_bgcolor + '"><div style="margin-top:0px; margin-left:0px; margin-right:0px; margin-bottom:0px;">');
else
	document.write ('<td align="left" valign="top" bgcolor="#FFFFFF"><div style="margin-top:25px; margin-left:25px; margin-right:25px; margin-bottom:25px;">');
}
