function NWMenu(selfVarName, clientId, defenition, map, readingDirection, lang, levelsToOutput, levelStart, topLevelOnlyCurrent, showRoot, pushRootIntoSecondLevel){
    this.selfVarName = selfVarName;
    this.clientId = clientId;
    this.def = defenition;
    this.map = map;
    this.readingDirection = (readingDirection==null)? NWGlobal.pageDir_get() : readingDirection;
    this.readingAlign = (this.ReadingDirection == "rtl") ? "right" : "left";
    this.readingOppositeAlign = (this.ReadingDirection == "rtl") ? "left" : "right";
    this.lang = lang;
    this.levelsToOutput = levelsToOutput;
    this.levelStart = levelStart;
    this.showRoot = showRoot;
    this.pushRootIntoSecondLevel = pushRootIntoSecondLevel;
    this.topLevelOnlyCurrent = topLevelOnlyCurrent;
    this.topLevelOnlyCurrentID = null;
    
    this.selectedAnchorItemId = null; 
    
    this.noMenuDisplayNoneControls = null;
    this.noMenuVisiblityHiddenControls = null;
    this.noMenuDisplayBlockControls = null;
    this.noMenuVisiblityVisibleControls = null;
    
    this.isEmpty = false;
    
    this.mapLoadedHandler = function(noTransorm){
        if(!this.def.isReadyForTransform_get()){
            if(noTransorm){
               window.setTimeout(selfVarName + ".mapLoadedHandler(true)",100);
            }else{
               window.setTimeout(selfVarName + ".mapLoadedHandler()",100);
            }
            return;
        }
        
        var elHtml = NWGlobal.getElementById(clientId);
        if(elHtml!=null){        
           if(NWMenu_oCommonXslSelectNodes!=null){
              var oMapTmp = this.map.cloneForMenu(this);
              if(oMapTmp!=null) this.map = oMapTmp;            
           }
           if(noTransorm) return;
           
           var sHtml = this.def.transform(this, this.map.getData(),-1);
           if(sHtml!=""){
              //alert(sHtml);
              elHtml.innerHTML = sHtml;
              return;
           }
        }
        this.applyNoMenu();
    }
    
    this.applyNoMenu = function(){
        this.isEmpty = true;
        applyNoMenu1(this.noMenuDisplayNoneControls,true,true);
        applyNoMenu1(this.noMenuVisiblityHiddenControls,false,true);
        applyNoMenu1(this.noMenuDisplayBlockControls,true,false);
        applyNoMenu1(this.noMenuVisiblityVisibleControls,false,false);        
    }
    
    this.applyNoMenuSync = function(){
        // todo wait untill all elements will be loaded
        this.applyNoMenu();
    }
    
    function applyNoMenu1(list,isDisplay,isHide){
        if(list==null)return;
        for(var i=0; i<list.length; i++){
            var oCtl = NWGlobal.getElementById(list[i]);
            if(oCtl!=null){
                if(isDisplay){
                    oCtl.style.display = (isHide) ? "none" : "";
                }else{
                    oCtl.style.visibility = (isHide) ? "hidden" : "visible";
                }
            }
        }    
    }
}//~~~ NWMenu

var NWMenu_oCommonXsl = null;
var NWMenu_oCommonXslSelectNodes = null;
function NWMenu_CommonXsl_SetXsl(xmlDom){
    //if(xmlDom==1)alert(1); else alert(xmlDom.xml_get());   
    if(xmlDom == 1){
        NWMenu_oCommonXsl = 1;
    }else{
        var oRootNode = xmlDom.selectSingleNode("//ROOT");
        if(oRootNode == null){
            NWMenu_oCommonXsl = xmlDom;
        }else{
            var oXml1 = new NWXmlDocument();oXml1.async_set(false);
            oXml1.loadXML(oRootNode.getChildNode(0).xml_get());                       
            
            var oXml2 = new NWXmlDocument();oXml2.async_set(false);
            oXml2.loadXML(oRootNode.getChildNode(1).xml_get());
                                   
            NWMenu_oCommonXslSelectNodes = new NWXslFactory(oXml2);
            NWMenu_oCommonXsl = oXml1;
            //alert(NWMenu_oCommonXsl.xml_get());
            //alert(NWMenu_oCommonXslSelectNodes.xml_get()); 
        }        
    }    
}
function NWMenu_CommonXsl_SetXsl1(xmlDom){
    NWMenu_oCommonXslSelectNodes = new NWXslFactory(xmlDom);
    NWMenu_oCommonXsl = 1;    
}

