//==================================================================================
//==================================================================================
//
// Navigation-Tool
// OO-PROGRAMMIERUNG
// AUTOR: DF
// © rdts AG
// ERSTELLT: 01.07.2005
//
// Menus für IE- und GECKO-Browser
//
//==================================================================================
//==================================================================================

function Navigation(id) {
  if (arguments.length>1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  this._id = undefined;
  this._setID(id);
  this._navigationAllowedStatus = undefined;
  this._direction = 'horizontal';
  this._dependVertical = 'top';
  this._dependHorizontal = 'right';
  this._highlightActiveRoot = 'no';
  this._highlightActiveClassPostfix = undefined;
  this._rootLeft = 0;
  this._rootTop = 0;
  this._differenceVertical = 0;
  this._differenceHorizontal = 0;
  this._navigationStructure = {};
  this._registerStructureItem = {};
  this._activeMenu = {};
  this._menuInUse = false;
  this._containerIDPrefix = this.id() + '_Nav';
  this._itemIDPrefix = this.id() + '_Item';
  this._timeout = undefined;
  this._delay = undefined;
  this._getNavigationStructureHTMLRoot = true;
  this._displayStructureOnLoad = 'no';
  
  this.setDelay(1000);
}

Navigation.prototype.toString = function() {
  return "\n[Navigation - id: " + this + "]\n";
}


Navigation.prototype.id = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._id = str;
  }
  return this._id;
}

Navigation.prototype.navigationStructure = function(obj) {
  if (arguments.length) {
    if (typeof obj != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._navigationStructure = obj;
  }
  return this._navigationStructure;
}

Navigation.prototype.registerStructureItem = function(obj) {
  if (arguments.length) {
    if (typeof obj != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._registerStructureItem = obj;
  }
  return this._registerStructureItem;
}

Navigation.prototype._direction = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._direction = str;
  return this._direction;
}


Navigation.prototype._setID = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.id(str);
}

Navigation.prototype._setRegisterStructureItem = function(obj) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof obj != "object") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.registerStructureItem(obj);
}

Navigation.prototype._setRootPosition = function() {
  var id = this._containerIDPrefix + 'root';
  if (document.getElementById(id)){
    var elem = document.getElementById(id);
    if (elem.offsetParent){
      elem = elem.offsetParent;
    }
    this._rootLeft = elem.offsetLeft;
    this._rootTop = elem.offsetTop;
  }
}

