/* 
 * (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.3";
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_vertical(params) {
  var IS_OPEN_AFTER_PAGE_LOAD = true;
  var MENUICONS_PATHS_ROOT = ["mul/pu1.gif", "mul/mu1.gif", "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;
  var DIRECTLINK_CLASSNAME = "directLinkBubble";
  this.menuId = "menu";
  this.expandCollapseLinksIds = ["nadmenu", "podmenu"];
  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", "přejít"];
  var menu_text = "menu";
  var menu_events_type = 0;
  var menu_icons_type = 0;
  var menu_icons_content = null;
  var menu_items_icons_type = 0;
  var menu_items_icons_content = null;
  var isHidePreviousRootNode = false;
  var node_change_state_delay = 0;
  var isRedirectToUrlByParam = true;
  var areAppendedClassesByItemsPositions = false;
  var directLinkBubbleType = 0;
  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':
        for (var j = 0; j < params[i][1].length; j++) menuTexts[j] = params[i][1][j];
        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 'menu text':
        menu_text = params[i][1];
        break;
      case 'redirect to url by param':
        isRedirectToUrlByParam = params[i][1];
        break;
      case 'append classes by items positions':
        areAppendedClassesByItemsPositions = params[i][1];
        break;
      case 'direct link bubble':
        directLinkBubbleType = params[i][1];
        break;
      }
    }
  }
  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();
    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, i);
        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.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.appendOrRemoveAttribute(thisMenu.menuItems[0], "class", "expanded", true);
          thisMenu.switchAllItems("block");
        }
        collapseLink.onclick = function () {
          thisMenu.appendOrRemoveAttribute(thisMenu.menuItems[0], "class", null, true);
          thisMenu.switchAllItems("none");
        }
      }
      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_text;
        document.getElementById("expandLink_" + menuLinkId).onclick = function () {
          thisMenu.appendOrRemoveAttribute(thisMenu.menuItems[0], "class", "expanded", true);
          thisMenu.switchAllItems("block");
        }
        document.getElementById("collapseLink_" + menuLinkId).onclick = function () {
          thisMenu.appendOrRemoveAttribute(thisMenu.menuItems[0], "class", null, true);
          thisMenu.switchAllItems("none");
        }
      }
    }
  }
  this.switchAllItems = function (nodeState) {
    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, this.menuItems[i]);
      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.appendOrRemoveAttribute = function (thisItem, attributeName, attributeValue, isAllItemsEdit) {
    if (thisItem.nearestNode) {
      if (attributeValue) {
        thisItem.actObj.setAttribute(attributeName, attributeValue);
      } else {
        thisItem.actObj.removeAttribute(attributeName);
      }
    }
    try {
      if (isAllItemsEdit) {
        this.appendOrRemoveAttribute(this.menuItems[thisItem.menuIndex + 1], "class", attributeValue ? attributeValue : null, true);
      }
    } catch (err) {}
  }
  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;
  }
  this.lastSibling = function (node) {
    var tmpObj = node.parentNode.lastChild;
    while (tmpObj.nodeType != 1 && tmpObj.previousSibling != null) {
      tmpObj = tmpObj.previousSibling;
    }
    return (tmpObj.nodeType == 1) ? tmpObj : false;
  }

  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) {}
  }

  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.isNoReload = true;
    this.directLink = null;
    this.isFromPrevious = false;
    var isTabPressed = false;
    var isShiftPressed = false;
    this.prepareItem = function () {
      var rootInfo_temp = isMenuItemRoot(this.actObj, true);
      this.levelIndex = rootInfo_temp[1];
      this.isRoot = rootInfo_temp[0];
      this.actObj.menuItem = this;
      if (this.actObj.parentNode) {
        this.nearestNode = this.actObj.parentNode.getElementsByTagName("ul")[0];
        if (this.nearestNode != null) {
          if (isRedirectToUrlByParam && this.actObj.className.toLowerCase().indexOf("noreload") == -1) {
            this.isNoReload = false;
          }
          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_onclick_handler(this);
          if (this.nearestNode.parentNode && (this.actObj.id.toLowerCase() == "osmakt" || this.actObj.className.toLowerCase().indexOf("vybrana") > -1)) {
            this.actObj.parentNode.className += " toOpen";
            this.actObj.setAttribute("class", "expanded");
          }
        } 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_handlers_to_item(this);
        if (IS_OPEN_AFTER_PAGE_LOAD) this.openParentNodes();
        if (areAppendedClassesByItemsPositions) {
          try {
            if (this.menuUl.lastSibling(this.actObj.parentNode) == this.actObj.parentNode) {
              this.appendClassToItem(this.menuUl.lastSibling(this.actObj.parentNode), (this.actObj.parentNode.getElementsByTagName("ul").length > 0 ? "lastnode" : "lastitem"));
            }
          } catch (err) {}
        }
      }
    }
    this.replaceSpaces = function (actObj) {
      if (actObj.className.toLowerCase().indexOf(" ") == 0) {
        actObj.className = actObj.className.replace(" ", "");
      }
    }
    this.append_onclick_handler = function (thisItem) {
      if (menu_events_type == 0) {
        thisItem.iconArea.onclick = thisItem.actObj.onclick = function (e) {
          setTimeout(function () {
            thisItem.changeNode(thisItem);
            if (thisItem.actObj.parentNode.getElementsByTagName("ul")[0].style.display.toLowerCase() == ("block" || "" || "inline")) {
              thisItem.menuUl.appendOrRemoveAttribute(thisItem, "class", "expanded", false);
            } else {
              thisItem.menuUl.appendOrRemoveAttribute(thisItem, "class", null, false);
            }
            stopBubble(e);
          }, node_change_state_delay);
          return false;
        }
      }
    }
    this.append_handlers_to_item = function (thisItem) {
      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.onmouseover = 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.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) {}
    }
    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) {
      if (isHidePreviousRootNode) {
        var actualMenuIcons = null;
        if (thisItem.isRoot) {
          if (!(thisItem.nearestNode.style.display == ("block" || "" || "inline"))) {
            this.menuUl.switchAllItems("none");
          }
          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);
        this.appendRemoveClassToNode(thisItem.actObj, "toOpen");
        this.setSubNodesStates("none", null);
        this.menuUl.lastChangedItem = thisItem;
      } else {
        if (thisItem.isRoot) {
          thisItem.switchNodeState(thisItem, thisItem.nearestNode, null, this.menuUl.mouseOverChangeIcon[0] ? menuicons_root_mouseOver : menuicons_root);
        } else {
          thisItem.switchNodeState(thisItem, thisItem.nearestNode, null, this.menuUl.mouseOverChangeIcon[0] ? menuicons_sub_mouseOver : menuicons_sub);
        }
        this.appendRemoveClassToNode(thisItem.actObj, "toOpen");
      }
    }
    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;
          }
          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);
        }
      }
    }
    this.switchNodeState = function (thisItem, actNode, newState, imagesList) {
      if (actNode) {
        if (actNode.tagName.toLowerCase() == "ul" && actNode.className == "menu") return;
        if (newState && newState.length > 0) {
          actNode.style.display = newState;
          if (thisItem) {
            if (newState == ("block" || "" || "inline")) {
              this.setImageNodeParams(thisItem, imagesList[1].src, menuTexts[1], menu_items_icons_content, thisItem.getElementsByTagName("span")[0], menu_items_icons_type);
              if (directLinkBubbleType > 0 && arguments.length == 5 && arguments[4].actObj) this.appendDirectLink(arguments[4]);
            } else {
              this.setImageNodeParams(thisItem, imagesList[0].src, menuTexts[0], menu_items_icons_content, thisItem.getElementsByTagName("span")[0], menu_items_icons_type);
              if (directLinkBubbleType > 0 && arguments.length == 5 && arguments[4].actObj) this.removeDirectLink(arguments[4]);
            }
          }
        } else if (actNode.style.display == "block" || actNode.style.display == "") {
          actNode.style.display = "none";
          if (thisItem) {
            this.setImageNodeParams(thisItem.iconArea, imagesList[0].src, menuTexts[0], menu_items_icons_content, thisItem.iconArea, menu_items_icons_type);
            if (directLinkBubbleType > 0) this.removeDirectLink(thisItem);
          }
        } else {
          actNode.style.display = "block";
          if (thisItem) {
            this.setImageNodeParams(thisItem.iconArea, imagesList[1].src, menuTexts[1], menu_items_icons_content, thisItem.iconArea, menu_items_icons_type);
            if (directLinkBubbleType > 0) this.appendDirectLink(thisItem);
          }
        }
      }
    }
    this.appendDirectLink = function (thisItem) {
      var MINUS_OFFSET = 50;
      var MIN_LETTER_WIDTH = 3;
      if (thisItem.isNoReload) return;
      var collectedText = menuTexts[7] + " " + thisItem.actObj.innerHTML + "";
      try {
        var fontDetector = new FontDetector();
        var fontSize = fontDetector.getStyleByParameter(thisItem.actObj, 'font-size');
        var fontFamily = fontDetector.getStyleByParameter(thisItem.actObj, 'font-family');
        var list = thisItem.actObj.parentNode.getElementsByTagName("ul")[0];
        thisItem.directLink = document.createElement("li");
        thisItem.directLink.className = DIRECTLINK_CLASSNAME;
        thisItem.directLink.style.display = "block";
        thisItem.directLink.style.position = "absolute";
        thisItem.directLink.style.width = (fontDetector.getSizes(collectedText, fontSize, fontFamily).width) + "px";
        thisItem.directLink.style.left = (fontDetector.getSizes(thisItem.actObj.innerHTML, fontSize, fontFamily).width) + "px";
        thisItem.directLink.style.top = "1px";
        thisItem.directLink.style.padding = "1px";
        thisItem.directLink.style.backgroundColor = "#ffffff";
        thisItem.directLink.style.border = "1px solid #000000";
        thisItem.directLink.style.zIndex = "100";
        var newLink = document.createElement("a");
        newLink.menuItem = thisItem;
        newLink.setAttribute("href", thisItem.actObj.getAttribute("href"));
        newLink.innerHTML = collectedText;
        thisItem.directLink.appendChild(newLink);
        list.appendChild(thisItem.directLink);
        list.insertBefore(thisItem.directLink, list.childNodes[0]);
        if (directLinkBubbleType == 2) {
          thisItem.actObj.onmouseover = function () {
            this.menuItem.directLink.style.display = "block";
          }
          thisItem.actObj.onmouseout = function () {
            this.menuItem.directLink.style.display = "none";
          }
          thisItem.actObj.onfocus = function () {
            this.menuItem.directLink.style.display = "block";
            if (this.menuItem.isFromPrevious) {
              this.menuItem.isFromPrevious = false;
              this.menuItem.directLink.getElementsByTagName("a")[0].focus();
            }
          }
          thisItem.directLink.onmouseover = function () {
            this.style.display = "block";
          }
          thisItem.directLink.onmouseout = function () {
            this.style.display = "none";
          }
          thisItem.actObj.onkeydown = function (e) {
            this.menuItem.keyDownHandler(e);
          }
          thisItem.actObj.onkeyup = function (e) {
            this.menuItem.keyUpHandler(e);
          }
          thisItem.actObj.onkeypress = function (e) {
            this.menuItem.keyPressHandler(e, "beforeDirectLink");
          }
          thisItem.directLink.parentNode.getElementsByTagName("li")[1].getElementsByTagName("a")[0].onkeydown = function (e) {
            this.parentNode.parentNode.getElementsByTagName("a")[0].menuItem.keyDownHandler(e);
          }
          thisItem.directLink.parentNode.getElementsByTagName("li")[1].getElementsByTagName("a")[0].onkeyup = function (e) {
            this.parentNode.parentNode.getElementsByTagName("a")[0].menuItem.keyUpHandler(e);
          }
          thisItem.directLink.parentNode.getElementsByTagName("li")[1].getElementsByTagName("a")[0].onkeypress = function (e) {
            this.parentNode.parentNode.getElementsByTagName("a")[0].menuItem.keyPressHandler(e, "afterDirectLink");
          }
        }
      } catch (err) {}
    }
    this.keyDownHandler = function (e) {
      if (isShiftPressed) return;
      var keyCode = this.menuUl.getKeyCode(e);
      switch (parseInt(keyCode)) {
      case 16:
        isShiftPressed = true;
        break;
      }
    }
    this.keyUpHandler = function (e) {
      var keyCode = this.menuUl.getKeyCode(e);
      switch (parseInt(keyCode)) {
      case 9:
        isTabPressed = true;
        break;
      case 16:
        isShiftPressed = false;
        break;
      }
    }
    this.keyPressHandler = function (e, cursorPosition) {
      if (isTabPressed && !isShiftPressed) {
        if (cursorPosition == "beforeDirectLink") {
          this.directLink.style.display = "block";
          this.isFromPrevious = true;
        } else if (cursorPosition == "afterDirectLink") {
          this.directLink.style.display = "none";
          this.isFromPrevious = false;
        }
      }
      if (isTabPressed && isShiftPressed) {
        if (cursorPosition == "beforeDirectLink") {
          this.directLink.style.display = "none";
          this.isFromPrevious = false;
        } else if (cursorPosition == "afterDirectLink") {
          this.directLink.style.display = "block";
          this.isFromPrevious = true;
        }
      }
      isTabPressed = false;
    }
    this.removeDirectLink = function (thisItem) {
      try {
        thisItem.actObj.onmouseover = null;
        var list = thisItem.actObj.parentNode.getElementsByTagName("ul")[0];
        if (list && list.firstChild.className == DIRECTLINK_CLASSNAME) list.removeChild(list.firstChild);
      } catch (err) {}
    }
    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);
          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);
        }
        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.appendClassToItem = function (actItem, newClassName) {
      var isToOpen = actItem.className.toLowerCase().indexOf(newClassName.toLowerCase()) > -1 ? true : false;
      actItem.className = isToOpen ? actItem.className.replace(newClassName, "") : newClassName + " " + actItem.className;
      this.replaceSpaces(actItem);
    }
  }
  this.getKeyCode = function (e) {
    var keyCode;
    if (window.event) keyCode = window.event.keyCode;
    else if (e) keyCode = e.which;
    return keyCode;
  }
  this.initMenuUl();
}

function showDebugMessage(objName, message) {
  document.getElementById(objName).innerHTML += "," + message;
  document.getElementById(objName).style.zIndex = 1000;
}

function initVerticalMenu(params) {
  try {
    new Menu_ul_vertical(params);
  } catch (err) {}
}

function init_faster(params) {
  try {
    if (document.addEventListener) {
      document.addEventListener("DOMContentLoaded", function () {
        initVerticalMenu(params);
      }, false);
    }
    if (document.getElementById("menu_mwb") && document.all && !window.opera) {
      document.getElementById("menu_mwb").onreadystatechange = function () {
        if (this.readyState == "complete") {
          initVerticalMenu(params);
        }
      }
    } else if (document.getElementById("zamenu") && document.all && !window.opera) {
      document.getElementById("zamenu").onreadystatechange = function () {
        if (this.readyState == "complete") {
          initVerticalMenu(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")) {
    initVerticalMenu(params);
  }
}

function FontDetector(srcText, fontSize, fontFamily) {
  this.fontSizeDetector = function (srcText, fontSize, fontFamily) {}
  this.getSizes = function (srcText, fontSize, fontFamily) {
    var totalSizes = {
      width: 0,
      height: 0
    };
    var tmpObjDiv = document.createElement("div");
    tmpObjDiv.style.left = "-10000px";
    var tmpObj = document.createElement("span");
    tmpObjDiv.appendChild(tmpObj);
    tmpObj.style.fontSize = fontSize;
    tmpObj.style.fontFamily = fontFamily;
    tmpObj.innerHTML = srcText;
    document.getElementsByTagName("body")[0].appendChild(tmpObjDiv);
    totalSizes.width = tmpObj.offsetWidth;
    totalSizes.height = tmpObj.offsetHeight;
    tmpObjDiv.parentNode.removeChild(tmpObjDiv);
    return totalSizes;
  }
  this.getStyleByParameter = function (actObj, fontFeature) {
    var result = "";
    try {
      result = getComputedStyle(actObj, '').getPropertyValue(fontFeature);
    } catch (err) {
      switch (fontFeature) {
      case "font-size":
        fontFeature = "fontSize";
        break;
      case "font-family":
        fontFeature = "fontFamily";
        break;
      }
      result = eval("actObj.currentStyle." + fontFeature);
    }
    return result;
  }
}