function NWMenuDefenition(selfVarName,intId){
    var oXslT = null;
    var oXsl = null;
    var ar_oLevels = new Array;
    
    this.levels = ar_oLevels;
    
    this.setXsl = function(xslDom){
        oXsl = xslDom;
        this.setXsl1();        
    }    
    this.setXsl1 = function(){
        if(NWMenu_oCommonXsl == null){
            window.setTimeout(selfVarName + ".setXsl1()",100);
            return;
        }
        if(NWMenu_oCommonXsl==1){
            oXslT = new NWXslFactory(oXsl);
        }else{
            var oXmlNew = new NWXmlDocument();
            oXmlNew.async_set(false);
            oXmlNew.loadXML(NWMenu_oCommonXsl.xml_get());
            
            var oNodes = oXsl.documentElement_get().selectNodes("child::*");
            var oRoot = oXmlNew.documentElement_get();
            for(var i=0; i<oNodes.length; i++){
                var oNodeNew = oNodes[i].cloneNode(true);
                oRoot.appendChild(oNodeNew)
            }
            oXslT = new NWXslFactory(oXmlNew);            
        }
        oXsl = null;
    }
    
    this.createAndAppendLevel = function(levelNumber){
        var sName = selfVarName + ".levels.[" + ar_oLevels.length + "]";
        var oRv = new NWMenuDefenitionLevel(sName, levelNumber, ar_oLevels.length, this);
        ar_oLevels.push(oRv);
        return oRv;
    }
    this.regImage = function(imageId,imageSrc){
        var oImage = new Image();
        //window.open(NWGlobal.convertAbsolutePathToReative(imageSrc));
        oImage.src = NWGlobal.convertAbsolutePathToReative(imageSrc);        
        this[imageId] = oImage;        
    }
    
    this.isReadyForTransform_get = function(){
        return (oXslT!=null);    
    }
    
    this.transform = function(menu, input, startLevelNumber)
    {
         if(oXslT==null) return "";
         
         var oNodeToTransform;
         if(NWMenu_oCommonXslSelectNodes == null){
             oNodeToTransform = transformOld(this, menu, input, startLevelNumber);
         }else{
             oNodeToTransform = input;
         }
         if(oNodeToTransform == null) return "";
         
         var oXslProc = oXslT.createProcessor();
            
         oXslProc.addParameter("menu-id", menu.selfVarName);
         oXslProc.addParameter("def-id", selfVarName);
         oXslProc.addParameter("def-id-css", intId);
         oXslProc.addParameter("page-dir", menu.readingDirection);
         oXslProc.addParameter("page-align", menu.readingAlign);
         oXslProc.addParameter("page-align-1", menu.readingOppositeAlign);
         oXslProc.addParameter("page-lang", menu.lang);
         if(oXslProc.impl_get()!="IE") oXslProc.addParameter("is-mz-impl", "1");         
         oXslProc.addParameter("user-agent", navigator.userAgent);
         //if(navigator.userAgent.indexOf("Opera") >= 0)oXslProc.addParameter("use-top-level-handlers", "1");         
         
         if(startLevelNumber > 1){
             if(menu.levelsToOutput > 0){
                 oXslProc.addParameter("levels-to-out", menu.levelsToOutput); //~~~ differences between startLevelNumber and levelsToOutput calculated in the xsl
             }             
             oXslProc.addParameter("levels-offset", startLevelNumber - 1);
         }else{
             oXslProc.addParameter("levels-to-out", menu.levelsToOutput);
         }         
         
         //alert(menu.selfVarName + "\n\n\n" + oNodeToTransform.xml_get());
         oXslProc.input_set(oNodeToTransform);
         if(oXslProc.transform()){
              var sHtml = oXslProc.output_get();
              if(oXslProc.impl_get()!="IE"){
                   sHtml = sHtml.replace(/\<!--nwlt--\>&lt;/g,"<").replace(/&gt;\<!--nwgt--\>/g,">").replace(/\<[\/]?tbody\>/gi,"");
                   if(navigator.userAgent.indexOf("Opera") >= 0){
                       sHtml = sHtml.replace(/\<!--nwgt--\>/g,"");
                   }
              }
              //alert(sHtml);
              return sHtml;
          }else{
              alert("xsl fail");
              //alert("xsl fail\n"+oNodeToTransform.xml_get());
              return "";
          }
    }
    
    function transformOld(def, menu, input, startLevelNumber){
          var oNodeToTransform = input;
          if (menu.levelStart > 1 || menu.topLevelOnlyCurrent){                
             if(startLevelNumber==-1){
                 //~~~ top level of menu
                 var iStartLevelNumber = menu.levelStart;
                 if (iStartLevelNumber < 1 && topLevelOnlyCurrent) iStartLevelNumber = 1;
                    
                 var iSearchMethod = 0;                    
                 var oNodeSelected = oNodeToTransform.selectSingleNode("//A[@nwSs='yes']/ancestor::UL[@nwL=" + iStartLevelNumber + "]");
                 if(oNodeSelected == null && menu.selectedAnchorItemId != null){
                     iSearchMethod = 1;
                     oNodeSelected = oNodeToTransform.selectSingleNode("//A[@nwInd='" + menu.selectedAnchorItemId + "']/ancestor::UL[@nwL=" + iStartLevelNumber + "]");
                     if(oNodeSelected == null){
                         iSearchMethod = 2;
                         oNodeSelected = oNodeToTransform.selectSingleNode("//A[@nwInd='" + menu.selectedAnchorItemId + "']/parent::LI/UL[@nwL=" + iStartLevelNumber + "]");
                     }
                  }                                        
                  if (oNodeSelected == null){
                     alert("Cant' find selected node (LevelStart or TopLevelOnlyCurrent mode)");
                     oNodeToTransform = null;
                  }else{
                     oNodeToTransform = oNodeSelected.cloneNode(true);
                  }
                                                                                            
                  //~~~ remove current node siblings
                  if (menu.topLevelOnlyCurrent){
                         switch (iSearchMethod){
                            case 0:
                                oNodeSelected = oNodeToTransform.selectSingleNode("LI[descendant::A/@nwSs='yes']");
                                break;
                            case 1:
                            case 2:
                                oNodeSelected = oNodeToTransform.selectSingleNode("LI[descendant::A/@nwInd='" + menu.selectedAnchorItemId + "']");
                                break;
                            default:
                                oNodeSelected = null;                                
                         }
                   
                         if (oNodeSelected == null){
                                alert("Cant' find selected node (TopLevelOnlyCurrent mode)");
                                oNodeToTransform = null;
                         }else{
                                menu.topLevelOnlyCurrentID = oNodeSelected.selectSingleNode("A").attributes.getNamedItem("nwInd").value;
                                                    
                                var lstXmlNodes = oNodeToTransform.selectNodes("LI");                            
                                for(var i=0; i<lstXmlNodes.length; i++){
                                   var oNodeTmp = lstXmlNodes[i];
                                   if (oNodeTmp.nativeObject_get() != oNodeSelected.nativeObject_get()){
                                       oNodeToTransform.removeChild(oNodeTmp);
                                   }
                                }                            
                        }
                  }
                  //~~~ remove current node siblings
                  //~~~ top level of menu
             }else{
                  //~~~ not top level of menu
                  oNodeToTransform = oNodeToTransform.cloneNode(true);
             }//~~~ if(startLevelNumber==-1)
             
             //~~~ fix level                   
             if(oNodeToTransform != null){
                  var iOffset = menu.levelStart - 1;                
                  var lstXmlNodes = oNodeToTransform.selectNodes("descendant-or-self::UL/@nwL");
                  for(var i=0; i<lstXmlNodes.length; i++){
                       var oNodeTmp = lstXmlNodes[i];
                       oNodeTmp.nodeValue_set(oNodeTmp.nodeValue_get() - iOffset);
                  }
                   
                  var oXmlToTransform = new NWXmlDocument();
                  oXmlToTransform.async_set(false);
                  oXmlToTransform.loadXML(oNodeToTransform.xml_get());
                  oNodeToTransform = oXmlToTransform;
             }
        }//~~~ if (menu.levelStart > 1 || menu.topLevelOnlyCurrent)
        
        return oNodeToTransform;
    }//~~~ transformOld()                
}//~~~ class NWMenuDefenition