Navigation.prototype._getNavigationStructureHTML = function(structure, html, id, loopPosition) {
  var containerClassName = '';
  var first = undefined;
  var second = undefined;
  if (loopPosition == 1){
    first = true;
  }
  if (loopPosition == 2){
    second = true;
  }
  var containerStyle = 'display: none;';
  if (this._getNavigationStructureHTMLRoot){
    containerStyle = 'display: block;';    
  }
  if (NavigationItem.hasInstance(id) && NavigationItem.getInstance(id).style()){
    containerStyle += NavigationItem.getInstance(id).style();
  }
  if (NavigationItem.hasInstance(id) && NavigationItem.getInstance(id).className()){
    containerClassName = 'class="'+ NavigationItem.getInstance(id).className() +'"';
  }
  this._getNavigationStructureHTMLRoot = false;
  if (this._direction == 'vertical'){
    if (loopPosition > 1 &&  loopPosition <= 2){
      html += '<div id="'+ id +'"  '+ containerClassName +' style="'+ containerStyle +' position: absolute; top: 20px;">';
    } else  if (loopPosition > 2){
      html += '<div id="'+ id +'"  '+ containerClassName +' style="'+ containerStyle +' position: static;">';
    } else {
      html += '<div id="'+ id +'" '+ containerClassName +' style="'+ containerStyle +' position: absolute;">';
    }
    for (var i in structure){
      var id = this._containerIDPrefix + i;
      var cssStyle = '';
      var cssClassName = '';
      var href = 'href="javascript:void(0);"';
      var target = '';
      var onclick = '';
      var label = this.registerStructureItem()[id].label();
      var title = '';
      if (this.registerStructureItem()[id].style()){
        cssStyle = 'style="' + this.registerStructureItem()[id].style() + '" ';
      }
      if (this.registerStructureItem()[id].className()){
        cssClassName = 'class="' + this.registerStructureItem()[id].className() + '" ';
      }
      if (this.registerStructureItem()[id].href()){
        href = 'href="' + this.registerStructureItem()[id].href() + '" ';
      }
      if (this.registerStructureItem()[id].target()){
        target = 'target="' + this.registerStructureItem()[id].target() + '" ';
      }
      if (this.registerStructureItem()[id].onclick()){
        onclick = 'onclick="' + this.registerStructureItem()[id].onclick();
      } else {
      }
      if (this.registerStructureItem()[id].title()){
        title = 'title="' + this.registerStructureItem()[id].title() + '" ';
      }
      if (first){
        html += '<div id="'+ this._itemIDPrefix + this.registerStructureItem()[id].id() +'" style="position: static; float: left;">\n';
      } else {
        html += '<div id="'+ this._itemIDPrefix + this.registerStructureItem()[id].id() +'" style="position: static;">\n';
      }
      if (this._dependVertical == 'top'){
        if (typeof structure[i] == 'object'){
          html += this._getNavigationStructureHTML(structure[i], '', id, loopPosition+1);
        } 
      }
      if (this.registerStructureItem()[id].type() == 0){
        if (this.registerStructureItem()[id].subClassName()){
          cssClassName = 'class="' + this.registerStructureItem()[id].subClassName() + '" ';
        }
        if (this.registerStructureItem()[id].subStyle()){
          cssStyle = 'style="' + this.registerStructureItem()[id].subStyle() + ' display: block;" ';
        }
        if (first){
          html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' onmouseout="Navigation.getInstance(\''+ this.id() +'\').collapseMenu();" onmouseover="Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');" '+ title +'>' + label +'</a>\n';
        } else {
          html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' onmouseout="Navigation.getInstance(\''+ this.id() +'\').collapseMenu();" '+ title +'>' + label +'</a>\n';
        }
      } else {
        html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' onmouseout="Navigation.getInstance(\''+ this.id() +'\').collapseMenu();" onmouseover="Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');" '+ title +'>' + label +'</a>\n';
      }
      if (this._dependVertical != 'top'){
        if (typeof structure[i] == 'object'){
          html += this._getNavigationStructureHTML(structure[i], '', id, loopPosition+1);
        } 
      } 
      html += '</div>\n'; 
    }
    html += '</div>';
  } else {
    html += '<div id="'+ id +'"  '+ containerClassName +' style="'+ containerStyle +'">\n';
    for (var i in structure){
      var id = this._containerIDPrefix + i;
      var cssStyle = '';
      var cssClassName = '';
      var href = 'href="javascript:void(0);"';
      var target = '';
      var onclick = '';
      var label = this.registerStructureItem()[id].label();
      var title = '';
      if (this.registerStructureItem()[id].style()){
        cssStyle = 'style="' + this.registerStructureItem()[id].style() + '" ';
      }
      if (this.registerStructureItem()[id].className()){
        cssClassName = 'class="' + this.registerStructureItem()[id].className() + '" ';
      }
      if (this.registerStructureItem()[id].href()){
        href = 'href="' + this.registerStructureItem()[id].href() + '" ';
      }
      if (this.registerStructureItem()[id].target()){
        target = 'target="' + this.registerStructureItem()[id].target() + '" ';
      }
      if (this.registerStructureItem()[id].onclick()){
        onclick = 'onclick="' + this.registerStructureItem()[id].onclick() + '" ';
      }
      if (this.registerStructureItem()[id].onclick()){
        if(document.all && !navigator.userAgent.match(/Opera/)){
          // NUR WENN PER SCRIPT DIE EIGENSCHAFTEN AUSGELESEN WERDEN
          onclick = 'onclick="new ' + this.registerStructureItem()[id].onclick() + '; Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');"';
        } else {
          onclick = 'onclick="' + this.registerStructureItem()[id].onclick() + '; Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');"';
        }
      } else {
        onclick = 'onclick="Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');"';
      }
      if (this.registerStructureItem()[id].title()){
        title = 'title="' + this.registerStructureItem()[id].title() + '" ';
      }
      if (first){
        html += '<div id="'+ this._itemIDPrefix + this.registerStructureItem()[id].id() +'" class="level-1-item">\n';
      } else if (second){
        html += '<div id="'+ this._itemIDPrefix + this.registerStructureItem()[id].id() +'" class="level-2-item">\n';
      } else {
        html += '<div id="'+ this._itemIDPrefix + this.registerStructureItem()[id].id() +'" class="level-sub-item">\n';
      }
      if (this.registerStructureItem()[id].type() == 0){
        if (this.registerStructureItem()[id].subClassName()){
          cssClassName = 'class="' + this.registerStructureItem()[id].subClassName() + '" ';
        }
        if (this.registerStructureItem()[id].subStyle()){
          cssStyle = 'style="' + this.registerStructureItem()[id].subStyle() + ' display: block;" ';
        }
        html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' '+ title +'>' + label +'</a>\n';
        //html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' onmouseout="Navigation.getInstance(\''+ this.id() +'\').collapseMenu();" onmouseover="Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');" '+ title +'>' + label +'</a>\n';
      } else {
        html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' '+ title +'>' + label +'</a>\n';
        //html += '<a id="button_'+ this.registerStructureItem()[id].id() +'" '+ href +' '+ cssStyle +' '+ cssClassName +' '+ target +' '+ onclick +' onmouseout="Navigation.getInstance(\''+ this.id() +'\').collapseMenu();" onmouseover="Navigation.getInstance(\''+ this.id() +'\').displaySubmenu(\''+ this.registerStructureItem()[id].id() +'\');" '+ title +'>' + label +'</a>\n';
      } 
      html += '</div>\n';
    } 
    if (first){
      html += '<div class="float-aufheben"><br /></div>\n';
    }
    html += '</div>\n';
    loopPosition++;
    for (var i in structure){
      var id = this._containerIDPrefix + '' + i;
      if (typeof structure[i] == 'object'){
        html += this._getNavigationStructureHTML(structure[i], '', id, loopPosition);
      } 
    }
  }
  return html;
}


Navigation.prototype._setHighlightedItems = function(id) {
  var items = [];
  var activeItem = NavigationItem.getInstance(id);
  items.push(activeItem);
  for (var i=0; i<items.length; i++){
    var elem = document.getElementById('button_' + items[i].id());
    if (elem){
      var className = items[i].subClassName() + this._highlightActiveClassPostfix;
      elem.className = className;
    }  
  }
}

Navigation.prototype._setOffHighlightedItems = function(id) {
  var items = [];
  var activeItem = NavigationItem.getInstance(id);
  items.push(activeItem);
  for (var i=0; i<items.length; i++){
    var elem = document.getElementById('button_' + items[i].id());
    if (elem){
      var className = items[i].subClassName();
      elem.className = className;
    }  
  }
}



// -------

// _getNavigationStructureActiveRootItems

// -------

Navigation.prototype._getNavigationStructureActiveRootItems = function(nodeList, arr) {
  if (arguments.length!=2) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  for (var i in nodeList){
    var id = this._containerIDPrefix + i;
    var item = NavigationItem.getInstance(id);
    if (item){
      if (item.isRootActiveElement() == 'yes'){
        arr.push(id);
      }
    }
    if (typeof nodeList[i] == 'object'){
      this._getNavigationStructureActiveRootItems(nodeList[i], arr);
    }
  }
  return arr;
}


