var xtimer=xpmhide=xpmvisible=0;
var stimer=spmhide=spmvisible=0;
var pm=new Array();
var sm=new Array();

function Menu(id,parent,pos) {
  this.className="Menu";
  this.width=240;
  this.visible=false;
  this.id=id;
  this.parent=parent;
  this.ul=document.createElement("ul");
  this.ul.style.position="absolute";
  this.ul.style.zIndex="1999";
  this.ul.style.margin="0px";
  this.ul.style.padding="0px";
  this.ul.style.height="24px";
  this.ul.style.whiteSpace="nowrap";
  this.ul.style.visibility="hidden";
  this.ul.style.display="none";
  this.ul.style.listStyle="none";
  var li=document.createElement("li");
  li.className="lmenu";
  li.style.backgroundPosition="top right";
  this.ul.appendChild(li);
  var li=document.createElement("li");
  li.className="cmenu";
  li.style.backgroundPosition="bottom left";
  li.style.color="#000000";
  li.innerHTML=parent.innerHTML;
  this.ul.appendChild(li);
  var li=document.createElement("li");
  li.className="amenu";
  li.style.backgroundPosition="bottom left";
  this.ul.appendChild(li);
  var li=document.createElement("li");
  li.className="rmenu";
  li.style.backgroundPosition="top right";
  this.ul.appendChild(li);
  this.ul.popupMenu=this;
  this.html=document.createElement("div");
  this.html.style.position="absolute";
  this.html.style.zIndex="1999";
  this.html.style.width=this.width+"px";
  this.html.style.left="0px";
  this.html.style.top="0px";
  this.html.style.visibility="hidden";
  this.html.style.display="none";
  var tbl=document.createElement("table");
  tbl.cellSpacing=0;
  tbl.cellPadding=0;
  tbl.style.border="none";
  tbl.style.width=this.width+"px";
  tbl.style.left="0px";
  tbl.style.top="0px";
  tbl.style.zIndex="1999";
  var tr=tbl.insertRow(-1);
  var td=tr.insertCell(-1);
  td.style.width=this.width+"px";
  td.style.height="4px";
  if (pos&&pos=="right") td.style.background="url(/img/menutopr.png) top left no-repeat";
  else td.style.background="url(/img/menutop.png) top left no-repeat";
  var tr=tbl.insertRow(-1);
  this.container=tr.insertCell(-1);
  this.container.style.width=this.width+"px";
  this.container.style.background="url(/img/menumiddle.png) top left repeat-y";
  var tr=tbl.insertRow(-1);
  var td=tr.insertCell(-1);
  td.style.width=this.width+"px";
  td.style.height="10px";
  td.style.background="url(/img/menubottom.png) top left no-repeat";
  this.html.popupMenu=this;
  this.ul.onmouseover=this.html.onmouseover=function(e) {
    if (xtimer) {
      clearTimeout(xtimer);
      xtimer=0;
    }
  }
  this.ul.onmouseout=this.html.onmouseout=function(e) {
    if (spmhide) return;
    xpmhide=this.popupMenu;
    xtimer=setTimeout("hideMenu()",50);
  }
  this.html.appendChild(tbl);
  document.body.appendChild(this.ul);
  document.body.appendChild(this.html);
  return this;
}
Menu.prototype.addContent=function(obj) {
  var td=obj.getElementsByTagName("td");
  for (var i=0; i<td.length; i++) {

  }
  this.container.appendChild(obj);
}
Menu.prototype.show=function(x,y,pos) {
  if (this.visible) return;
  if (xpmvisible&&xpmvisible.id&&xpmvisible.id!=this.id) xpmvisible.hide();
  this.ul.style.left=(x+5)+"px";
  this.ul.style.top=(y-24)+"px";
  this.ul.style.visibility="visible";
  this.ul.style.display="block";
  if (pos&&pos=="right") {
    this.html.style.left=(x-(230-this.ul.offsetWidth))+"px";
    this.html.style.top=y+"px";
  } else {
    this.html.style.left=x+"px";
    this.html.style.top=y+"px";
  }
  this.html.style.visibility="visible";
  this.html.style.display="block"; 
  this.visible=true;
  xpmvisible=this;
}
Menu.prototype.hide=function() {
  if (!this.visible) return;
  this.ul.style.visibility="hidden";
  this.ul.style.display="none";
  this.ul.style.left="0px";
  this.ul.style.top="0px";
  this.html.style.visibility="hidden";
  this.html.style.display="none";
  this.html.style.left="0px";
  this.html.style.top="0px";
  this.visible=false;
  xpmvisible=0;
}
Menu.prototype.setImage=function(img) {}
function hideMenu() {
  if (xpmhide) {
    xpmhide.hide();
    if (xpmhide.image) xpmhide.image.src=cacheHost()+"/m/0.jpg";
    if (xtimer) clearTimeout(xtimer);
    xtimer=0;
    xpmhide=0;
  }
}
function Submenu(id,groupid) {
  this.className="Menu";
  this.width=240;
  this.visible=false;
  this.id=id;
  this.groupid=groupid;
  this.html=document.createElement("div");
  this.html.style.position="absolute";
  this.html.style.zIndex="2000";
  this.html.style.width=this.width+"px";
  this.html.style.left="0px";
  this.html.style.top="0px";
  this.html.style.visibility="hidden";
  this.html.style.display="none";
  var tbl=document.createElement("table");
  tbl.cellSpacing=0;
  tbl.cellPadding=0;
  tbl.style.border="none";
  tbl.style.width=this.width+"px";
  tbl.style.left="0px";
  tbl.style.top="0px";
  tbl.style.zIndex="1999";
  var tr=tbl.insertRow(-1);
  var td=tr.insertCell(-1);
  td.style.width=this.width+"px";
  td.style.height="10px";
  td.style.background="url(/img/submenutop.png) top left no-repeat";
  var tr=tbl.insertRow(-1);
  var td=tr.insertCell(-1);
  td.style.width=this.width+"px";
  td.style.height="50px";
  td.style.verticalAlign="top";
  td.style.paddingLeft="9px";
  td.style.background="url(/img/menumiddle.png) top left repeat-y";
  this.image=new Image(222,46);
  this.image.src="/act/menuimage/0/"+groupid;
  td.appendChild(this.image);
  var tr=tbl.insertRow(-1);
  this.container=tr.insertCell(-1);
  this.container.style.width=this.width+"px";
  this.container.style.background="url(/img/menumiddle.png) top left repeat-y";
  var tr=tbl.insertRow(-1);
  var td=tr.insertCell(-1);
  td.style.width=this.width+"px";
  td.style.height="10px";
  td.style.background="url(/img/menubottom.png) top left no-repeat";
  this.html.popupMenu=this;
  this.html.onmouseover=function(e) {
    if (stimer) {
      clearTimeout(stimer);
      stimer=0;
    }
    if (xtimer) {
      clearTimeout(xtimer);
      xtimer=0;
    }
  }
  this.html.onmouseout=function(e) {
    spmhide=this.popupMenu;
    stimer=setTimeout("hideSubMenu()",50);
    xpmhide=this.popupMenu.masterMenu;
    xtimer=setTimeout("hideMenu()",50);
  }
  this.html.appendChild(tbl);
  document.body.appendChild(this.html);
  return this;
}
Submenu.prototype.addContent=function(obj) {
  var td=obj.getElementsByTagName("td");
  for (var i=0; i<td.length; i++) {

  }
  this.container.appendChild(obj);
}
Submenu.prototype.show=function(x,y,td) {
  if (this.visible) return;
  this.masterMenu=xpmhide;
  if (spmvisible&&spmvisible.id&&spmvisible.id!=this.id) spmvisible.hide();
  this.html.style.left=x+"px";
  this.html.style.top=y+"px";
  this.html.style.visibility="visible";
  this.html.style.display="block"; 
  this.visible=true;
  spmvisible=this;
}
Submenu.prototype.hide=function() {
  if (!this.visible) return;
  this.html.style.visibility="hidden";
  this.html.style.display="none";
  this.html.style.left="0px";
  this.html.style.top="0px";
  this.visible=false;
  spmvisible=0;
}
Submenu.prototype.setImage=function(img) {
  this.image.src=img.src;
}
function hideSubMenu() {
  if (spmhide) {
    spmhide.hide();
    spmhide.image.src="/act/menuimage/0/"+spmhide.groupid;
    if (stimer) clearTimeout(stimer);
    stimer=0;
    spmhide=0;
  }
}
function Imagemenu(id,parent,pos) {
  this.className="Menu";
  this.width=240;
  this.visible=false;
  this.id=id;
  this.parent=parent;
  this.ul=document.createElement("ul");
  this.ul.style.position="absolute";
  this.ul.style.zIndex="1999";
  this.ul.style.margin="0px";
  this.ul.style.padding="0px";
  this.ul.style.height="24px";
  this.ul.style.whiteSpace="nowrap";
  this.ul.style.visibility="hidden";
  this.ul.style.display="none";
  this.ul.style.listStyle="none";
  var li=document.createElement("li");
  li.className="lmenu";
  li.style.backgroundPosition="top right";
  this.ul.appendChild(li);
  var li=document.createElement("li");
  li.className="cmenu";
  li.style.backgroundPosition="bottom left";
  li.style.color="#000000";
  li.innerHTML=parent.innerHTML;
  this.ul.appendChild(li);
  var li=document.createElement("li");
  li.className="amenu";
  li.style.backgroundPosition="bottom left";
  this.ul.appendChild(li);
  var li=document.createElement("li");
  li.className="rmenu";
  li.style.backgroundPosition="top right";
  this.ul.appendChild(li);
  this.ul.popupMenu=this;
  this.html=document.createElement("div");
  this.html.style.position="absolute";
  this.html.style.zIndex="1999";
  this.html.style.width=this.width+"px";
  this.html.style.left="0px";
  this.html.style.top="0px";
  this.html.style.visibility="hidden";
  this.html.style.display="none";
  var tbl=document.createElement("table");
  tbl.cellSpacing=0;
  tbl.cellPadding=0;
  tbl.style.border="none";
  tbl.style.width=this.width+"px";
  tbl.style.left="0px";
  tbl.style.top="0px";
  tbl.style.zIndex="1999";
  var tr=tbl.insertRow(-1);
  var td=tr.insertCell(-1);
  td.style.width=this.width+"px";
  td.style.height="4px";
  if (pos&&pos=="right") td.style.background="url(/img/menutopr.png) top left no-repeat";
  else td.style.background="url(/img/menutop.png) top left no-repeat";
  var tr=tbl.insertRow(-1);
  var td=tr.insertCell(-1);
  td.style.width=this.width+"px";
  td.style.height="50px";
  td.style.verticalAlign="top";
  td.style.paddingLeft="9px";
  td.style.background="url(/img/menumiddle.png) top left repeat-y";
  this.image=new Image(222,46);
  this.image.src=cacheHost()+"/m/0.jpg";
  td.appendChild(this.image);
  var tr=tbl.insertRow(-1);
  this.container=tr.insertCell(-1);
  this.container.style.width=this.width+"px";
  this.container.style.background="url(/img/menumiddle.png) top left repeat-y";
  var tr=tbl.insertRow(-1);
  var td=tr.insertCell(-1);
  td.style.width=this.width+"px";
  td.style.height="10px";
  td.style.background="url(/img/menubottom.png) top left no-repeat";
  this.html.popupMenu=this;
  this.ul.onmouseover=this.html.onmouseover=function(e) {
    if (xtimer) {
      clearTimeout(xtimer);
      xtimer=0;
    }
  }
  this.ul.onmouseout=this.html.onmouseout=function(e) {
    if (spmhide) return;
    xpmhide=this.popupMenu;
    xtimer=setTimeout("hideMenu()",50);
  }
  this.html.appendChild(tbl);
  document.body.appendChild(this.ul);
  document.body.appendChild(this.html);
  return this;
}
Imagemenu.prototype.addContent=function(obj) {
  this.container.appendChild(obj);
}
Imagemenu.prototype.show=function(x,y,pos) {
  if (this.visible) return;
  if (xpmvisible&&xpmvisible.id&&xpmvisible.id!=this.id) xpmvisible.hide();
  if (this.image) this.image.src=cacheHost()+"/m/0.jpg";
  this.ul.style.left=(x+5)+"px";
  this.ul.style.top=(y-24)+"px";
  this.ul.style.visibility="visible";
  this.ul.style.display="block";
  if (pos&&pos=="right") {
    this.html.style.left=(x-(230-this.ul.offsetWidth))+"px";
    this.html.style.top=y+"px";
  } else {
    this.html.style.left=x+"px";
    this.html.style.top=y+"px";
  }
  this.html.style.visibility="visible";
  this.html.style.display="block"; 
  this.visible=true;
  xpmvisible=this;
}
Imagemenu.prototype.hide=function() {
  if (!this.visible) return;
  this.ul.style.visibility="hidden";
  this.ul.style.display="none";
  this.ul.style.left="0px";
  this.ul.style.top="0px";
  this.html.style.visibility="hidden";
  this.html.style.display="none";
  this.html.style.left="0px";
  this.html.style.top="0px";
  this.visible=false;
  xpmvisible=0;
}
Imagemenu.prototype.setImage=function(img) {
  if (img) this.image.src=img.src; else this.image.src=cacheHost()+"/m/0.jpg";
}