function NWMenuDefenitionLevel(selfVarName, levelNumber, levelIndex, defenition){
    var ar_oStates = new Array();
    
    this.itemCount = -1;
    
    this.childDisposition = null;
    this.childOpenEventHdl = null;
    this.childInlineOpenEventExtHdl = null;
    this.childOpenDelay = null;
    
    this.itemWidthType = null;this.itemWidthValue = null;
    //this.itemHeightType = null;this.itemHeightValue = null;
    
    this.states = ar_oStates;
    this.normalState = null;
    this.overState = null;
    
    this.createAndAppendItemState = function(stateMask, stateName, isAlsoSelected){
        var sName = selfVarName + ".states.[" + ar_oStates.length + "]";
        var oRv = new NWMenuItemState(sName, stateName);
        ar_oStates.push(oRv);
        if(stateName=="normal")this.normalState=oRv;
        if(stateName=="over")this.overState=oRv;
        if(isAlsoSelected=="yes")oRv.isAlsoSelected=true;        
        return oRv;
    }    
    
    this.setChildDisposition = function(alignParent,alignChild,valignParent,valignChild,offsetX,offsetY,offsetXmz,offsetYmz){        
        var sTmp = "'"+alignParent+"','"+alignChild+"','"+valignParent+"','"+valignChild+"',";
        if(NWGlobal.BrName=="MZ"){
            sTmp += (offsetXmz + "," + offsetYmz);
        }else{
            sTmp += (offsetX + "," + offsetY);
        }
        this.childDisposition = sTmp;
    }
    
    this.getNextLevel = function(){
       if((levelIndex + 1) < defenition.levels.length){
          return defenition.levels[levelIndex + 1];
       }
       return this;
    }
    
    this.uiHandler = function(menu,obj,objlnk,type){              
       if(type=="msov"){
           if(this.overState!=null)this.overState.applyState(obj); 
           if(this.childOpenEventHdl=="mouse-over"){
               if(obj.getAttribute("nwCh")=="yes") this.showChildren(menu,obj);else this.hideSiblingChildren(menu,obj);
           }else{
               this.hideSiblingChildren_OnlyMouseOverFly(menu,obj);
           }           
       }else if(type=="mslv"){
           this.normalState.applyState(obj);           
       }else if(type=="clk"){
           if(this.childOpenEventHdl != "click-url-go"){                                
               if(this.childOpenEventHdl=="click-url-disable" || this.childOpenEventHdl=="click-url-doubleclick"){
                   if(obj.getAttribute("nwCh")=="yes"){
                      if(this.showChildren(menu,obj))return false;
                   }else{
                      this.hideSiblingChildren(menu,obj);
                   }                                   
               }
           }
           if(this.openLink(menu,obj,objlnk,type))return true;                                  
       }else if(type=="dblclk"){
           if(this.childOpenEventHdl=="double-click"){
               if(obj.getAttribute("nwCh")=="yes") this.showChildren(menu,obj);else this.hideSiblingChildren(menu,obj);
           }else if(this.childOpenEventHdl=="click-url-doubleclick" && obj.getAttribute("nwCh")=="yes"){
               this.openLink(menu,obj,objlnk,type);
           }           
       }       
       return false;
    }
    
    this.applyRemoveState = function(menu,obj,state,apply){
        var sClassName = obj.className;
        var sTp = obj.getAttribute("nwTp");
        var sClassName = "nw-i";
        
        if(sTp!=null && sTp!=""){
           if(sTp.indexOf("h")>=0)sClassName += " .nw-ih";
           if(sTp.indexOf("d")>=0)sClassName += " .nw-id";
        }
        if(apply){
           switch(state){
               case "select" : sClassName += " .nw-is";
               case "d-select" : sClassName += " .nw-isd";
               case "open"  : sClassName += " .nw-io";
               case "down" : sClassName += " .nw-msdn";
               case "over" : sClassName += " .nw-msov";
           }
        }
        
        //NWGlobal.setClassName(null,obj,null,state,apply,false);
    }    
    
    //~~~ private methods
    this.openLink = function(menu,obj,objlnk,type){
        var sTp = obj.getAttribute("nwTp");if(sTp != null && sTp.indexOf("d") >= 0) return false;
        
        if(objlnk!=null && type=="clk")return true;
        
        var oA = objlnk;
        if(oA==null){
            var colA = obj.getElementsByTagName("A");
            for(var i=0; i<colA.length;i++){
               if(colA[i].getAttribute("nwl")=="y"){
                  oA = colA[i];
                  break;
               }
            }        
        }        
        if(oA!=null){
            var sHref = oA.href;
            if(sHref!=null && sHref!=""){
               if(NWGlobal.BrName == "IE" && NWGlobal.BrVers <= 6){
                   var oRe = new RegExp("href=\\\"([^\\\"]+)\\\"","i");
                   var oReMatch  = oRe.exec(oA.outerHTML);
                   if(oReMatch != null && oReMatch.length > 1){
                       sHref = oReMatch[1];
                   }
               }
            
               var sTarget = oA.target;
               if(sTarget!=null && sTarget!="") 
                   window.open(sHref,sTarget);
               else               
                   location.href=sHref;
            }
        }
                
        return false;
    }    
    this.showChildren = function(menu,obj){               
        var oItem = NWMenuItem_get(obj,menu,this,false);
        if(oItem!=null){
           return oItem.showChildren();
        }
        return false;        
    }    
    this.hideSiblingChildren = function(menu,obj){               
        var oItem = NWMenuItem_get(obj,menu,this,false);
        if(oItem!=null){
           return oItem.hideSiblingChildren();
        }
        return false;        
    }
    this.hideSiblingChildren_OnlyMouseOverFly = function(menu,obj){
        var oItem = NWMenuItem_get(obj,menu,this,false);
        if(oItem!=null){
           return oItem.hideSiblingChildren(true);
        }
        return false;
    }
}//~~~ class NWMenuDefenitionLevel