// -------
// _displaySubmenuOnLoad
// -------
Navigation.prototype._displaySubmenuOnLoad = function() {
  var arr = [];
  arr = this._getNavigationStructureActiveRootItems(this.navigationStructure(), arr);
  //alert(arr.length);
  for (var i=0; i<arr.length; i++){
    this.displaySubmenu(arr[i]);
  }
}


Navigation.prototype.setDirection = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._direction = str;
}

Navigation.prototype.getNavigationAllowedStatus = function() {
  if (document.getElementById){
    this._navigationAllowedStatus = true;
  }
  return this._navigationAllowedStatus;
}

Navigation.prototype.setDelay = function(n) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (!NavigationTools.checkNumber(n)) {
    focus();
    throw new Error("Argument ist nicht vom Typ Number!");
  }
  if (document.all){
    if (n < 1200){
      n = n + (n/5);
    }
  }
  this._delay = n;
}

Navigation.prototype.setHighlightActiveRoot = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._highlightActiveRoot = str;
}

Navigation.prototype.setHighlightActiveClassPostfix = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._highlightActiveClassPostfix = str;
}

Navigation.prototype.setDependHorizontal = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._dependHorizontal = str;
}

Navigation.prototype.setDependVertical = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._dependVertical = str;
}

Navigation.prototype.setDifferenceVertical = function(n) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (!NavigationTools.checkNumber(n)) {
    focus();
    throw new Error("Argument ist nicht vom Typ Number!");
  }
  this._differenceVertical = n;
}

Navigation.prototype.setDifferenceHorizontal = function(n) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (!NavigationTools.checkNumber(n)) {
    focus();
    throw new Error("Argument ist nicht vom Typ Number!");
  }
  this._differenceHorizontal = n;
}

Navigation.prototype.setNavigationStructure = function(obj) {
  if(!this.getNavigationAllowedStatus()){
    return;
  }
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof obj != "object") {
    focus();
    throw new Error("Argument ist nicht vom Typ HMTL-Object!");
  }
  var structure = {};
  structure = Navigation._getNavigationStructureByNode(obj, structure, '', 0, this._containerIDPrefix);
  this.navigationStructure(structure);
  this._setRegisterStructureItem(NavigationItem._registerInstance);
}

Navigation.prototype.drawNavigationStructure = function(html) {
  if(!this.getNavigationAllowedStatus()){
    return;
  }
  if(!document.getElementById(this.id())){
    return;
  }
  var html = '';
  html += this._getNavigationStructureHTML(Navigation._getFirstItem(this.navigationStructure()), '', this._containerIDPrefix + 'root', 1);
  /*
  var win = window.open('','test');
  var doc = win.document;
  doc.open();
  doc.write(html);
  doc.close();
  */
  document.getElementById(this.id()).innerHTML = html;
  this._setRootPosition();
  if (this._displayStructureOnLoad == 'yes'){
    this._displaySubmenuOnLoad();
  }
}

// -------
// setDisplayStructureOnLoad
// -------
Navigation.prototype.setDisplayStructureOnLoad = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this._displayStructureOnLoad = str;
}

Navigation.prototype.hideVisitedNavigation = function(id) {
  var item = NavigationItem.getInstance(id);
  for (var i in this._activeMenu){
    var rootPos = i.split(this._containerIDPrefix)[1];
    if (item.rootObj()[rootPos] == undefined){
      if (this._activeMenu[i]['elem']){
        this._activeMenu[i]['elem'].style.display = 'none';
        this._setOffHighlightedItems(this._activeMenu[i]['item'].id());
      }
      delete this._activeMenu[i];
    }
  }
}

Navigation.prototype.showActiveNavigation = function(id) {
  var elem = document.getElementById(id);
  if (elem){
    this.setElementPosition(id);
    if (elem.style.display == 'block'){
      elem.display = 'none';
    } else {
      elem.style.display = 'block';
    } 
    if (this._highlightActiveRoot == 'yes'){
      if (this._highlightActiveClassPostfix){
        this._setHighlightedItems(id);
      }
    }
  }
}

