var menutexts = ["","我&nbsp;&nbsp;&nbsp;们","简&nbsp;&nbsp;&nbsp;报","文&nbsp;&nbsp;&nbsp;章","摄&nbsp;&nbsp;&nbsp;影","论&nbsp;&nbsp;&nbsp;坛","留&nbsp;&nbsp;&nbsp;言"];
var menubgcolors = ["", "#E13C28", "#F48222", "#FFDE00", "#08A844", "#0965B0", "#945C8D"];

var subtitles = ["主页","我们","简报","文章","摄影","论坛","留言",
                 "联系我们","活动一览表",
                 "佳作选读","自传","散文","游记","小说","诗歌","艺评"];
var urls = ["/home.shtml", "/aboutus.shtml", "/newsletter.shtml", "/essay.shtml", "/photography.shtml", "/phpBB2/index.php", "/cgi/guestbook.cgi",
            "/contact.shtml", "/event.shtml",
            "/recommend.shtml", "/essay_autobio.shtml", "essay_prose.shtml", "essay_travel.shtml", "essay_novel.shtml", "essay_poem.shtml", "/essay_artcriticism.shtml"];
var titleimages = ["title.gif", "title_aboutus.gif","title_newsletter.gif","title_essay.gif","title_photography.gif","","title_guestbook.gif",
                   "title_contact.gif", "title_event.gif",
                   "title_recommend.gif", "title_autobio.gif", "title_prose.gif", "title_travel.gif", "title_novel.gif", "title_poem.gif", "title_artcriticism.gif"];
var titleimagewidths = [135, 108, 110, 110, 108, 0, 83,
                        109, 135,
                        109, 109, 109, 110, 110, 109, 109];
var sublinks = [[], ["结识在缘分的天空", "加入我们"], [], [], [], [], [],
                ["联系我们","投稿须知"], [],
                [], [], [], [], [], [], []];
var subanchors = [[], ["#gettoknow", "#join"], [], [], [], [], [],
                  ["#contact", "#contribute"], [],
                  [], [], [], [], [], [], []];

var ESSAY_INDEX = 3;
var CATEGORY_INDEX_BEGIN = 9; // inclusive
var CATEGORY_INDEX_END = 16; // exclusive

function populateSublink(index) {
    var sublink = sublinks[index];
    var subanchor = subanchors[index];
    if (index != ESSAY_INDEX) {
        sublink[sublink.length] = "全部文章";
        subanchor[subanchor.length] = urls[ESSAY_INDEX];
    }
    for (var i = CATEGORY_INDEX_BEGIN; i < CATEGORY_INDEX_END; i++) {
        if (i != index) {
            sublink[sublink.length] = subtitles[i];
            subanchor[subanchor.length] = urls[i];
        }
    }
}

function openWindow(link, title, width, height, scroll) {
  window.open(link, title, 'width=' + width + ',height=' + height + ',scrollbars=' + scroll);
}

function renderMainMenus() {
    populateSublink(ESSAY_INDEX);
    for (var i = CATEGORY_INDEX_BEGIN; i < CATEGORY_INDEX_END; i++) populateSublink(i);

    document.write("<table width=750 border=0 cellspacing=0 cellpadding=0><tr>\n");
    for (var i = 1; i < menutexts.length; i++) {
        var bgcolor;
        if (subtitles[i] == subtitle) bgcolor = menubgcolors[i];
        else bgcolor = "#808080";
        document.write("<td width=125 align=center bgcolor=" + bgcolor);
        if (subtitles[i] != subtitle) document.write(" onclick=\"window.location='" + urls[i] + "';\"");
        document.write(" onmouseover=\"this.style.background='" + menubgcolors[i] + "';\"");
        document.write(" onmouseout=\"this.style.background='" + bgcolor + "';\"");
        document.write(" style=\"cursor:pointer;\">");
        document.write("<img src='/img/nothing.gif' width=125 height=2><br>");
        document.write("<font color=#000000>" + menutexts[i] + "</font></td>\n");
    }
    document.write("</tr></table>\n");

    var index = 0;
    for (var i = 1; i < subtitles.length; i++) if (subtitles[i] == subtitle) index = i;

    document.write("<table width=750 height=40 border=0 cellspacing=0 cellpadding=5 bgcolor=#CCCCCC><tr>\n");
    document.write("<td><img src=\"/img/nothing.gif\" width=15 height=1>");
    document.write("<img src=\"/img/leaf.gif\" border=0 width=30 height=30 style=\"cursor:pointer;\" onclick=\"window.location='" + urls[0] + "'\" alt=\"返回主页\">");
    document.write("<img src=\"/img/" + titleimages[index] + "\" border=0 width=" + titleimagewidths[index] + " height=30>");
    document.write("<img src=\"/img/nothing.gif\" width=10 height=1></td>");
    if (subtitle != subtitles[0])
    {
        document.write("<td width=100% valign=bottom><a href=\"" + urls[0] + "\" class=navigation>返回主页</a>");
        for (var i = 0; i < sublinks[index].length; i++)
            document.write(" | <a href=\"" + subanchors[index][i] + "\" class=navigation>" + sublinks[index][i] + "</a>");
        document.write("</td>\n");
    }
    document.write("</tr></table>\n");
}

function renderColumnMenus() {
    for (var i = 0; i < menutexts.length; i++) {
        document.write("<td onclick=\"window.location='" + urls[i] + "';\"");
        document.write(" onmouseover=\"this.style.background='#CCCCCC'; this.style.color='#000000';\"");
        document.write(" onmouseout=\"this.style.background='#000000'; this.style.color='#FFFFFF';\"");
        document.write(" class=navigation>");
        document.write("【" + subtitles[i] + "】</td>\n");
    }
}