// ---------------------------------- oSubMenu --------------------------------
function oSubMenu (sSubMenuName, oMenu, sActiveZoneLayer, sSubMenuLayer) {
  this.Name=sSubMenuName;
  this.oMenu=oMenu;
  this.sActiveZoneLayer = sActiveZoneLayer;
  this.sSubMenuLayer = sSubMenuLayer;
  this.Width=800;
  this.Status=0;
  this.Visible=false;
  if(document.all){ //IE
    this.oActiveZoneLayer=document.all[sActiveZoneLayer];
        this.oSubMenuLayer=document.all[sSubMenuLayer];
    this.ActiveZoneCSS=this.oActiveZoneLayer.style;
        this.SubMenuCSS=this.oSubMenuLayer.style;
        this.VisibleOn="visible";
        this.VisibleOff="hidden";
        this.gw=document.body.clientWidth;
  } else { //NS
    this.oActiveZoneLayer=document.layers[sActiveZoneLayer];
        this.oSubMenuLayer=document.layers[sSubMenuLayer];
    this.ActiveZoneCSS=this.oActiveZoneLayer;
        this.SubMenuCSS=this.oSubMenuLayer;
        this.VisibleOn="show";
        this.VisibleOff="hide";
        this.gw=innerWidth-15;
  }
  this.X=this.SubMenuCSS.left;
  this.Y=this.SubMenuCSS.top;
  this.SubMenuOver=oSubMenu_SubMenuOver;
  this.SubMenuOut=oSubMenu_SubMenuOut;
  this.ActiveZoneOver=oSubMenu_ActiveZoneOver;
  this.ActiveZoneOut=oSubMenu_ActiveZoneOut;
  this.ShowSubMenu=oSubMenu_ShowSubMenu;
  this.HideSubMenu=oSubMenu_HideSubMenu;
}

function oSubMenu_SubMenuOver(){
  this.Status=1;
  this.oMenu.ClearTimeOut();
}

function oSubMenu_SubMenuOut(){
  this.Status=0;
  this.oMenu.HideAllwDelay();
}

function oSubMenu_ActiveZoneOver(){
  this.Status=1;
  this.oMenu.ClearTimeOut();
  this.ShowSubMenu();
}

function oSubMenu_ActiveZoneOut(){
  this.Status=0;
  this.oMenu.HideAllwDelay();
}

function oSubMenu_ShowSubMenu(){
  if (!this.Visible) {
    this.oMenu.HideAll();
        //alert(this.SubMenuCSS.left+" - "+this.ActiveZoneCSS.left+" - "+this.BaseLayerCSS.left);
        if(document.all){
      this.gw=document.body.clientWidth;
    } else {
          this.gw=innerWidth-15;
    }
    //if (this.gw<=this.Width) {
    //  posx=this.X;
    //} else {
    //  posx=parseInt(this.X)+Math.round((this.gw-this.Width)/2);
    //}
    posx=parseInt(this.X);
                //alert(posx);
        //if (this.X>=0){this.SubMenuCSS.left=this.X+"px";}
        //if (this.Y>=0){this.SubMenuCSS.top=this.Y+"px";}
    //this.SubMenuCSS.left=parseint(this.ActiveZoneCSS.left)+this.dX;
        //this.SubMenuCSS.top=parseint(this.ActiveZoneCSS.bottom)+1+this.dY;
        this.SubMenuCSS.left=posx;
        this.SubMenuCSS.top=this.Y;
    this.SubMenuCSS.visibility=this.VisibleOn;
    this.Visible=true;
  }
}

function oSubMenu_HideSubMenu(){
  if (this.Visible && (this.Status==0)) {
    this.SubMenuCSS.visibility=this.VisibleOff;
        this.Visible=false;
  }
}

// ---------------------------------- oMenu --------------------------------
function oMenu (sMenuName) {
  this.Name=sMenuName;
  this.arSubMenus = new Array();
  this.TimerID=0;
  this.TimeoutDelay=100;
  this.AddSubMenu=oMenu_AddSubMenu;
  this.Prepare=oMenu_Prepare;
  this.HideAll=oMenu_HideAll;
  this.HideAllwDelay=oMenu_HideAllwDelay;
  this.ClearTimeOut=oMenu_ClearTimeOut;
}

function oMenu_AddSubMenu(sSubMenuName, sActiveZoneLayer, sSubMenuLayer){
  return this.arSubMenus[this.arSubMenus.length]=new oSubMenu (sSubMenuName, this, sActiveZoneLayer, sSubMenuLayer);
}

function oMenu_Prepare(){
  for(i=0; i<this.arSubMenus.length;i++){
        this.arSubMenus[i].oActiveZoneLayer.onmouseover=new Function(this.Name+".arSubMenus["+i+"].ActiveZoneOver()");
    this.arSubMenus[i].oActiveZoneLayer.onmouseout=new Function(this.Name+".arSubMenus["+i+"].ActiveZoneOut()");
    this.arSubMenus[i].oSubMenuLayer.onmouseover=new Function(this.Name+".arSubMenus["+i+"].SubMenuOver()");
    this.arSubMenus[i].oSubMenuLayer.onmouseout=new Function(this.Name+".arSubMenus["+i+"].SubMenuOut()");
  }
}

function oMenu_HideAll(){
  this.ClearTimeOut();
  for(i=0; i<this.arSubMenus.length;i++){
    this.arSubMenus[i].HideSubMenu();
  }
}

function oMenu_HideAllwDelay(){
  this.ClearTimeOut();
  this.TimerID=setTimeout(this.Name+".HideAll()", this.TimeoutDelay);
}

function oMenu_ClearTimeOut(){
  if (this.TimerID!=0) {
    clearTimeout(this.TimerID);
        this.TimerID=0;
  }
}

// ------ выпадающее меню
function borderize(what,color){
what.style.borderColor=color
}

function borderize_on(e){
if (document.all)
source3=event.srcElement
else if (document.getElementById)
source3=e.target
if (source3.className=="menulines"){
borderize(source3,"black")
}
else{
while(source3.tagName!="TABLE"){
source3=document.getElementById? source3.parentNode : source3.parentElement
if (source3.className=="menulines")
borderize(source3,"black")
}
}
}

function borderize_off(e){
if (document.all)
source4=event.srcElement
else if (document.getElementById)
source4=e.target
if (source4.className=="menulines")
borderize(source4,"#D3D3D3")
else{
while(source4.tagName!="TABLE"){
source4=document.getElementById? source4.parentNode : source4.parentElement
if (source4.className=="menulines")
borderize(source4,"#D3D3D3")
}
}
}