Navigation.prototype.setElementPosition = function(id) {
  var item = NavigationItem.getInstance(id);
  var rootPos = id.split(this._containerIDPrefix)[1];
  var activeItem = NavigationItem.createInstance(this._itemIDPrefix +''+ id, '');
  if (this._direction == 'vertical'){
    if (document.getElementById(id)){
      if (this._dependHorizontal=='left'){
        document.getElementById(id).style.marginRight =  this._differenceHorizontal + 'px';
      } else {
        document.getElementById(id).style.marginLeft =  this._differenceHorizontal + 'px';
      }
      document.getElementById(id).style.marginTop = this._differenceVertical + 'px';
    }
  } else {  
    var _top;
    var _left;
    if (item.rootObj()[rootPos]){
      var idxR = parseFloat(item.rootObj()[rootPos] -1);
      if (item.rootArr()[idxR]){
        var rootItem = NavigationItem.getInstance(this._containerIDPrefix +''+ item.rootArr()[idxR]);
        if (this._dependHorizontal == 'left'){
          if (rootItem.properties().getLeft() != undefined){
            _left = parseFloat(rootItem.properties().getLeft() - item.properties().getWidth());
          } else {
            if (document.getElementById(this._itemIDPrefix +''+ id)){
            _left = parseFloat(activeItem.properties().getLeft() - item.properties().getWidth());
            }
          }
        } else {
          if (idxR > 0) {
            if (rootItem.properties().getRight() != undefined){
              if (idxR == 1) {
                _left = activeItem.properties().getRight();
              } else {
                _left = rootItem.properties().getRight();
              }
            } else {
              if (document.getElementById(this._itemIDPrefix +''+ id)){
              _left = activeItem.properties().getRight();
              }
            }
          }
        }
        if (this._dependVertical=='middle'){
          if (document.getElementById(this._itemIDPrefix +''+ id)){
            _top = parseFloat(activeItem.properties().getTop() + parseFloat(activeItem.properties().getHeight() / 2));
          }
        } else if (this._dependVertical=='bottom'){
          if (document.getElementById(this._itemIDPrefix +''+ id)){
            _top = activeItem.properties().getBottom();
          } 
        } else {
          if (document.getElementById(this._itemIDPrefix +''+ id)){
            _top = activeItem.properties().getTop();
          } 
        }
      }
    }
    if (document.getElementById(id)){
      if (_top != undefined){
        if (idxR > 1){
          document.getElementById(id).style.top = parseFloat(parseFloat(_top + this._differenceVertical) - this._rootTop) + 'px';
        } else {
          //document.getElementById(id).style.top = parseFloat(parseFloat(_top) - this._rootTop) + 'px';
        }  
      }
      if (navigator.userAgent.match(/Opera/)){
        document.getElementById(id).style.position = 'absolute';
      }
      if (_left != undefined){   
        if (idxR > 1){  
          document.getElementById(id).style.left = parseFloat(parseFloat(_left + this._differenceHorizontal) - this._rootLeft) + 'px';
        } else {  
          document.getElementById(id).style.left = parseFloat(parseFloat(_left - activeItem.properties().getWidth()) - this._rootLeft) + 'px';
        }
      }
      if (navigator.userAgent.match(/Opera/)){
        document.getElementById(id).style.position = 'absolute';
      }
    }
  }
}

Navigation.prototype.displaySubmenu = function(id) {
  this._menuInUse = true;
  var item = NavigationItem.getInstance(id);
  var elem = undefined;
  if (document.getElementById(id)){
    elem = document.getElementById(id);
  }
  this.hideVisitedNavigation(id);
  this.showActiveNavigation(id);
  /*
  var rootPos = id.split(this._containerIDPrefix)[1];
  var item = NavigationItem.getInstance(id);
  for (var i in NavigationItem._registerInstance){
    var subitem = NavigationItem._registerInstance[i];
    if (subitem.rootObj()[rootPos]){
      this.showActiveNavigation(subitem.id());
    }
  }
  */
  if (this._direction == 'vertical'){
    if (this._activeMenu[id] || item.type() == 1){
      this._menuInUse = true;
      this.hideAll();
      return;
    }
  }
  this._activeMenu[id] = {};
  if (document.getElementById(id)){
    this._activeMenu[id]['elem'] = document.getElementById(id);
  }
  this._activeMenu[id]['item'] = item;
}

Navigation.prototype.collapseMenu = function() {
  this._menuInUse = false;
  var funcStr = 'Navigation.getInstance(\''+ this.id() +'\').hideAll()';
  this._timeout = window.setTimeout(funcStr, this._delay);
}

Navigation.prototype.hideAll = function() {
  if (this._timeout){
    window.clearTimeout(this._timeout);
  }
  if (!this._menuInUse){
    for (var i in this._activeMenu){
      if (this._activeMenu[i]['elem']){
        this._activeMenu[i]['elem'].style.display = 'none';
        this._setOffHighlightedItems(this._activeMenu[i]['item'].id());
      }
      delete this._activeMenu[i];
    }
  }
}


Navigation._defaultID = [];

Navigation._registerInstance = {};

Navigation._getNavigationStructureHTMLRoot = true;

Navigation._attributesToIE = {};
Navigation._attributesToIE['src'] = 'src';
Navigation._attributesToIE['style'] = 'style';
Navigation._attributesToIE['align'] = 'align';
Navigation._attributesToIE['title'] = 'title';
Navigation._attributesToIE['alt'] = 'alt';
Navigation._attributesToIE['valign'] = 'valign';
Navigation._attributesToIE['vspace'] = 'vspace';
Navigation._attributesToIE['hspace'] = 'hspace';
Navigation._attributesToIE['class'] = 'className';
Navigation._attributesToIE['border'] = 'border';
Navigation._attributesToIE['cellspacing'] = 'cellspacing';
Navigation._attributesToIE['cellpadding'] = 'cellpadding';
Navigation._attributesToIE['data'] = 'data';
Navigation._attributesToIE['marginwidth'] = 'marginwidth';
Navigation._attributesToIE['marginheight'] = 'marginheight';
Navigation._attributesToIE['margintop'] = 'margintop';
Navigation._attributesToIE['marginleft'] = 'marginleft';
Navigation._attributesToIE['frameborder'] = 'frameborder';
Navigation._attributesToIE['dataformatas'] = 'dataformatas';
Navigation._attributesToIE['type'] = 'type';
Navigation._attributesToIE['width'] = 'width';
Navigation._attributesToIE['height'] = 'height';
Navigation._attributesToIE['onmouseover'] = 'onMouseover';
Navigation._attributesToIE['onmouseout'] = 'onMouseout';
Navigation._attributesToIE['onclick'] = 'onClick';
Navigation._attributesToIE['onfocus'] = 'onFocus';
Navigation._attributesToIE['onblur'] = 'onBlur';
Navigation._attributesToIE['onload'] = 'onLoad';
Navigation._attributesToIE['onchange'] = 'onChange';
Navigation._attributesToIE['onsubmit'] = 'onSubmit';
Navigation._attributesToIE['name'] = 'name';
Navigation._attributesToIE['value'] = 'value';
Navigation._attributesToIE['id'] = 'id';
Navigation._attributesToIE['href'] = 'href';
Navigation._attributesToIE['target'] = 'target';