var MenuActivated=false;

function NWMenuUIHdl(obj,ev,type,menuVarName,levelIndex,objLink){ 
if(MenuActivated)
{   
    var bRv = false;
    //var oMenu = null;try{eval("oMenu = " + menuVarName);}catch(e){oMenu = null}; 
    var oMenu = menuVarName;       
    if(oMenu != null){
       bRv = oMenu.def.levels[levelIndex].uiHandler(oMenu,obj,objLink,type);           
    }
    //if(type=="msov")alert(obj.id + "\n" + obj.innerHTML);
    if(!bRv && (NWGlobal.BrName!="IE" || type!="msov"))ev.cancelBubble = true;
    //if(!bRv)ev.cancelBubble = true;    
    return bRv;
}
}//~~~ function NWMenuUIHdl

function setOnloadEvent(func)
{
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		window.attachEvent('onload',func);
	}
	else
	{
		window.addEventListener('load',func,false);
	}
}
function ActivateMenu(){
    MenuActivated=true;
    
    NWGlobal.BrName=BrsrInfo.BrName();
    NWGlobal.BrVers=BrsrInfo.BrVers();    
}
setOnloadEvent(ActivateMenu);
//setOnloadEvent(CheckExplorer);

function NWMenuUIHandler(obj,ev,type,menuVarName,levelIndex){        
    var bRv = false;    
    var bContinue = true;
    var elSrc = NWGlobal.getEventTargetElement(ev);
    var elItem = elSrc;
    var elA = null;
    while(true){
       if(elItem.className.indexOf("nw-i")==0 && elItem.tagName=="TABLE"){
          break;
       }
       if(elItem.tagName=="A" && elItem.getAttribute("nwl")=="y"){
          elA = elItem;
       }
       elItem = elItem.offsetParent;
       if(elItem==null || elItem==obj){
           bContinue = false;
           break;
       }
    }
    if(bContinue){
        bRv = NWMenuUIHdl(elItem,ev,type,menuVarName,levelIndex,elA);        
    }     
    return bRv;
}//~~~ function NWMenuUIHandler

function NWMenuItemState(selfVarName, stateName){
    this.stateName = stateName;
    this.isAlsoSelected = false;
    
    this.iconImg = null; this.iconChildClosedImg = null; this.iconChildOpenedImg = null;
    
    this.leftArrow = null; this.rightArrow = null; this.topArrow = null; this.bottomArrow = null;
    
    this.borderGraphics = null;    
    this.borderGraphicsCornerTopRight = null;
    this.borderGraphicsCornerTopLeft = null;
    this.borderGraphicsCornerBottomLeft = null;
    this.borderGraphicsCornerBottomRight = null;
    
    this.applyState = function(obj){
        var sSel = (this.isAlsoSelected) ? obj.getAttribute("nwSs") : null;
        if(sSel == null || sSel == ""){
            NWGlobal.setClassName(null, obj, null, 'nw-is-4', (stateName=="over"), false);
           
            if(this.borderGraphics){
                applyCornerImage(this,this.borderGraphicsCornerTopLeft,obj,0,0);
                applyCornerImage(this,this.borderGraphicsCornerTopRight,obj,0,2);
                applyCornerImage(this,this.borderGraphicsCornerBottomLeft,obj,2,0);
                applyCornerImage(this,this.borderGraphicsCornerBottomRight,obj,2,2);
            }  
        }              
    }
    
    function applyCornerImage(state, cornerImage, obj, row, cell){
        if(cornerImage==null)return;        
        var oCell = obj.rows[row].cells[cell];
        var oImg = oCell.getElementsByTagName("IMG")[0];
        if(oImg.src != cornerImage.src){
            oImg.src = cornerImage.src;
        }        
    }
}

function NWMenuItem_get(htmlItemObject,menu,level,doNotCreate){
   var sId = htmlItemObject.id + "_NWMenuItem";
   if(window[sId]==null){
       if(doNotCreate != null && doNotCreate) return null;
       /*var elParent = htmlItemObject;
       while(elParent!=null){
          if(elParent.tagName=="DIV" && elParent.getAttribute("nwMnu") == "yes")break;
          elParent = elParent.parentNode;
       }*/
       var oItem = new NWMenuItem(sId, htmlItemObject, menu, level);
       window[sId] = oItem;
       return oItem;
   }else{
       var oItem = window[sId];
       return oItem;
   }   
}//~~~ function NWMenuItem_get

