////////////////////Please leave this notice//////////////////////
//								//
//	Dynamic JS Menu 1.0					//
//	By Pat Libby (Libbypa@maine.rr.com)			//
//	http://dragonsbane1.topcities.com			//
//	It works only with IE5.0(++) and Netscape6.0(++)	//
//	Free to use!						//
//								//
////////////////////Last modified 01-31-2003//////////////////////


//  Modify following four lines to customize your menu
var tdColor="#777777";      // menu item text color
var tdsColor="#ffffff";     // sub menu item text color
var tdBgColor="#FF0000";    // menu item background color
var hlColor="#ffffff";      // highlight text color
var hlBgColor="#FF9999";    // highlight background color
//	After change, modify same values in your DropDown.css file

////////////////////DO NOT MODIFY BELOW HERE//////////////////////
var md=250;
var ti=-1;
var oTd=new Object;
oTd=null;
//by leepeng to check current width
function checkWidth()   {
    var cw = 600;
    if (document.body.clientWidth)
        cw = document.body.clientWidth;
    else
        cw = window.innerWidth - 20;
    return cw;
}
function doMenu(td, firstlvl){
    clearTimeout(ti);

    if (firstlvl)   {
        td.style.backgroundColor="#CC0000";
        //td.style.color=hlColor;
    }
    else    {
        td.style.backgroundColor="#000000";
        //td.style.color=tdsColor;
    }
    
    var i;
    var sT="";
    var tda=new Array();
    tda=td.id.split("_");
    if(oTd!=null){
        var tdo=new Array();
        tdo=oTd.id.split("_");
        for(i=1;i<tdo.length;i++){
            sT+="_"+tdo[i];
            if(tdo[i]!=tda[i]){
                document.getElementById("td"+sT).style.backgroundColor="";
                if(document.getElementById("tbl"+sT)!=null) {
                    document.getElementById("tbl"+sT).style.visibility="hidden";
                    document.getElementById("div"+sT).style.visibility="hidden";
                }
            }
        }
    }
    oTd=td;
    sT="tbl";
    sT2="div";

    for(i=1;i<tda.length;i++)   {
        sT+="_"+tda[i];
        sT2+="_"+tda[i];
    }
    if(document.getElementById(sT)!=null)   {
        document.getElementById(sT).style.visibility="visible";
        document.getElementById(sT2).style.visibility="visible";
    }
}
function clearMenu(){
    if(oTd!=null){
        var tdo=new Array();
        tdo=oTd.id.split("_");
        var sT="";
        for(var i=1;i<tdo.length;i++){
            sT+="_"+tdo[i];
            document.getElementById("td"+sT).style.backgroundColor="";
            
            if(document.getElementById("tbl"+sT)!=null) {
                document.getElementById("tbl"+sT).style.visibility="hidden";
                document.getElementById("div"+sT).style.visibility="hidden";
            }
        }
        oTd=null;
    }
}
function runMenu(strURL){
    location.href=strURL;
}
var tt="";
var sT="";
var pT=new Array();
var tA=new Array();

function resetCoord(st) {
    if (document.getElementById("div"+st) != undefined) {
        var cmargin = 0;
        var cw = checkWidth();
        if (cw > 960)
            cmargin = (cw - 960) / 2;

        tA=st.split("_");
        var idx = tA[tA.length-1];

        //is sub sub menu
        if(tA.length>2){
            tA=tA.slice(0,-1);
            tt=tA.join("_");
            document.getElementById("div"+st).style.left = document.getElementById("div"+tt).style.pixelLeft+158;
        }
        //first level sub menu
        else{
            document.getElementById("div"+st).style.left = cmargin + 181;
        }
    }
}
function getCoord(st){
    var cmargin = 0;
    var cw = checkWidth();
    if (cw > 960)
        cmargin = (cw - 960) / 2;
    tA=st.split("_");
    var idx = tA[tA.length-1];
    if(tA.length>2){
        tA=tA.slice(0,-1);
        tt=tA.join("_");

        str = "top:" + (document.getElementById("div"+tt).style.pixelTop + ((parseInt(idx) -1) * 26))+"px;left:"+
            (document.getElementById("div"+tt).style.pixelLeft+164)+"px\">";
    }else{
        str = "top:" + (((parseInt(idx) -1) * 26) + 151) +"px;left:"+ (cmargin + 168) +"px\">";
    }
    return str;
}
function renderMenu()   {
    var sH="";
    sH+="<div style=\"width:180px;border-right:1px solid #999999;cursor:pointer\" id=\"divmain\">";
    sH+="<table width='180px' id=\"mainmenu\" cellspacing=\"0\" border=\"0\" cellpadding=\"0\" style=\"border:0\"><tr>";
    //render first level menu items
    var p=0;
    var j=0;
    while(eval("typeof(td_"+ ++j +")!=\"undefined\"")){
        sH+="<tr><td id=\"td_" + j + "\" style=\"border-bottom:1px solid #999999;padding:2px 5px 2px 5px;font-family:verdana;font-size:8pt;color:#777777;line-height:21px;text-align:left;\" id=\"td_"+j+"\" onmouseover=\"resetCoord('_"+j+"');doMenu(this, 1)\" onmouseout=\"ti=setTimeout('clearMenu()',md)\"";
        sH+=(eval("typeof(url_"+j+")!=\"undefined\""))?" onclick=\"runMenu('"+eval("url_"+j)+"')\">":">";
        sH+=eval("td_"+j)+"</td></tr>";
        if (eval("typeof(td_"+j+"_1)!=\"undefined\""))
            pT[p++]="_"+j;
    }
    sH+="</table>";
    sH+="</div>";
    document.write(sH);
    for(var q=0;typeof(pT[q])!="undefined";q++){
        sT=pT[q];
        sH="";
        j=0;
        //sH+="<table class=\"menu\" id=\"tbl"+sT+"\" cellspacing=\"0\" cellpadding=\"0\" style=\"top:"+getCoord(sT);

        sH+="<div id=\"div"+sT+"\" style=\"cursor:pointer;visibility:hidden;position:absolute;z-index:100;width:160px;text-align:left;background-color:#cc0000;border:1px solid #ffffff;" +getCoord(sT);
        sH+="<table id=\"tbl"+sT+"\" width=\"160\" cellspacing=\"0\">";

        while (eval("typeof(td"+sT+"_"+ ++j +")!=\"undefined\"")){
            sH+="<tr><td style=\"font-family:verdana;font-size:8pt;color:#ffffff;padding:2px 5px 2px 5px;\" id=\"td"+sT+"_"+j+"\" onmouseover=\"resetCoord('"+sT+"_"+j+"');doMenu(this, 0)\" onmouseout=\"ti=setTimeout('clearMenu()',md)\"";
            sH+=(eval("typeof(url"+sT+"_"+j+")!=\"undefined\""))?" onclick=\"runMenu('"+eval("url"+sT+"_"+j)+"')\">":">";
            sH+=eval("td"+sT+"_"+j)+"</td></tr>";
            if (eval("typeof(td"+sT+"_"+j+"_1)!=\"undefined\""))
                pT[p++]=sT+"_"+j;
        }
        sH+="</table>";
        sH+="</div>";
        document.write(sH);
    }
    document.getElementById("mainmenu").style.visibility="visible";
}