Navigation._attributesIE = {};
Navigation._attributesIE['src'] = 'src';
Navigation._attributesIE['style'] = 'style';
Navigation._attributesIE['align'] = 'align';
Navigation._attributesIE['title'] = 'title';
Navigation._attributesIE['alt'] = 'alt';
Navigation._attributesIE['valign'] = 'valign';
Navigation._attributesIE['vspace'] = 'vspace';
Navigation._attributesIE['hspace'] = 'hspace';
Navigation._attributesIE['className'] = 'class';
Navigation._attributesIE['border'] = 'border';
Navigation._attributesIE['cellspacing'] = 'cellspacing';
Navigation._attributesIE['cellpadding'] = 'cellpadding';
Navigation._attributesIE['data'] = 'data';
Navigation._attributesIE['marginwidth'] = 'marginwidth';
Navigation._attributesIE['marginheight'] = 'marginheight';
Navigation._attributesIE['margintop'] = 'margintop';
Navigation._attributesIE['marginleft'] = 'marginleft';
Navigation._attributesIE['frameborder'] = 'frameborder';
Navigation._attributesIE['dataformatas'] = 'dataformatas';
Navigation._attributesIE['type'] = 'type';
Navigation._attributesIE['width'] = 'width';
Navigation._attributesIE['height'] = 'height';
Navigation._attributesIE['onMouseover'] = 'onmouseover';
Navigation._attributesIE['onMouseout'] = 'onmouseout';
Navigation._attributesIE['onClick'] = 'onclick';
Navigation._attributesIE['onFocus'] = 'onfocus';
Navigation._attributesIE['onBlur'] = 'onblur';
Navigation._attributesIE['onLoad'] = 'onload';
Navigation._attributesIE['onChange'] = 'onchange';
Navigation._attributesIE['onSubmit'] = 'onsubmit';
Navigation._attributesIE['name'] = 'name';
Navigation._attributesIE['value'] = 'value';
Navigation._attributesIE['id'] = 'id';
Navigation._attributesIE['href'] = 'href';
Navigation._attributesIE['target'] = 'target';

Navigation._styleAttributesIE = {};
Navigation._styleAttributesIE['width'] = 'width';
Navigation._styleAttributesIE['height'] = 'height';
Navigation._styleAttributesIE['top'] = 'top';
Navigation._styleAttributesIE['left'] = 'left';
Navigation._styleAttributesIE['display'] = 'display';
Navigation._styleAttributesIE['position'] = 'position';
Navigation._styleAttributesIE['textAlign'] = 'text-align';
Navigation._styleAttributesIE['textDecoration'] = 'text-decoration';
Navigation._styleAttributesIE['padding'] = 'padding';
Navigation._styleAttributesIE['paddingTop'] = 'padding-top';
Navigation._styleAttributesIE['paddingRight'] = 'padding-right';
Navigation._styleAttributesIE['paddingBottom'] = 'padding-bottom';
Navigation._styleAttributesIE['paddingLeft'] = 'padding-left';
Navigation._styleAttributesIE['margin'] = 'margin';
Navigation._styleAttributesIE['marginTop'] = 'margin-top';
Navigation._styleAttributesIE['marginRight'] = 'margin-right';
Navigation._styleAttributesIE['marginBottom'] = 'margin-bottom';
Navigation._styleAttributesIE['marginLeft'] = 'margin-left';
Navigation._styleAttributesIE['border'] = 'border';
Navigation._styleAttributesIE['borderLeft'] = 'border-left';
Navigation._styleAttributesIE['borderRight'] = 'border-right';
Navigation._styleAttributesIE['borderTop'] = 'border-top';
Navigation._styleAttributesIE['borderBottom'] = 'border-bottom';
Navigation._styleAttributesIE['borderColor'] = 'border-color';
Navigation._styleAttributesIE['borderStyle'] = 'border-style';
Navigation._styleAttributesIE['borderWidth'] = 'border-width';
Navigation._styleAttributesIE['borderCollapse'] = 'border-collapse';
Navigation._styleAttributesIE['fontSize'] = 'font-size';
Navigation._styleAttributesIE['fontWeight'] = 'font-weight';
Navigation._styleAttributesIE['fontStyle'] = 'font-style';
Navigation._styleAttributesIE['fontFace'] = 'font-face';
Navigation._styleAttributesIE['color'] = 'color';
Navigation._styleAttributesIE['backgroundColor'] = 'background-color';
Navigation._styleAttributesIE['backgroundImage'] = 'background-image';
Navigation._styleAttributesIE['backgroundPosition'] = 'background-position';
Navigation._styleAttributesIE['backgroundRepeat'] = 'background-repeat';
Navigation._styleAttributesIE['zIndex'] = 'z-index'; 