function NWMenuItem(selfVarName, itemElement, menu, level){
   this.selfVarName = selfVarName;
   
   var sItemNodeId = itemElement.id.replace(menu.selfVarName+"_","").replace(/\_i$/,"");
   var bHaveChildren = (itemElement.getAttribute("nwCh")=="yes");
   var bChildrenIsInline = (level.childDisposition=="inline");
   var bHideSiblings = (!bChildrenIsInline || level.childInlineOpenEventExtHdl=="open-and-close-others")
   var bShowHide = (bChildrenIsInline && level.childOpenEventHdl.indexOf("click")>=0);
   var bAlwaysShow = (level.childInlineOpenEventExtHdl=="always-opened");
   
   var hOpenTimeOut = null;

   this.showChildren = function(){ 
      return this.showChildren1();           
   }
   this.hideChildren = function(){
      return this.hideChildren1();     
   }
   this.hideSiblingChildren = function(onlyMouseOverFly){
      this.ensureFirstSiblingItem();
      return this.firstSiblingItem.hideSiblingChildren1(this,onlyMouseOverFly);                      
   }
   
   //~~~ private methods
   this.firstChild = null;
   this.children = null;
   this.firstSiblingItem = null;
   this.siblingItems = null;
   
   var bFirstChildIsEnsured = false;
   this.ensureFirstChild = function(){
      if(!bFirstChildIsEnsured){
          var oXmlNode = menu.map.getFirstChildrenDataByItemId(sItemNodeId);                 
          if(oXmlNode!=null){
              var sFirstChildElementId = oXmlNode.attributes.getNamedItem("nwInd").value;
              sFirstChildElementId =  menu.selfVarName + "_" + sFirstChildElementId + "_i";
              var oFirstChildElement = NWGlobal.getElementById(sFirstChildElementId);
              if(oFirstChildElement!=null){
                  var oFirstChildItem = NWMenuItem_get(oFirstChildElement,menu,null,true);
                  if(oFirstChildItem==null)oFirstChildItem = NWMenuItem_get(oFirstChildElement,menu,level.getNextLevel(),false);
                  if(oFirstChildItem!=null){
                     this.firstChild = oFirstChildItem;
                     bFirstChildIsEnsured = true;
                  }
              }
          }
      }
   }//~~~this.ensureFirstChild = function(){
   
   //17-12-2008 start   - itemElement is the main menu element - we can attach events to it   
	NWGlobal.attachEvent(itemElement, "mouseout", function (evt){CloseMainNWMenuItem_lvHandler(evt, selfVarName);} );
	
   
   this.ensureChildren = function(){           
      if(bHaveChildren && this.children == null){
          var sChildrenFieldName = selfVarName + ".children";
          var sChildrenDivId = itemElement.id.replace(/\_i$/,"_c");
          var elChildrenDiv = NWGlobal.getElementById(sChildrenDivId);
          
          if(bChildrenIsInline){
                if(elChildrenDiv!=null){
                    this.children = new NWMenuItem_Inline(sChildrenFieldName, elChildrenDiv);
                }          
          }else{
                if(elChildrenDiv==null){
                    var oXmlNode = menu.map.getChildrenDataByItemId(sItemNodeId);                 
                    if(oXmlNode!=null){
                        var sHtml = menu.def.transform(menu,oXmlNode);
                        if(sHtml!=""){
                            var oDiv = document.createElement("div");
                            oDiv.id = sChildrenDivId;
                            oDiv.setAttribute("nwMnu","yes");
                            document.body.appendChild(oDiv);
                            oDiv.style.position="absolute";
                            oDiv.style.visibility = "hidden";
                            oDiv.style.display = "none";
                            oDiv.style.top = "0px";
                            oDiv.style.width = "200px";
                                                     
                            oDiv.innerHTML = sHtml;                            


                            //18-12-2008 create a hidden iframe behind the menu to hide the dropdowns
					        var iframeHtml = "";

				            if (NWGlobal.BrName == "IE" && NWGlobal.BrVers <7){


					        //ie6, add transparent iframe behind the table to hide the select boxes


					            var oIframe = document.createElement("Iframe");
					            oIframe.id = sChildrenDivId + "Iframe";
					            oIframe.setAttribute("src",document.images[0].src); // load the first image from the page as a source -probably cached
					            oIframe.setAttribute("frameborder","yes");
					            oIframe.setAttribute("scrolling","no");

					            oIframe.style.position="absolute";
						        oIframe.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
						        oIframe.style.zIndex = -1;

					            oIframe.style.left = "0px";
					            oIframe.style.top = "0px";
					            oIframe.style.width = "100%";
					            oIframe.style.height = "0px";

					            iframeHtml = oIframe.outerHTML;

				            }else{
					        iframeHtml = "";
				            }

                                    oDiv.innerHTML = iframeHtml + sHtml;   // added iframeHtml before
				            //18-12-2008 end
                            var sCommand = "var oFly = new NWAbsoluteElementEx('"+sChildrenFieldName+"','"+itemElement.id+"','"+sChildrenDivId+"',"+level.childDisposition+");";
                            eval(sCommand);
                            oFly.freeStateObject = this;
                            oFly.outerClickAutoClose = true;
                            
                            oFly.timeoutAutoCloseCancelCallBack = NWMenuItem_TimeoutHandler;
                            
                            //17-12-2008 added mouseOutAutoClose =true, changed 2000 to 60000
                            oFly.mouseOutAutoClose = true;
                            if(level.childOpenDelay != null && level.childOpenDelay > 0){                            
                               oFly.timeoutAutoClose = level.childOpenDelay + 60000;
                            }else{
                               oFly.timeoutAutoClose = 60000;
                            }
                            
                            this.children = oFly;
                            //NWGlobal.setChildCoodinates(document.body,oDiv,'center','center','top','top',0,0);
                        }//~~~ if(sHtml!=""){
                    }//~~~ if(oXmlNode!=null){                                             
                }//~~~ if(elChildrenDiv==null){            
          }//~~~ if(level.childDisposition!="inline"){
      }//~~~ if(this.children == null){      
   }//~~~ this.ensureChildren = function(){
   this.ensureFirstSiblingItem = function(){
       if(this.firstSiblingItem==null){
          var lstSiblings = menu.map.getSiblingsDataByItemId(sItemNodeId);
          var sSiblingElementId = lstSiblings[0].attributes.getNamedItem("nwInd").value;
          sSiblingElementId =  menu.selfVarName + "_" + sSiblingElementId + "_i";
          var oSiblingElement = NWGlobal.getElementById(sSiblingElementId);
          if(oSiblingElement!=null){
              var oItem = NWMenuItem_get(oSiblingElement,menu,level,false);
              oItem.ensureSiblingItems(lstSiblings);
              this.firstSiblingItem = oItem;              
          }else if(menu.topLevelOnlyCurrentID != null){
              for(var i=0; i<lstSiblings.length; i++){                  
                  var sId = lstSiblings[i].attributes.getNamedItem("nwInd").value;
                  if(sId == menu.topLevelOnlyCurrentID){
                      sSiblingElementId =  menu.selfVarName + "_" + sId + "_i";
                      var oSiblingElement = NWGlobal.getElementById(sSiblingElementId);
                      if(oSiblingElement!=null){                           
                           var oItem = NWMenuItem_get(oSiblingElement,menu,level,false);
                           if(oItem.siblingItems==null){
                              var ar_oTmp = new Array(); ar_oTmp.push(lstSiblings[i]);
                              oItem.ensureSiblingItems(ar_oTmp);
                           }
                           this.firstSiblingItem = oItem;     
                      }
                      break;
                  }
              }          
          }
       }
    }//~~~ this.ensureFirstSiblingItem = function(){
    this.ensureSiblingItems = function(siblingsList){                
       if(this.siblingItems==null){
          var lstSiblings = siblingsList;
          var ar_oSiblings = new Array();          
          for(var i=0; i<lstSiblings.length; i++){
             if(level.itemCount > 0 && i >= level.itemCount) break;
                         
             var sSiblingElementId = lstSiblings[i].attributes.getNamedItem("nwInd").value;
             sSiblingElementId =  menu.selfVarName + "_" + sSiblingElementId + "_i";             
             
             var oSiblingElement = NWGlobal.getElementById(sSiblingElementId);
             if(oSiblingElement!=null){
                var oItem = NWMenuItem_get(oSiblingElement,menu,level,false);
                ar_oSiblings.push(oItem);                
             }else{
                ar_oSiblings.push(sSiblingElementId);
             }                                
          }
          this.siblingItems = ar_oSiblings;
       }
   }//~~~ this.ensureSiblingItems = function(){
   this.getSiblingItem = function(index){
       var oTmp = this.siblingItems[index];
       if(oTmp!=null){
          if(typeof(oTmp)=="string"){
             oTmp = NWGlobal.getElementById(oTmp);
             if(oTmp!=null){
                oTmp = NWMenuItem_get(oTmp,menu,level,false);
                this.siblingItems[index] = oTmp;
                return oTmp;                
             }
          }else{
             return oTmp;
          }
       }
       return null;       
   }//~~~ this.getSiblingItem = function(){   
   this.hideSiblingChildren1 = function(item, onlyMouseOverFly){
      var bRv = false;
      if(bHideSiblings || onlyMouseOverFly){
          for(var i=0; i<this.siblingItems.length; i++){
             var oMenuItem = this.getSiblingItem(i);
             if(oMenuItem.hideChildren1(onlyMouseOverFly)) bRv = true;            
          }
      }
      return bRv;
   }//~~~ this.hideSiblingChildren1 = function(){
   this.hideChildren1 = function(onlyMouseOverFly){
      var bRv = false;
      this.ensureChildren();
      
      if(hOpenTimeOut!=null){
          window.clearInterval(hOpenTimeOut);
          hOpenTimeOut = null;
      }
      
      if(this.children != null){
        if(onlyMouseOverFly){
            //if(confirm(itemElement.textContent)){
            //   debugger
            //}
            if(!bChildrenIsInline){
               bRv = this.children.hide();
            }
            this.ensureFirstChild();
            if(this.firstChild!=null && !this.firstChild.hideChildren1(onlyMouseOverFly))this.firstChild.hideSiblingChildren(onlyMouseOverFly);
        }else{
            if(this.children.hide()){
               this.ensureFirstChild();
               if(this.firstChild!=null && !this.firstChild.hideChildren())this.firstChild.hideSiblingChildren();
               bRv = true;
            }        
        }
     }
     if(bRv){
        this.apllyOpenState(false);
     }
     return bRv;     
   }//~~~ this.hideChildren1 = function(){
   this.showChildren1 = function(callByInterval){      
      if(bShowHide){
          this.ensureChildren();
          if(this.children != null && this.children.isOpened_get()){
              return this.hideChildren();
          }
      }
      
      if(callByInterval!=null){
         if(hOpenTimeOut!=null){
             window.clearInterval(hOpenTimeOut);
             hOpenTimeOut = null;
         }
      }
      
      this.hideSiblingChildren();   
      if(bAlwaysShow) return false;      
      this.ensureChildren();
      if(this.children == null) return false;
      
      var bLocalOpen = false;
      
      if(!bChildrenIsInline){
         var oLevel = level.getNextLevel();
         var oDiv = this.children.flyObj.childObj;

		//18-12-2008 set the hidden iframe height to match the menu height
	    if (NWGlobal.BrName == "IE" && NWGlobal.BrVers <7){

		iframeElId = itemElement.id.replace(/\_i$/,"_c") + "Iframe";
		//trace ("seek:" + iframeElId);
		var oIframe = document.getElementById(iframeElId);
		if(oIframe){
			var oDivHeight = oDiv.scrollHeight;
			oIframe.style.height = oDivHeight + "px";
		}
	}
		//18-12-2008 end
         var oTable = oDiv.getElementsByTagName("TABLE");oTable = oTable[0]; 
         //alert(oDiv.style.width);         
                            
         if(!this.children.isOpened_get()){
              bLocalOpen = true;
              this.children.show();
         }
                                  
         switch(oLevel.itemWidthType){
             case "by-parent-item-size" :
             case "by-max-item-size" : 
                if(oLevel.itemWidthValue == "no-min-to-parent") break;
                                    
                var iTableWidth = oTable.offsetWidth;
                var iParentWidth = itemElement.offsetWidth;
                if(oLevel.itemWidthType == "by-max-item-size" && iTableWidth >= iParentWidth) break;
                oTable.style.width = iParentWidth + "px";                    
                
                break;
         }
         oDiv.style.width = oTable.offsetWidth + "px";                                       
      }//~~~ if(!bChildrenIsInline){
      
      if(level.childOpenDelay != null && callByInterval==null && level.childOpenDelay > 0){
          if(bLocalOpen){this.children.hide();bLocalOpen=false;}
          
          if(this.children.isOpened_get()){              
              return false;
          }else{
              hOpenTimeOut = window.setInterval(selfVarName + ".showChildren1(true);",level.childOpenDelay);
              return true;
          }
      }else{
          this.children.setPosition();          
          if(bLocalOpen || this.children.show()){
             this.apllyOpenState(true);
             return true;
          }
      }
         
      return false;
   }//~~~ this.showChildren1 = function(){
   this.apllyOpenState = function(open){
       if(bChildrenIsInline){           
           var colTD = itemElement.getElementsByTagName("TD");           
           for(var i=0; i<colTD.length; i++){
              if(colTD[i].className == "nw-arrow"){
                  var elTD = colTD[i];
                  var oS = level.states[0];                 
                  var oArr = (open)? oS.topArrow : oS.bottomArrow;
                  var sHtml = "";
                  if(typeof(oArr) == "string"){
                      sHtml = oArr;
                  }else{
                      sHtml = "<IMG alt=\"\" src=\""+oArr.src+"\"/>";
                  }
                  elTD.innerHTML = sHtml;
                  break;
              }
           }           
       }       
   }//~~~ this.apllyOpenState
   this.flatDescendantIsOpened1_get = function(innerLevel){
      if(this.children != null && this.children.isOpened_get()){
          if(innerLevel && !bChildrenIsInline){
              return true;
          }            
          this.ensureFirstChild();
          if(this.firstChild!=null){
             this.firstChild.ensureFirstSiblingItem();
             if(this.firstChild.firstSiblingItem.flatSiblingsIsOpened1_get()){
                return true;
             }
          }         
      }      
      return false;   
   }//~~~ this.flatDescendantIsOpened1_get = function(){
   this.flatSiblingsIsOpened1_get = function(){
      for(var i=0; i<this.siblingItems.length; i++){
         var oMenuItem = this.getSiblingItem(i);
         if(oMenuItem.flatDescendantIsOpened1_get(true)){
             return true;
         }         
      }
      return false;
   }//~~~ this.flatSiblingsIsOpened1_get = function(){
}//~~~ class NWMenuItem

