﻿/* 
 * (c) Všechna práva vyhrazena. Kód webové stránky je autorským dílem společnosti WEBHOUSE, s.r.o. podle platných zákonů.
 * Bez autorizovaného povolení jej ani jeho části nelze kopírovat ani jinak používat zejména pro komerční účely.
 */
var MENU_VERSION = "1.0.2";
var IS_ICON_BEFORE = false;
var IS_ICON_BY_ROOT_ITEM_WITH_NO_SUBNODE = false;
var IS_SAME_CLASS_IN_EVERY_OPENED_LEVEL = true;

function Menu_ul(params) {
  var IS_OPEN_AFTER_PAGE_LOAD = false;
  var MENUICONS_PATHS_ROOT = ["mul/pu1.png", "mul/mu1.png", "mul/u1.gif"];
  var MENUICONS_PATHS_SUB = ["mul/pu2.gif", "mul/mu2.gif", "mul/u2.gif"];
  var MENUICONS_PATHS_ROOT_MOUSEOVER = ["pu1_mo.gif", "mu1_mo.gif", "u1_mo.gif"];
  var MENUICONS_PATHS_SUB_MOUSEOVER = ["pu2_mo.gif", "mu2_mo.gif", "u2_mo.gif"];
  var EXPAND_COLLAPSE_LINKS_PATHS = ["rozbalit.gif", "sbalit.gif"];
  var menuicons_root = [new Image(), new Image(), new Image()];
  var menuicons_sub = [new Image(), new Image(), new Image()];
  var menuicons_root_mouseOver = [new Image(), new Image(), new Image()];
  var menuicons_sub_mouseOver = [new Image(), new Image(), new Image()];
  var expandCollapseLinks = [new Image(), new Image()];
      
  this.mainMenu = null;
  this.menuItems = new Array();
  this.pageViewer = null;
  this.menuId = "menu";
  this.expandCollapseLinksIds = [];
  this.imagesPath = "/html/images/";
  this.pageViewerSettings = [false, 0];
  this.mouseOverChangeIcon = [false, "/html/images/mul/"];
  var menuTexts = ["sbaleno", "rozbaleno", "sbalit menu", "rozbalit menu", "(Odkazy v hlavní nabídce, mající u sebe ikony Rozbaleno / Sbaleno nejsou odkazem na webovou stránku, nýbrž slouží k obsluze samotné nabídky)", "sbalit", "rozbalit"];
  var menu_events_type = 2;
  var menu_icons_type = 0;
  var menu_icons_content = null;
  var menu_items_icons_type = 0;
  var menu_items_icons_content = null;
  var isHidePreviousRootNode = true;
  var node_change_state_delay = 0;
  var hide_menu_delay = 0; // _KN_20120126
  var delayedClosingTimer=null; // _KN_20120126  
  if (params) {
    for (var i = 0; i < params.length; i++) {
      switch (params[i][0]) {
      case 'menu id':
        this.menuId = params[i][1];
        break;
      case 'expand/collapse':
        this.expandCollapseLinksIds = params[i][1];
        break;
      case 'images path':
        this.imagesPath = params[i][1];
        break;
      case 'texts':
        menuTexts = params[i][1];
        break;
      case 'events type':
        menu_events_type = params[i][1];
        break;
      case 'icons content change by expand/collapse':
        menu_icons_type = params[i][1];
        menu_icons_content = params[i][2] && params[i][2].length > 0 ? params[i][2] : "&nbsp;";
        break;
      case 'icons content change by menu items':
        menu_items_icons_type = params[i][1];
        menu_items_icons_content = params[i][2] && params[i][2].length > 0 ? params[i][2] : "&nbsp;";
        break;
      case 'hide previous root node':
        isHidePreviousRootNode = eval(params[i][1]);
        break;
      case 'page viewer':
        this.pageViewerSettings = eval(params[i][1]);
        break;
      case 'mouseover change icon':
        this.mouseOverChangeIcon = eval(params[i][1]);
        break;
      case 'node change state delay':
        node_change_state_delay = params[i][1];
        break;
      case 'icon by item':
        break;       
      case 'hide menu delay when mouse is out':
        hide_menu_delay = params[i][1];
        break;
      }
    }
  }
  this.lastChangedItem = null;
  this.initMenuUl = function () {
    this.mainMenu = document.getElementById(this.menuId);
    if (!this.mainMenu) return;
    this.mainMenu.className = "jsMenu";
    this.mainMenu.getElementsByTagName("ul")[0].id = this.menuId + "MainNode";
    this.initImagesIcons("menuicons_root", MENUICONS_PATHS_ROOT);
    this.initImagesIcons("menuicons_sub", MENUICONS_PATHS_SUB);
    if (this.mouseOverChangeIcon[0]) {
      this.initImagesIcons("menuicons_root_mouseOver", MENUICONS_PATHS_ROOT_MOUSEOVER);
      this.initImagesIcons("menuicons_sub_mouseOver", MENUICONS_PATHS_SUB_MOUSEOVER);
    }
    this.initImagesIcons("expandCollapseLinks", EXPAND_COLLAPSE_LINKS_PATHS);
    if (this.pageViewerSettings[0]) this.appendPageViewer();
    this.initItems();
    this.appendHandlers(this);
    for (var i = 0; i < this.expandCollapseLinksIds.length; i++) {
      this.appendExpandCollapseLinks(this, this.expandCollapseLinksIds[i]);
    }
    if (document.getElementById("menuinfo")) {
      document.getElementById("menuinfo").innerHTML = menuTexts[4];
    }
  }
  this.appendPageViewer = function () {
    this.pageViewer = document.createElement("iframe");
    this.pageViewer.id = "pageViewer";
    this.pageViewer.style.zIndex = 100;
    this.pageViewer.style.position = "absolute";
    this.pageViewer.style.display = "none";
    this.pageViewer.style.left = "0px";
    this.pageViewer.style.top = "0px";
    this.pageViewer.style.width = "auto";
    this.pageViewer.style.height = "auto";
    document.body.appendChild(this.pageViewer);
  }
  this.initItems = function () {
    if (this.mainMenu) {
      var itemIndex = 0;
      var menu_items = this.mainMenu.getElementsByTagName("a");
      for (var i = 0; i < menu_items.length; i++) {
        if (menu_items[i].parentNode.tagName.toLowerCase() != "li") {
          continue;
        }
        this.menuItems[itemIndex] = new MenuItem(menu_items[i], this);
        this.menuItems[itemIndex].prepareItem();
        itemIndex++;
      }
    }
  }
  this.initImagesIcons = function (menuicons_variable_name, menuicons_paths) {
    for (var i = 0; i < menuicons_paths.length; i++) {
      eval(menuicons_variable_name + "[i]").isLoaded = false;
      eval(menuicons_variable_name + "[i]").onload = function () {
        this.isLoaded = true;
      }
      eval(menuicons_variable_name + "[i]").onerror = function () {
        this.isLoaded = false;
      }
      if (menuicons_variable_name == "menuicons_root_mouseOver" || menuicons_variable_name == "menuicons_sub_mouseOver") {
        eval(menuicons_variable_name + "[i]").src = this.mouseOverChangeIcon[1] + menuicons_paths[i];
      } else {
        eval(menuicons_variable_name + "[i]").src = this.imagesPath + menuicons_paths[i];
      }
    }
  }
  this.appendHandlers = function (thisMenu) {
    document.body.onclick = function () {
      if(delayedClosingTimer){clearTimeout(delayedClosingTimer);}
      thisMenu.switchAllItems("none",true);
      thisMenu.menuItems[0].actObj.className="";
      thisMenu.menuItems[0].actObj.removeAttribute("class");                            
      thisMenu.setAttributeToSubElements(thisMenu.menuItems[0], "a", "class", null);      
    }          
    // KN_20120126_z
    if(hide_menu_delay>0){                     
      document.body.onmouseover = function (e) {
        if(!thisMenu.isInMenuIncluded(e)){
          for(var i=0;i<thisMenu.menuItems.length;i++){              
            //document.getElementById("hl").value+=thisItem.menuUl.menuItems[i].actObj.className+", ";                                
            if (thisMenu.menuItems[i].actObj.className.indexOf("expanded")>-1){ // || thisMenu.menuItems[i].actObj.parentNode.parentNode.style.display==("block" || "none")) {                                
              if(thisMenu.menuItems[i].nearestNode)thisMenu.menuItems[i].changeNode(thisMenu.menuItems[i], e);
              thisMenu.menuItems[i].actObj.className = "";
              thisMenu.menuItems[i].actObj.removeAttribute("class");
              thisMenu.setAttributeToSubElements(thisMenu.menuItems[i], "a", "class", null);
            }
          }
        }                   
        stopBubble(e);
        return false;
      }                   
    }
    // KN_20120126_k    
  }
  this.appendExpandCollapseLinks = function (thisMenu, menuLinkId) {
    if (document.getElementById(menuLinkId)) {
      document.getElementById(menuLinkId).className = "js" + menuLinkId;
      var expandLink = document.createElement("a");
      expandLink.id = "expandLink_" + menuLinkId;
      expandLink.setAttribute("href", "javascript:void(0);");
      var collapseLink = document.createElement("a");
      collapseLink.id = "collapseLink_" + menuLinkId;
      collapseLink.setAttribute("href", "javascript:void(0);");
      if (menu_icons_type == 1 || menu_icons_type == 2) {
        expandLink.innerHTML = menuTexts[6];
        collapseLink.innerHTML = menuTexts[5];
      }
      if (menu_icons_type == 0 || menu_icons_type == 2) {
        expandLink.appendChild(getImageElement(this, menuTexts[3], expandCollapseLinks[0].src));
        collapseLink.appendChild(getImageElement(this, menuTexts[2], expandCollapseLinks[1].src));
        expandLink.onclick = function () {
          thisMenu.setAttributeToSubElements(thisMenu.menuItems[0], "a", "class", "expanded");
          thisMenu.switchAllItems("block",false);
        }
        collapseLink.onclick = function () {
          thisMenu.setAttributeToSubElements(thisMenu.menuItems[0], "a", "class", null);
          thisMenu.switchAllItems("none",false);
        }
      }
      document.getElementById(menuLinkId).appendChild(expandLink);
      document.getElementById(menuLinkId).appendChild(collapseLink);
      if (menu_icons_type == 1 || menu_icons_type == 2) {
        document.getElementById(menuLinkId).innerHTML = document.getElementById(menuLinkId).innerHTML.replace(/<\/a><a/gi, "</a> | <a");
        document.getElementById(menuLinkId).innerHTML += " menu";
        document.getElementById("expandLink_" + menuLinkId).onclick = function () {
          thisMenu.setAttributeToSubElements(thisMenu.menuItems[0], "a", "class", "expanded");
          thisMenu.switchAllItems("block",false);
        }
        document.getElementById("collapseLink_" + menuLinkId).onclick = function () {
          thisMenu.setAttributeToSubElements(thisMenu.menuItems[0], "a", "class", null);
          thisMenu.switchAllItems("none",false);
        }
      }
    }
  }
  this.switchAllItems = function (nodeState,isBodyEvent) {  
    for (var i = 0; i < this.menuItems.length; i++) {
      this.menuItems[i].switchNodeState(this.menuItems[i].actObj.parentNode, this.menuItems[i].nearestNode, nodeState, this.menuItems[i].isRoot ? menuicons_root : menuicons_sub, node_change_state_delay, isBodyEvent);      
      if (this.menuItems[i].nearestNode && nodeState == ("block" || "" || "inline") && this.menuItems[i].actObj.parentNode.className.toLowerCase().indexOf("toopen") == -1) {
        this.menuItems[i].actObj.parentNode.className = "toOpen " + this.menuItems[i].actObj.parentNode.className;        
      } else if (this.menuItems[i].nearestNode && !(nodeState == ("block" || "" || "inline"))) {
        this.menuItems[i].actObj.parentNode.className = this.menuItems[i].actObj.parentNode.className.replace("toOpen", "");        
      }
      this.menuItems[i].replaceSpaces(this.menuItems[i].actObj.parentNode)
    }
  }
  this.setAttributeToSubElements = function (thisItem, tagName, attributeName, attributeValue) {
    var linksElms = thisItem.actObj.parentNode.parentNode.getElementsByTagName(tagName);
    for (var i = 0; i < linksElms.length; i++) {
      if (linksElms[i] == thisItem.actObj || linksElms[i].parentNode.getElementsByTagName("ul").length == 0) {
        continue;
      }
      if (attributeValue) {
        linksElms[i].setAttribute(attributeName, attributeValue);
      } else {
        linksElms[i].className = "";
        linksElms[i].removeAttribute(attributeName);
      }
    }
  }
  this.getMousePosition = function (e) {
    var posX = 0;
    var posY = 0;
    if (e) {
      posX = e.clientX;
      posY = e.clientY;
    } else if (event) {
      posX = event.clientX;
      posY = event.clientY;
    }
    return {
      X: posX,
      Y: posY
    };
  }
  this.getClientSize = function (e) {
    var width = 0;
    var height = 0;
    try {
      width = document.body.clientWidth;
      height = document.body.clientHeight;
    } catch (err) {}
    return {
      width: width,
      height: height
    };
  }
  this.alignPageViewer = function (thisItem) {
    var TOP_OFFSET = -15;
    return parseInt(this.pageViewer.style.top) + parseInt(this.pageViewer.style.height) > parseInt(document.body.scrollTop) + this.getClientSize().height ? parseInt(this.pageViewer.style.top) - ((parseInt(this.pageViewer.style.top) + parseInt(this.pageViewer.style.height)) - this.getClientSize().height) + parseInt(document.body.scrollTop) + TOP_OFFSET : parseInt(this.pageViewer.style.top) + TOP_OFFSET;
  }

  function isArray(actObj) {
    if (actObj.constructor.toString().toLowerCase().indexOf("array") > -1) return true;
    return false;
  }

  function getIconArea(thisItem, actObj, imageSrc, iconAreaContentIndex, menuIconContent) {
    var imageArea = document.createElement("span");
    imageArea.className = "menuobr";
    if (iconAreaContentIndex == 1 || iconAreaContentIndex == 2) {
      if (IS_ICON_BY_ROOT_ITEM_WITH_NO_SUBNODE || ((thisItem.isRoot && thisItem.nearestNode != null) || (!thisItem.isRoot && thisItem.nearestNode != null))) {
        imageArea.innerHTML = menuIconContent ? menuIconContent : menuTexts[0];
      }
    }
    if (imageSrc && imageSrc.length > 0 && (iconAreaContentIndex == 0 || iconAreaContentIndex == 2)) {
      if (IS_ICON_BY_ROOT_ITEM_WITH_NO_SUBNODE || ((thisItem.isRoot && thisItem.nearestNode != null) || (!thisItem.isRoot && thisItem.nearestNode != null))) {
        var image = document.createElement("img");
        image.src = imageSrc;
        image.setAttribute("alt", menuTexts[0]);
        imageArea.appendChild(image);
      }
    }
    return imageArea;
  }

  function getImageElement(thisItem, imageAlt, imageSrc) {
    var imageElm = document.createElement("img");
    imageElm.src = imageSrc;
    imageElm.setAttribute("alt", imageAlt);
    return imageElm;
  }

  function isMenuItemRoot(actObj, isGetLevel) {
    var actNode = actObj.parentNode;
    var parentNodesCount = 0;
    while (actNode && actNode.tagName && (actNode.tagName.toLowerCase() != "body" || actNode.id.indexOf("menu") == -1)) {
      if (actNode.tagName.toLowerCase() == "ul") {
        parentNodesCount++;
      }
      actNode = actNode.parentNode;
    }
    if (isGetLevel) return [(parentNodesCount == 1 ? true : false), parentNodesCount - 1];
    return parentNodesCount == 1 ? true : false;
  }

  function stopBubble(e) {
    try {
      if (e) e.stopPropagation();
      else event.cancelBubble = true;
    } catch (err) {}
  }
  this.isInMenuIncluded=function(e){
    e=e?e:event;
    var srcElement=e.srcElement?e.srcElement:e.target;
    var actElement=srcElement;
    //if(actElement=="body")return true;
    while(actElement && actElement!="body"){
      if(actElement){
        if(actElement.id=="menu")return true;        
        actElement=actElement.parentNode;
      }
    }
    return false;
  }

  function MenuItem(actObj, menuUl, menuIndex) {
    this.actObj = actObj;
    this.menuUl = menuUl;
    this.nearestNode = null;
    this.iconArea = null;
    this.isRoot = false;
    this.levelIndex = -1;
    this.menuIndex = menuIndex;
    this.oldIconPath = "";
    this.prepareItem = function () {
      var rootInfo_temp = isMenuItemRoot(this.actObj, true);
      this.levelIndex = rootInfo_temp[1];
      this.isRoot = rootInfo_temp[0];
      if (this.actObj.parentNode) {
        this.nearestNode = this.actObj.parentNode.getElementsByTagName("ul")[0];
        if (this.nearestNode != null) {
          if (this.nearestNode.tagName.toLowerCase() == "ul" && this.nearestNode.className != "menu") {
            this.nearestNode.className = "sub"
          }
          this.actObj.parentNode.className += " kontneodkaz";
          this.replaceSpaces(this.actObj.parentNode);
          this.switchNodeState(null, this.nearestNode, null);
          if (menuicons_root.length >= 1 && menuicons_sub.length >= 1) this.appendIcon(this.isRoot ? menuicons_root[0].src : menuicons_sub[0].src, menu_items_icons_type, menu_items_icons_content);
          this.append_MenuItem_handler(this);
        } else {
          this.actObj.parentNode.className += " kontodkaz";
          this.replaceSpaces(this.actObj.parentNode);
          if (menuicons_root.length >= 3 && menuicons_sub.length >= 3) this.appendIcon(this.isRoot ? menuicons_root[2].src : menuicons_sub[2].src, menu_items_icons_type, menu_items_icons_content);
          this.append_MenuItem_handler(this);
        }
        if (IS_OPEN_AFTER_PAGE_LOAD) this.openParentNodes();
      }
    }
    this.replaceSpaces = function (actObj) {
      if (actObj.className.toLowerCase().indexOf(" ") == 0) {
        actObj.className = actObj.className.replace(" ", "");
      }
    }
    this.append_MenuItem_handler = function (thisItem) {
      var timer1 = null;
      try {
        thisItem.iconArea.onfocus = thisItem.actObj.onfocus = function (e) {
          if (thisItem.menuUl.mouseOverChangeIcon[0]) thisItem.changeIconIfMouseIsOver(e, thisItem, menuicons_root_mouseOver, menuicons_sub_mouseOver);
        }
        thisItem.iconArea.onblur = thisItem.actObj.onblur = function (e) {
          if (thisItem.menuUl.mouseOverChangeIcon[0]) thisItem.changeIconIfMouseIsOver(e, thisItem, menuicons_root, menuicons_sub);
        }
        thisItem.iconArea.onmouseout = thisItem.actObj.onmouseout = function (e) {
          if (thisItem.menuUl.mouseOverChangeIcon[0]) thisItem.changeIconIfMouseIsOver(e, thisItem, menuicons_root, menuicons_sub);
        }
        if (thisItem.menuUl.pageViewer) {
          thisItem.menuUl.pageViewer.onmouseout = function (e) {
            if (thisItem.menuUl.pageViewerSettings[0]) thisItem.hidePageViewer(e, thisItem);
          }
        }
        thisItem.iconArea.onmousemove = thisItem.actObj.onmousemove = function (e) {
          if (thisItem.menuUl.pageViewerSettings[0]) thisItem.changePageViewerPosition(e, thisItem);
        }
      } catch (err) {}
      if (menu_events_type == 0 || menu_events_type == 2) {
        if (thisItem.nearestNode) {        
          var returnResult = false;
          thisItem.iconArea.onclick = thisItem.actObj.onclick = function (e) {
            timer1 = setTimeout(function () {
              thisItem.changeNode(thisItem, e);
              if (thisItem.actObj.parentNode.getElementsByTagName("ul")[0].style.display == ("block" || "" || "none")) {
                thisItem.actObj.className = "expanded";
              } else {                            
                thisItem.actObj.className = "";
                thisItem.actObj.removeAttribute("class");
              }
              thisItem.menuUl.setAttributeToSubElements(thisItem, "a", "class", null);
            }, node_change_state_delay);
            stopBubble(e);
            return returnResult;
          }
        }                          
      }
      if (menu_events_type == 1 || menu_events_type == 2) {
        if (thisItem.nearestNode) {
          thisItem.actObj.onmouseover = function (e) {
            if (thisItem.menuUl.pageViewerSettings[0]) thisItem.showPageViewer(e, thisItem);
            if (thisItem.menuUl.mouseOverChangeIcon[0]) thisItem.changeIconIfMouseIsOver(e, thisItem, menuicons_root_mouseOver, menuicons_sub_mouseOver);
            if (thisItem.actObj.parentNode.getElementsByTagName("ul")[0].style.display != ("block" || "" || "none")) {
              timer1 = setTimeout(function () {
                thisItem.changeNode(thisItem, e);
                thisItem.actObj.className = "expanded";
                thisItem.menuUl.setAttributeToSubElements(thisItem, "a", "class", null);
              }, node_change_state_delay);
              stopBubble(e);
              return false;
            }
          }
        } else {
          thisItem.actObj.onmouseover = function (e) {
            if (thisItem.menuUl.pageViewerSettings[0]) thisItem.showPageViewer(e, thisItem);
            if (thisItem.menuUl.mouseOverChangeIcon[0]) thisItem.changeIconIfMouseIsOver(e, thisItem, menuicons_root_mouseOver, menuicons_sub_mouseOver);
            thisItem.switchNodeState(thisItem.actObj, thisItem.actObj.parentNode.parentNode.getElementsByTagName("ul")[0], "none", thisItem.isRoot ? menuicons_root : menuicons_sub, node_change_state_delay, false);
            thisItem.setSubNodesStates("none", thisItem.isRoot ? menuicons_root : menuicons_sub);
            thisItem.menuUl.setAttributeToSubElements(thisItem, "a", "class", null);
            if (thisItem.isRoot) {
              clearTimeout(timer1);
              timer1 = setTimeout(function () {
                thisItem.menuUl.switchAllItems("none",false);
              }, node_change_state_delay);
            }
            stopBubble(e);
            return false;
          }
        }
      }
    }
    this.append_handler_mouseOverChangeIcon = function (thisItem) {
      if (menu_events_type == 0) {
        try {} catch (err) {}
      }
    }
    this.appendIcon = function (imageSrc, iconAreaContentIndex, iconContent) {
      this.iconArea = getIconArea(this, this.actObj, imageSrc, iconAreaContentIndex, iconContent);
      if (IS_ICON_BEFORE) {
        this.actObj.parentNode.insertBefore(this.iconArea, this.actObj);
      } else {
        this.actObj.parentNode.insertBefore(this.iconArea, this.actObj.nextSibling);
      }
    }
    this.getIconsAreaContent = function (thisItem, menuIconContent, iconAreaContentIndex) {
      var tmpElm = document.createElement("div");
      tmpElm.innerHTML = menuIconContent;
      if (iconAreaContentIndex == 0 || iconAreaContentIndex == 2) tmpElm.appendChild(thisItem.getElementsByTagName("img")[0]);
      return tmpElm.innerHTML;
    }
    this.showPageViewer = function (e, thisItem) {
      if (thisItem.actObj.getAttribute("href").length == 0) {
        this.menuUl.pageViewer.style.display = "none";
        return;
      }
      var MAX_OPACITY = 20;
      var mousePosition = this.menuUl.getMousePosition(e);
      this.menuUl.pageViewer.style.width = "400px";
      this.menuUl.pageViewer.style.height = "260px";
      if (this.menuUl.pageViewerSettings[1] == 0) {
        this.menuUl.pageViewer.style.left = parseInt(document.body.scrollLeft) + mousePosition.X + 100 + "px";
      } else {
        this.menuUl.pageViewer.style.left = parseInt(document.body.scrollLeft) + mousePosition.X - parseInt(this.menuUl.pageViewer.style.width) - 100 + "px";
      }
      this.menuUl.pageViewer.style.top = parseInt(document.body.scrollTop) + mousePosition.Y + "px";
      this.menuUl.pageViewer.style.top = this.menuUl.alignPageViewer();
      this.menuUl.pageViewer.src = thisItem.actObj.getAttribute("href");
      var overPageLayout = document.createElement("div");
      overPageLayout.id = "overPageLayout";
      overPageLayout.style.position = "absolute";
      overPageLayout.style.left = "0px";
      overPageLayout.style.top = "0px";
      overPageLayout.style.width = "10000px";
      overPageLayout.style.height = "10000px";
      overPageLayout.style.backgroundColor = "#FFFFFF";
      overPageLayout.style.MozOpacity = MAX_OPACITY / 100;
      overPageLayout.style.opacity = MAX_OPACITY / 100;
      overPageLayout.style.filter = "alpha(opacity=" + MAX_OPACITY + ")";
      overPageLayout.style.zIndex = 50;
      var actItem = this;
      var timer1 = setInterval(function () {
        try {
          if (actItem.menuUl.pageViewer.contentWindow.document.body) {
            clearInterval(timer1);
            actItem.menuUl.pageViewer.onmouseover = function () {
              actItem.menuUl.pageViewer.style.width = "100%";
              actItem.menuUl.pageViewer.style.height = "100%";
              if (actItem.menuUl.pageViewerSettings[1] == 1) {
                actItem.menuUl.pageViewer.style.left = "100px";
              }
            }
          }
        } catch (err) {
          clearInterval(timer1);
        }
      }, 10);
      this.menuUl.pageViewer.style.display = "block";
    }
    this.changePageViewerPosition = function (e, thisItem) {
      var mousePosition = thisItem.menuUl.getMousePosition(e);
      thisItem.menuUl.pageViewer.style.top = parseInt(document.body.scrollTop) + parseInt(mousePosition.Y) + "px";
      thisItem.menuUl.pageViewer.style.top = thisItem.menuUl.alignPageViewer();
    }
    this.hidePageViewer = function (e, thisItem) {
      var mousePosition = this.menuUl.getMousePosition(e);
      this.menuUl.pageViewer.style.left = mousePosition.X;
      this.menuUl.pageViewer.style.top = mousePosition.Y;
      this.menuUl.pageViewer.style.width = "0px";
      this.menuUl.pageViewer.style.height = "0px";
      this.menuUl.pageViewer.style.display = "none";
    }
    this.changeIconIfMouseIsOver = function (e, thisItem, imagesRootPaths, imagesSubPaths) {
      var actImg = this.actObj.parentNode.getElementsByTagName("img")[0];
      var actImgParentElm = this.actObj.parentNode.getElementsByTagName("span")[0];
      var isOpened = this.actObj.parentNode.className.toLowerCase().indexOf("toopen") > -1 ? true : false;
      var newImgSrc = "";
      if (actImg) {
        this.oldIconPath = actImg.getAttribute("src");
        if (isOpened) {
          actImg.setAttribute("src", this.isRoot ? imagesRootPaths[1].src : imagesSubPaths[1].src);
        }
        if (!isOpened) {
          actImg.setAttribute("src", this.isRoot ? imagesRootPaths[0].src : imagesSubPaths[0].src);
        }
        if (!this.nearestNode) {
          actImg.setAttribute("src", this.isRoot ? imagesRootPaths[2].src : imagesSubPaths[2].src);
        }
      }
      if (actImgParentElm && !this.nearestNode) {
        var eventType = null;
        if (e) eventType = e.type;
        else if (event) eventType = event.type;
        if (eventType.toLowerCase().indexOf("mouseover") > -1 || eventType.toLowerCase().indexOf("focus") > -1) actImgParentElm.className = "menuobr acticonelm";
        else if (eventType.toLowerCase().indexOf("mouseout") > -1 || eventType.toLowerCase().indexOf("blur") > -1) actImgParentElm.className = "menuobr";
      }
    }
    this.changeNode = function (thisItem, e) {
      var actualMenuIcons = null;
      if (thisItem.isRoot) {
        if (!(thisItem.nearestNode.style.display == ("block" || "" || "inline"))) {
          this.menuUl.switchAllItems("none",false);
        }
        actualMenuIcons = this.menuUl.mouseOverChangeIcon[0] ? menuicons_root_mouseOver : menuicons_root;
      } else {
        actualMenuIcons = this.menuUl.mouseOverChangeIcon[0] ? menuicons_sub_mouseOver : menuicons_sub;
      }
      thisItem.switchNodeState(thisItem, thisItem.nearestNode, null, actualMenuIcons, node_change_state_delay, false);
      thisItem.appendRemoveClassToNode(thisItem.actObj, "toOpen");
      if (isHidePreviousRootNode) {
        thisItem.setSubNodesStates("none", actualMenuIcons);
      }
      thisItem.menuUl.lastChangedItem = thisItem;
      stopBubble(e);
    }
    this.setSubNodesStates = function (newState, imageList) {
      var allSubNodes = null;
      if (this.isRoot && this.nearestNode) {
        allSubNodes = this.nearestNode.getElementsByTagName("ul");
      } else if (this.actObj) {
        allSubNodes = this.actObj.parentNode.parentNode.getElementsByTagName("ul");
      }
      if (allSubNodes) {
        for (var i = 0; i < allSubNodes.length; i++) {
          if (this.nearestNode == allSubNodes[i]) {
            continue;
          }
          this.switchNodeState(allSubNodes[i], allSubNodes[i], newState, isMenuItemRoot(allSubNodes[i]) ? menuicons_root : menuicons_sub, node_change_state_delay, false);
          if (newState == "none") {
            allSubNodes[i].parentNode.className = allSubNodes[i].parentNode.className.replace("toOpen ", "");
          } else {
            this.appendRemoveClassToNode(allSubNodes[i].parentNode.parentNode.getElementsByTagName("a")[0], "toOpen");
          }
          this.replaceSpaces(allSubNodes[i].parentNode);
        }
      }
    }
    // _KN_20120126_z
    this.switchNodeState = function (thisItem, actNode, newState, imagesList, delay, isBodyEvent) {
      var thisObj=this;
      if (actNode) {
        if (!isBodyEvent && hide_menu_delay > 0 && actNode.style.display == "block" || actNode.style.display == ""){//document.getElementById("hl").value+=" "+(actNode.style.display;)
          delayedClosingTimer=setTimeout(function(){          
            thisObj.switchNodeState_continue(thisItem, actNode, newState, imagesList, delay);                       
          },hide_menu_delay);
        }
        else{
          clearTimeout(delayedClosingTimer);          
          thisObj.switchNodeState_continue(thisItem, actNode, newState, imagesList, delay);
        }  
      }
    }
    // _KN_20120126_k
    this.switchNodeState_continue = function (thisItem, actNode, newState, imagesList, delay) {
      var thisObj=this;
      if (actNode) {
        if (actNode.tagName.toLowerCase() == "ul" && actNode.className == "menu") return;
        this.switchNodeState_execution(thisItem, actNode, newState, imagesList);        
      }
    }
    this.switchNodeState_execution = function (thisItem, actNode, newState, imagesList) {
      var thisObj = this;            
      if (newState && newState.length > 0) {
        actNode.style.display = newState;
        actNode.style.visibility = newState=="block"?"visible":"hidden";  // _KN_20120210_r
        if (thisItem) {
          thisItem = actNode.parentNode;
          if (newState == ("block" || "" || "inline")) {
            thisObj.setImageNodeParams(thisItem, imagesList[1].src, menuTexts[1], menu_items_icons_content, thisItem.getElementsByTagName("span")[0], menu_items_icons_type);
          } else {          
            thisObj.setImageNodeParams(thisItem, imagesList[0].src, menuTexts[0], menu_items_icons_content, thisItem.getElementsByTagName("span")[0], menu_items_icons_type);
          }
        }
      } 
      else if (actNode.style.display == "block" || actNode.style.display == "") {
        actNode.style.display = "none";
        actNode.style.visibility="hidden";  // _KN_20120210_r
        if (thisItem) {
          thisObj.setImageNodeParams(thisItem.iconArea, imagesList[0].src, menuTexts[0], menu_items_icons_content, thisItem.iconArea, menu_items_icons_type);
        }
      } 
      else {
        actNode.style.display = "block";
        actNode.style.visibility="visible";  // _KN_20120210_r
        if (thisItem) {
          thisObj.setImageNodeParams(thisItem.iconArea, imagesList[1].src, menuTexts[1], menu_items_icons_content, thisItem.iconArea, menu_items_icons_type);
        }
      }
    }
    this.setImageNodeParams = function (actObj, imgSrc, imgAlt, iconContent, iconContentElement, menuIconType) {
      if (menuIconType == 0 || menuIconType == 2) {
        actObj.getElementsByTagName("img")[0].src = imgSrc;
        actObj.getElementsByTagName("img")[0].setAttribute("alt", imgAlt);
      }
      if ((menuIconType == 1 || menuIconType == 2) && iconContentElement) {
        iconContentElement.innerHTML = this.getIconsAreaContent(actObj, iconContent ? iconContent : imgAlt, menuIconType);
      }
    }
    this.openParentNodes = function () {
      var actNode = this.actObj.parentNode;
      while (actNode && actNode.tagName && (actNode.tagName.toLowerCase() != "body" || actNode.id.indexOf("menu") == -1)) {
        if ((this.actObj.id == "osmakt" || this.actObj.className == "vybrana") && actNode.tagName.toLowerCase() == "ul" && actNode.className != "menu") {
          this.switchNodeState(actNode.parentNode, actNode, "block", isMenuItemRoot(actNode.parentNode) ? menuicons_root : menuicons_sub, false);
          this.appendRemoveClassToNode(actNode, "toOpen", true);
        } else if (actNode.className.toLowerCase().indexOf("toopen") > -1 && actNode.tagName.toLowerCase() == "li") {
          this.switchNodeState(actNode, actNode.getElementsByTagName("ul")[0], "block", isMenuItemRoot(actNode) ? menuicons_root : menuicons_sub, false);
        }
        actNode = actNode.parentNode;
      }
    }
    this.appendRemoveClassToNode = function (actNode, newClassName, isOnlyClassAppend) {
      if (actNode.parentNode && (isMenuItemRoot(actNode) || IS_SAME_CLASS_IN_EVERY_OPENED_LEVEL)) {
        var isToOpen = actNode.parentNode.className.toLowerCase().indexOf(newClassName.toLowerCase()) > -1 ? true : false;
        if ((isOnlyClassAppend && !isToOpen) || !isOnlyClassAppend) {
          actNode.parentNode.className = isToOpen ? actNode.parentNode.className.replace(newClassName, "") : newClassName + " " + actNode.parentNode.className;
          this.replaceSpaces(actNode.parentNode);
        }
      }
    }
  }
  this.initMenuUl();
}