Navigation._getNavigationStructureByNode = function(node, structure, path, countx, containerPrefix) {
  if (arguments.length!=5) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (!node){
    return structure;
  }
  var arr = structure;
  for (var i=0; i<node.childNodes.length; i++){
    var child = node.childNodes[i];
    if (child.nodeType == 1){
      if (child.nodeName.toLowerCase() == 'a'){
        if (path.length){
          path += '-';
        }
        arr[path +''+ countx] = 1;
        var item = NavigationItem.createInstance(containerPrefix + path +''+ countx);
        item.setType('1');
        item.setRoot(path +''+ countx);
        if (Navigation.hasAttributes(child, 'class')){
          var __className__ = Navigation.getAttributesFromElement(child, 'class');
          if (__className__.toString().match(/^rootactive ?/)){
            //__className__ = __className__.toString().replace(/^rootactive ?/,'');
            item.setIsRootActiveElement('yes');
          }
          item.setClassName(__className__);
        }
        if (Navigation.hasAttributes(child, 'style')){
          item.setStyle(Navigation.getAttributesFromElement(child, 'style'));
        }
        if (Navigation.hasAttributes(child, 'href')){
          item.setHref(Navigation.getAttributesFromElement(child, 'href'));
        }
        if (Navigation.hasAttributes(child, 'target')){
          item.setTarget(Navigation.getAttributesFromElement(child, 'target'));
        }
        if (Navigation.hasAttributes(child, 'onclick')){
          item.setOnClick(Navigation.getAttributesFromElement(child, 'onclick'));
        }
        if (Navigation.hasAttributes(child, 'title')){
          item.setTitle(Navigation.getAttributesFromElement(child, 'title'));
        }
        var label = Navigation.getTextNodeValue(child);
        item.setLabel(label);
      }
      if (child.nodeName.toLowerCase() == 'li'){
        countx++;
      }
      if (child.nodeName.toLowerCase() == 'ul'){
        path += countx;
        countx = 0;
        structure[path] = {};
        arr = structure[path];
        var item = NavigationItem.createInstance(containerPrefix + path);
        item.setType('0');
        item.setRoot(path);
        if (Navigation.hasAttributes(child, 'class')){
          var __className__ = Navigation.getAttributesFromElement(child, 'class');
          if (__className__.toString().match(/^rootactive ?/)){
            //__className__ = __className__.toString().replace(/^rootactive ?/,'');
            item.setIsRootActiveElement('yes');
          }
          item.setClassName(__className__);
        }
        if (Navigation.hasAttributes(child, 'style')){
          item.setStyle(Navigation.getAttributesFromElement(child, 'style'));
        }
        var subChild = undefined;
        if(child.previousSibling){
          if (child.previousSibling && child.previousSibling.nodeName.toLowerCase() == 'a'){
            subChild = child.previousSibling;
          } else if (child.previousSibling.previousSibling && child.previousSibling.previousSibling.nodeName.toLowerCase() == 'a'){
            subChild = child.previousSibling.previousSibling;
          }
        }
        if (subChild){
          if (Navigation.hasAttributes(subChild, 'class')){
            item.setSubClassName(Navigation.getAttributesFromElement(subChild, 'class'));
          }
          if (Navigation.hasAttributes(subChild, 'style')){
            item.setSubStyle(Navigation.getAttributesFromElement(subChild, 'style'));
          }
          if (Navigation.hasAttributes(subChild, 'href')){
            item.setHref(Navigation.getAttributesFromElement(subChild, 'href'));
          }
          if (Navigation.hasAttributes(subChild, 'target')){
            item.setTarget(Navigation.getAttributesFromElement(subChild, 'target'));
          }
          if (Navigation.hasAttributes(subChild, 'onclick')){
            item.setOnClick(Navigation.getAttributesFromElement(subChild, 'onclick'));
          }
          if (Navigation.hasAttributes(subChild, 'title')){
            item.setTitle(Navigation.getAttributesFromElement(subChild, 'title'));
          }
          var label = Navigation.getTextNodeValue(subChild);
          item.setLabel(label);
        }
      }
      Navigation._getNavigationStructureByNode(child, arr, path, countx, containerPrefix);
    }
  }
  return structure;
}

Navigation._getNavigationStructuretoString = function(nodeList, str, x) {
  if (arguments.length!=3) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  for (var i in nodeList){
    var count = x;
    while (count > 0){
      str += '. .';
      count--;
    }
    str += i + ' = ' + nodeList[i] + '\n';
    if (typeof nodeList[i] == 'object'){
      str += Navigation._getNavigationStructuretoString(nodeList[i], '', x+1);
    }
  }
  return str;
}


Navigation._getFirstItem = function(obj) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  var count = 0;
  for (var i in obj){
    if (count == 0){
      return obj[i];
    }
  }
  return obj;
}



Navigation.getTextNodeValue = function(node) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  var str = '';
  for (var i=0; i<node.childNodes.length; i++){
    var child = node.childNodes[i];
    if (child.nodeType == 3){
      str += child.nodeValue;
    }
  }  
  return str;
}

Navigation.hasAttributes = function(elem, attrName) {
  var str = '';
  if (document.all){
    if (Navigation._attributesToIE[attrName]){
      attrName = Navigation._attributesToIE[attrName];
    }
    if (attrName == 'className'){
      if (elem.getAttribute('class')){
        attrName = 'class';
      }
    }
  }
  if (elem.getAttribute(attrName)){
    return true;
  }
  return false;
}

Navigation.getAttributesFromElement = function(elem, attrName) {
  var str = '';
  if (document.all){
    str = Navigation._getAttributesFromElementIE(elem, attrName);
  } else {
    str = Navigation._getAttributesFromElementDOM(elem, attrName);
  }
  return str;
}

Navigation._getAttributesFromElementIE = function(elem, attrName) { 
  var str = '';
  if (Navigation._attributesToIE[attrName]){
    var attr = Navigation._attributesToIE[attrName];
    if (attr == 'className'){
      if (elem.getAttribute('class')){
        attr = 'class';
      }
    }
    var attrValue = elem.getAttribute(attr);
    if (attrValue){
      if (typeof attrValue == 'object'){
        for (var a in Navigation._styleAttributesIE){
          if (attrValue[a] && attrValue[a].length){
            str += Navigation._styleAttributesIE[a]+': '+attrValue[a]+'; ';
          }
        }
      } else {
        str += attrValue;
      }
    }
  }
  return str;
}