function NWMenuItem_TimeoutHandler(flyObj){
    return flyObj.freeStateObject.flatDescendantIsOpened1_get();   
}

function NWMenuItem_Inline(selfVarName, itemElement){
    this.isOpened_get = function(){
       return (itemElement.style.display != "none");
    }
    this.setPosition = function(parentObj){       
    }
    this.show = function(){
       if(itemElement.style.display == "none"){
          itemElement.style.display = "";
          return true;
       }
       return false;
    }
    this.hide = function(){
       if(itemElement.style.display != "none"){
          itemElement.style.display = "none";
          return true;
       }
       return false;
    }
}//~~~ class NWMenuItem_Inline

function NWMenuMap(selfVarName, optionalXml){
    var oXml = optionalXml;
    var oInnerHTMLChecker = new RegExp("(\\<)|(&(amp|apos|quot|lt|gt|#[\\d]+);)","g");
    
    this.getData = function(){
        return oXml;
    }    
    this.getDataByItemId = function(itemId){
        var sXPath = "//A[@nwInd='"+itemId+"']";
        return oXml.selectSingleNode(sXPath);        
    }
    this.getFirstChildrenDataByItemId = function(itemId){
        var sXPath = "//A[@nwInd='"+itemId+"']/parent::LI/UL/LI/A";
        return oXml.selectSingleNode(sXPath);        
    }
    this.getChildrenDataByItemId = function(itemId){
        var sXPath = "//A[@nwInd='"+itemId+"']/parent::LI/UL";
        return oXml.selectSingleNode(sXPath);        
    }    
    this.getSiblingsDataByItemId = function(itemId){
        var sXPath = "//A[@nwInd='"+itemId+"']/parent::LI/parent::UL/LI/A";
        var oNodesList = oXml.selectNodes(sXPath);
        return oNodesList;    
    }
    
    var ar_oLoadOnPageNodesHandlers = new Array();
    var ar_oLoadOnPageNodesHandlers1 = new Array();
    this.addLoadOnPageNodesHandler = function(menu, noTransorm){
        if(oXml==null){
           if(noTransorm){
              ar_oLoadOnPageNodesHandlers1.push(menu);
           }else{
              ar_oLoadOnPageNodesHandlers.push(menu);
           }
        }else{
           menu.mapLoadedHandler(noTransorm);
        }
    }
    this.cloneForMenu = function(menu){
        if(NWMenu_oCommonXslSelectNodes == null) return null;
        
        var sXmlNew = "";
        var oXmlNew = null;
        var oXslProc = NWMenu_oCommonXslSelectNodes.createProcessor();        
        
        oXslProc.addParameter("start-level", menu.levelStart);
        oXslProc.addParameter("max-levels", menu.levelsToOutput);
        if(menu.showRoot) oXslProc.addParameter("show-root", "1");
        if(menu.pushRootIntoSecondLevel) oXslProc.addParameter("root-in-next-level", "1");        
        if(menu.topLevelOnlyCurrent) oXslProc.addParameter("top-level-only-current", "1");
        if(menu.selectedAnchorItemId != null){
           oXslProc.addParameter("selected-anchor", menu.selectedAnchorItemId);
        }
        
        oXslProc.input_set(oXml);        
        if(oXslProc.transform()){
            sXmlNew = oXslProc.output_get();            
        }
        
        oXmlNew = new NWXmlDocument();
        oXmlNew.async_set(false);
        if(sXmlNew!="") oXmlNew.loadXML(sXmlNew);        
            else oXmlNew.loadXML("<UL/>");
        //alert(oXmlNew.xml_get());
        
        if(oXmlNew != null){
            var sNewMapVarName = menu.selfVarName + "__gMap";
            var oMapNew = new NWMenuMap(sNewMapVarName, oXmlNew);
            window[sNewMapVarName] = oMapNew;
            return oMapNew;
        }
   
        return null;        
    }
    this.loadOnPageNodes = function(){        
        oXml = new NWXmlDocument();
        oXml.async_set(false);
        oXml.loadXML("<UL/>");
        
        var oRootEl = NWGlobal.getElementById(selfVarName + "__l__");        
        if(oRootEl!=null){
            var oNode = oXml.documentElement_get();
            loadOnPageElement(oXml,oNode,oRootEl,true);
        }else{
            oXml.loadXML("<UL/>");
        }
        //alert(oXml.xml_get());
        
        for(var i=0; i<ar_oLoadOnPageNodesHandlers.length;i++){
           ar_oLoadOnPageNodesHandlers[i].mapLoadedHandler();
        }
        for(var i=0; i<ar_oLoadOnPageNodesHandlers1.length;i++){
           ar_oLoadOnPageNodesHandlers1[i].mapLoadedHandler(true);
        }              
    }
    function loadOnPageElement(xmlDoc, xmlNode, htmlElement, isRoot){
        if(htmlElement==null || typeof(htmlElement.tagName)!="string") return null;
	    
	    var bTmp;
	    var bProcessChilder = true;	    
	    var oNode;
	    if(isRoot!=null && isRoot){
	        oNode = xmlNode;
	    }else{
	        oNode = xmlDoc.createElement(htmlElement.tagName);
	        if(xmlNode!=null){
	            xmlNode.appendChild(oNode);
	        }
	    }	    
	    switch(htmlElement.tagName){
	        case "UL" :  
	                NWXml.appendOptionalAttribute(oNode,"nwDId", htmlElement.getAttribute("nwDId"));
	                NWXml.appendOptionalAttribute(oNode,"nwL", htmlElement.getAttribute("nwL"));
	                break;
	        case "A"  :
	                NWXml.appendOptionalAttribute(oNode, "href", htmlElement.href);
	                NWXml.appendOptionalAttribute(oNode, "target", htmlElement.target);
	                NWXml.appendOptionalAttribute(oNode, "nwhrefdis", htmlElement.getAttribute("nwhrefdis"));
                    NWXml.appendOptionalAttribute(oNode, "title", htmlElement.title);
                    NWXml.appendOptionalAttribute(oNode, "nwCh", htmlElement.getAttribute("nwCh"));
                    NWXml.appendOptionalAttribute(oNode, "nwDId", htmlElement.getAttribute("nwDId"));
                    NWXml.appendOptionalAttribute(oNode, "nwInd", htmlElement.getAttribute("nwInd"));
                    NWXml.appendOptionalAttribute(oNode, "nwIco",htmlElement.getAttribute("nwIco")); 
                    NWXml.appendOptionalAttribute(oNode, "nwTp", htmlElement.getAttribute("nwTp"));
                    NWXml.appendOptionalAttribute(oNode, "nwSs", htmlElement.getAttribute("nwSs"));
                    
                    sHtml = htmlElement.innerHTML;
                    bTmp = (sHtml.indexOf("<") >= 0 || oInnerHTMLChecker.test(sHtml));
                    if(bTmp){
                        sHtml = sHtml.replace(/\<br\>/gi,"<br/>");
                        var oNode1 = oNode.appendXml(sHtml);
                    }else{
                        oNode.nodeValue_set(htmlElement.innerHTML);
                    }
                    bProcessChilder = false;
	                break;
	    }
	    if(bProcessChilder){
	        for(var i=0; i<htmlElement.childNodes.length; i++){
	            loadOnPageElement(xmlDoc, oNode, htmlElement.childNodes[i]);
	        }
	    }
	    return oNode;    
    }//~~~ loadOnPageElement()       
}//~~~ calss NWMenuMap()
/*
function CheckExplorer(){
    if(document.body.currentStyle)
        NWGlobal.BrName = "IE";
    else
        NWGlobal.BrName = "MZ";
}
*/
//alert("js menu is never ok");