function showDebugMessage(objName, message) {
  document.getElementById(objName).innerHTML = message;
  document.getElementById(objName).style.zIndex = 1000;
}

function init(params) {
  try {
    new Menu_ul(params);
  } catch (err) {}
}

function init_faster(params) {
  try {
    if (document.addEventListener) {
      document.addEventListener("DOMContentLoaded", function () {
        init(params);
      }, false);
    }
    if (document.getElementById("menu_mwb") && document.all && !window.opera) {
      document.getElementById("menu_mwb").onreadystatechange = function () {
        if (this.readyState == "complete") {
          init(params);
        }
      }
    } else if (document.getElementById("zamenu") && document.all && !window.opera) {
      document.getElementById("zamenu").onreadystatechange = function () {
        if (this.readyState == "complete") {
          init(params);
        }
      }
    }
  } catch (err) {}
  if (document.addEventListener) {
    window.addEventListener("load", function () {
      verifyPreparedMenu(params);
    }, false);
  } else {
    window.attachEvent("onload", function () {
      verifyPreparedMenu(params);
    });
  }
}

function verifyPreparedMenu(params) {
  var menuId = "menu";
  for (var i = 0; i < params.length; i++) {
    if (params[i][0] == 'menu id') {
      menuId = params[i][1];
      break;
    }
  }
  if (!document.getElementById(menuId + "MainNode")) {
    init(params);
  }
}