Navigation._getAttributesFromElementIELoop = function(elem, attrName) { 
  var str = '';
  for (var i in Navigation._attributesIE){
    var attr = i;
    if (attr == 'className'){
      if (elem.getAttribute('class')){
        attr = 'class';
      }
    }
    if (elem.getAttribute(attr)){
      var name = Navigation._attributesIE[i];
      if (name == attrName){
        var attrValue = elem.getAttribute(attr);
        if (attrValue){
          if (typeof attrValue == 'object'){
            for (var a in Navigation._styleAttributesIE){
              if (attrValue[a] && attrValue[a].length){
                str += Navigation._styleAttributesIE[a]+': '+attrValue[a]+'; ';
              }
            }
          } else {
            str += attrValue;
          }
        }
      } 
    }  
  }
  return str;
}

Navigation._getAttributesFromElementDOM = function(elem, attrName) {
  var attributes = elem.attributes;
  var str = '';
  if (attributes.length){
    if (elem.getAttribute(attrName)){
      str += elem.getAttribute(attrName);
    }
  }
  return str;
}


Navigation._getAttributesFromElementDOMLoop = function(elem, attrName) {
  var attributes = elem.attributes;
  var str = '';
  var output = '';
  if (attributes.length){
    for (var i=0; i<attributes.length; i++){
      var attr = attributes.item(i);
      if (attr && attr.value && attr.value.length){
        var name = attr.name;
        if (attrName == name){
          var attrValue = attr.value;
          str += attrValue;
        }  
      }
    }
  }
  return str;
}

Navigation.getInstance = function(id) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (! (Navigation._registerInstance[id])){
    focus();
    throw new Error("Es ist keine Navigation.Instance mit id=" + id + " registriert!");
  } 
  return Navigation._registerInstance[id];
}

Navigation.createInstance = function(id) {
  if (!arguments.length) {
    id = 'navigation' + Navigation._defaultID.length;
    Navigation._defaultID.push(1);
  }
  if (! (Navigation._registerInstance[id])){
    Navigation._registerInstance[id] = new Navigation(id);
  } 
  return Navigation.getInstance(id);
}





function NavigationItem(id) {
  if (arguments.length>1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  this._id = undefined;
  this._rootArr = [];
  this._rootObj = {};
  this._type = undefined;
  this._href = undefined;
  this._label = undefined;
  this._style = undefined;
  this._target = undefined;
  this._onclick = undefined;
  this._className = undefined;
  this._title = undefined;
  this._subStyle = undefined;
  this._subClassName = undefined;
  this._setID(id);
  this._properties = NavigationItemProperties.createNavigationItemProperties(this.id(), this._getParentElement());
  this._isRootActiveElement = undefined;
}

NavigationItem.prototype.toString = function() {
  return "\n[Navigation - id: " + this.id + "]\n";
}


NavigationItem.prototype.id = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._id = str;
  }
  return this._id;
}

NavigationItem.prototype.type = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._type = str;
  }
  return this._type;
}

NavigationItem.prototype.label = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._label = str;
  }
  return this._label;
}

NavigationItem.prototype.href = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._href = str;
  }
  return this._href;
}

NavigationItem.prototype.title = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._title = str;
  }
  return this._title;
}

NavigationItem.prototype.target = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._target = str;
  }
  return this._target;
}

NavigationItem.prototype.onclick = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._onclick = str;
  }
  return this._onclick;
}

NavigationItem.prototype.style = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._style = str;
  }
  return this._style;
}

NavigationItem.prototype.className = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._className = str;
  }
  return this._className;
}

NavigationItem.prototype.subStyle = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._subStyle = str;
  }
  return this._subStyle;
}

NavigationItem.prototype.subClassName = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._subClassName = str;
  }
  return this._subClassName;
}

NavigationItem.prototype.rootArr = function(arr) {
  if (arguments.length) {
    if (typeof arr != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._rootArr = arr;
  }
  return this._rootArr;
}

NavigationItem.prototype.rootObj = function(obj) {
  if (arguments.length) {
    if (typeof obj != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._rootObj = obj;
  }
  return this._rootObj;
}

NavigationItem.prototype.properties = function(obj) {
  if (arguments.length) {
    if (typeof obj != "object") {
      focus();
      throw new Error("Argument ist nicht vom Typ Object!");
    }
    this._properties = obj;
  }
  return this._properties;
}



// -------
// isRootActiveElement
// -------
NavigationItem.prototype.isRootActiveElement = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("Argument ist nicht vom Typ String!");
    }
    this._isRootActiveElement = str;
  }
  return this._isRootActiveElement;
}


NavigationItem.prototype._setID = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.id(str);
}

NavigationItem.prototype._getParentElement = function() {
  var elem = document.getElementById(this.id());
  var parentElem = '';
  if (elem){
    if (document.all){
      parentElem = elem.parentElement.id;
    } else {
      parentElem = elem.parentNode.id;
    }  
  }  
  return parentElem;
}




NavigationItem.prototype.setType = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.type(str);
}

NavigationItem.prototype.setLabel = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.label(str);
}

NavigationItem.prototype.setHref = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.href(str);
}

NavigationItem.prototype.setTitle = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.title(str);
}

NavigationItem.prototype.setTarget = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.target(str);
}

NavigationItem.prototype.setOnClick = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.onclick(str);
}

NavigationItem.prototype.setStyle = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.style(str);
}

NavigationItem.prototype.setClassName = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.className(str);
}

NavigationItem.prototype.setSubStyle = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.subStyle(str);
}

NavigationItem.prototype.setSubClassName = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.subClassName(str);
}

NavigationItem.prototype.setRoot = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  var arr = str.split(/-/);
  var _str = '';
  var rootListArr = [];
  var rootListObj = {};
  for (var i=0; i<arr.length; i++){
    if (i>0){
      _str += '-';
    }
    _str += arr[i];
    rootListObj[_str] = i;
    rootListArr[i] = _str;
  }
  this.rootArr(rootListArr);
  this.rootObj(rootListObj);
}



