var cssFile="css-shar/menu.css";
var topOffset=113;
var leftOffset=74;
var md=500;
var ti=-1;

// top menu styles
var isHorizontalMenu=true;
var topmenuWidth=0; // set to 0 if using horizontal
var tpClass="topmenu";
var tpFrColor="#FF0000";
var tpBgColor="";
var tpArrow=" <img src=\""+siteurl+"img-shar/menuarrw.gif\" />";

// float menu styles
var menuWidth=160;
var tblClass="menutable";
var tdClass="menuitem";
var tdFrColor="#FFFFFF";
var tdBgColor="#5456A0";
var tdArrow=" <img src=\""+siteurl+"img-shar/redarrw.gif\" />";

var oTd=null;

function doMenu(td, firstlvl) {
  clearTimeout(ti);
  td.style.color = (firstlvl) ? tpFrColor : tdFrColor;
  td.style.backgroundColor = (firstlvl) ? tpBgColor : tdBgColor;
  var sT="";
  var tda=td.id.split("_");
  if(oTd!=null){
    var tdo=oTd.id.split("_");
    for(i=1;i<tdo.length;i++) {
      sT+="_"+tdo[i];
      if(tdo[i]!=tda[i]) {
        document.getElementById("td"+sT).style.color="";
        document.getElementById("td"+sT).style.backgroundColor="";
        if(document.getElementById("div"+sT)!=null)
          document.getElementById("div"+sT).style.visibility="hidden";
      }
    }
  }
  oTd=td;
  sT="div";
  for(i=1;i<tda.length;i++)
    sT+="_"+tda[i];
  
  if(document.getElementById(sT)!=null) {
    nextPos=(tda.length < 3)?topmenuWidth:menuWidth;
    if(nextPos)
	  document.getElementById(sT).style.top=getOffSetTop(td);
	document.getElementById(sT).style.left = nextPos+getOffSetLeft(td)-2;
    document.getElementById(sT).style.visibility="visible";
  }
}

function clearMenu() {
  if(oTd!=null){
    var tdo=oTd.id.split("_");
    var sT="";
    for(i=1;i<tdo.length;i++) {
      sT+="_"+tdo[i];
	  document.getElementById("td"+sT).style.color="";
      document.getElementById("td"+sT).style.backgroundColor="";
      if(document.getElementById("div"+sT)!=null)
        document.getElementById("div"+sT).style.visibility="hidden";
    }
    oTd=null;
  }
}

function runMenu(strURL) {
  location.href=strURL;
}

function getOffSetLeft(el) {
  if(!el&&this)
    el=this;
  var nLeftPos=el.offsetLeft;
  var ep=el.offsetParent;
  while(ep!=null) {
    nLeftPos+=ep.offsetLeft;
    ep=ep.offsetParent;
  }
  return nLeftPos;
}

function getOffSetTop(el) {
  if(!el&&this)
    el=this;
  var nTopPos=el.offsetTop;
  var ep=el.offsetParent;
  while(ep!=null) {
    nTopPos+=ep.offsetTop;
    ep=ep.offsetParent;
  }
  return nTopPos;
}

function renderMenu() {
  var tt="";
  var sT="";
  var pT=new Array();
  var tA=new Array();
  
  document.write("<link href=\""+cssFile+"\" rel=\"stylesheet\" type=\"text/css\">");
  var sH="<table id=\"mainmenu\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
  if(isHorizontalMenu) sH+="<tr>";
  var p=0, j=0;
  while(eval("typeof(td_"+ ++j +")!=\"undefined\"")) {
    if(!isHorizontalMenu) sH+="<tr>";
    sH+="<td nowrap class=\""+tpClass+"\" id=\"td_" + j + "\" style=\"cursor:pointer;\" onmouseover=\"doMenu(this, 1);\" onmouseout=\"ti=setTimeout('clearMenu()',md);\"";
    sH+=(eval("typeof(url_"+j+")!=\"undefined\""))?" onclick=\"runMenu('"+siteurl+eval("url_"+j)+"');\">":">";
    sH+=eval("td_"+j);
    sH+=(eval("typeof(td_"+j+"_1)!=\"undefined\""))?tpArrow:"";
    sH+="</td>";
	if(!isHorizontalMenu) sH+="</tr>";
    if(eval("typeof(td_"+j+"_1)!=\"undefined\""))
      pT[p++]="_"+j;
  }
  if(isHorizontalMenu) sH+="</tr>";
  sH+="</table>";
  document.write(sH);
  for(var q=0;typeof(pT[q])!="undefined";q++) {
    sT=pT[q];
    j=0;
    sH="<table id=\"div"+sT+"\" class=\""+tblClass+"\" cellspacing=\"0\" border=\"0\" style=\"visibility:hidden; width:"+menuWidth+"; position:absolute; top:" + topOffset +"px; z-index:2;\">";
    while(eval("typeof(td"+sT+"_"+ ++j +")!=\"undefined\"")) {
      sH+="<tr><td nowrap id=\"td"+sT+"_"+j+"\" class=\""+tdClass+"\" onmouseover=\"doMenu(this, 0);\" onmouseout=\"ti=setTimeout('clearMenu()',md);\"";
      sH+=(eval("typeof(url"+sT+"_"+j+")!=\"undefined\""))?" onclick=\"runMenu('"+siteurl+eval("url"+sT+"_"+j)+"')\" style=\"cursor:pointer;\">":">";
      sH+=eval("td"+sT+"_"+j);
      sH+=(eval("typeof(td"+sT+"_"+j+"_1)!=\"undefined\""))?tdArrow:"";
      sH+="</td></tr>";
      if(eval("typeof(td"+sT+"_"+j+"_1)!=\"undefined\""))
        pT[p++]=sT+"_"+j;
    }
    sH+="</table>";
    document.write(sH);
  }
}