// -------

// setIsRootActiveElement

// -------

NavigationItem.prototype.setIsRootActiveElement = function(str) {
  if (arguments.length!=1) {
    focus();
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (typeof str != "string") {
    focus();
    throw new Error("Argument ist nicht vom Typ String!");
  }
  this.isRootActiveElement(str);
}


NavigationItem._defaultID = [];

NavigationItem._registerInstance = {};

NavigationItem._isRoot = false;




NavigationItem.getInstance = function(id) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (! (NavigationItem._registerInstance[id])){
    focus();
    throw new Error("Es ist keine NavigationItem.Instance mit id=" + id + " registriert!");
  } 
  return NavigationItem._registerInstance[id];
}

NavigationItem.hasInstance = function(id) {
  if (arguments.length!=1) {
    throw new Error("Falsche Anzahl von Argumenten!");
  }
  if (! (NavigationItem._registerInstance[id])){
    return false;
  } 
  return true;
}

NavigationItem.createInstance = function(id) {
  if (!arguments.length) {
    id = 'navigation' + NavigationItem._defaultID.length;
    NavigationItem._defaultID.push(1);
  }
  if (! (NavigationItem._registerInstance[id])){
    NavigationItem._registerInstance[id] = new NavigationItem(id);
  } 
  return NavigationItem.getInstance(id);
}






function NavigationItemProperties(id, idParentElement) {  
  this._id = undefined;
  this._idParentElement = 'body';
  this.id(id);
  this.idParentElement(idParentElement);
}



NavigationItemProperties.prototype.id = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("ArgumentError:noString!");
    }
    this._id = str;
  }
  return this._id;
}


NavigationItemProperties.prototype.idParentElement = function(str) {
  if (arguments.length) {
    if (typeof str != "string") {
      focus();
      throw new Error("ArgumentError:noString!");
    }  
    this._idParentElement = str.toLowerCase();
  }
  return this._idParentElement;
}



NavigationItemProperties.prototype.getTop = function() {  
  if (this._existsElement(this.id())){
    var parentDiv = document.getElementById(this.id());
    var topPosition = 0;
    if (this._existsElement(this.idParentElement())){
      while (parentDiv && parentDiv.id != this.idParentElement()){
        if (parentDiv.nodeType == 1){
          topPosition += parseFloat(parentDiv.offsetTop);
        }
        parentDiv = parentDiv.offsetParent;
      }
    }
    else{
      while (parentDiv){
        if (parentDiv.nodeType == 1){
          topPosition += parseFloat(parentDiv.offsetTop);
        }
        parentDiv = parentDiv.offsetParent;
      }
    }
    return parseFloat(topPosition);
  }
  return undefined;
}


NavigationItemProperties.prototype.getLeft = function() {  
  if (this._existsElement(this.id())){
    var parentDiv = document.getElementById(this.id());
    var leftPosition = 0;
    if (this._existsElement(this.idParentElement())){
      while (parentDiv && parentDiv.id != this.idParentElement()){
        if (parentDiv.nodeType == 1){
          leftPosition += parseFloat(parentDiv.offsetLeft);
        }
        parentDiv = parentDiv.offsetParent;
      }
    }
    else{
      while (parentDiv){
        if (parentDiv.nodeType == 1){
          leftPosition += parseFloat(parentDiv.offsetLeft);
        }
        parentDiv = parentDiv.offsetParent;
      }
    }
    return parseFloat(leftPosition);
  }
  return undefined;
}


NavigationItemProperties.prototype.getBottom = function() {
  if (this._existsElement(this.id())){
    var bottomPosition = parseFloat(this.getTop() +  this.getHeight());
    return parseFloat(bottomPosition);
  }
  return undefined;
}


NavigationItemProperties.prototype.getRight = function() {  
  if (this._existsElement(this.id())){
    var rightPosition = parseFloat(this.getLeft() + this.getWidth());
    return parseFloat(rightPosition);
  }
  return undefined;
}


NavigationItemProperties.prototype.getWidth = function() {
  if (this._existsElement(this.id())){
    var width = parseFloat(document.getElementById(this.id()).offsetWidth);
    return parseFloat(width);
  }
  return undefined;
}


NavigationItemProperties.prototype.getHeight = function() {
  if (this._existsElement(this.id())){
    var height = parseFloat(document.getElementById(this.id()).offsetHeight);
    return parseFloat(height);
  }
  return undefined;
}


NavigationItemProperties.prototype._existsElement = function(id) {
  if (document.getElementById(id) != undefined){
    return true;
  }
  return false;
}



NavigationItemProperties.createNavigationItemProperties = function(id, idParentElement) { 
  return new NavigationItemProperties(id, idParentElement);
}


NavigationItemProperties.prototype.toString = function() {
  return Object.prototype.toString.apply(this);
}



function NavigationTools() {
}


NavigationTools.checkNumber = function(n){
  if (!arguments.length){
    return false;
  }
  if (n == undefined){
    return false;
  }
  n = n.toString();
  if (n == '0'){
    return n;
  }
  if (!n.length){
    return false;
  }
  n = n.replace(/,/g,'.');
  if (isNaN(n)){
    return false;
  }
  if (!isFinite(n)) {
    return false;
  }
  n = parseFloat(n);
  return n;
}


NavigationTools.checkWertInArrayVorhanden = function(){
  var str = arguments[0];
  var arr = new Array();
  arr = arguments[1];
  for (var i in arr){
    if (arr[i] == str){
      return true;
    } 
  }
  return false;
}



NavigationTools.prototype.toString = function() {
  return Object.prototype.toString.apply(this);
}



