getPageCoordinates = function() {
  var tags = document.getElementsByTagName("meta");
  for (var i=0; i < tags.length; i++) {
      if (tags[i].name == "page-coordinates") {
        var coord = tags[i].content;
        var coord1 = coord.match(/\b(\d{1,2})/);
        var coord2 = coord.match(/-(\d{1,2})/);
        var coord3 = coord.match(/-(\d{1,2})-(\d{1,2})/);
        
        if ( coord1 !== null && coord2 !== null) {
            var homeRow1Coord = coord1[1];
            var homeRow2Coord = coord2[1];
            break;
        }
        else {
        return;
        }
      }
  }
  var homeRow1 = document.getElementById("menu-row-1-tab-" + homeRow1Coord );
  if (homeRow1 !== null) {
    homeRow1.className = "row1hovering";
    var homeRow1UL = homeRow1.getElementsByTagName("UL")[0];
    if (homeRow1UL !== null) {
        homeRow1UL.id = "home-row1";
    }
      
    if (homeRow2Coord > 0){
      var row2LIs = homeRow1.getElementsByTagName("LI");
      if ( row2LIs.length >= homeRow2Coord-1) {
        var homeRow2 = row2LIs[homeRow2Coord-1] ;
        homeRow2.id = "home-row2" ;
        homeRow2.className = "row2hovering" ;
      }
    }
  }
}

setHoveringMethods = function() {
  
  var LIs = document.getElementById("menu").getElementsByTagName("LI");
  for (var i=0; i < LIs.length; i++) {
    if ( LIs[i].className.match(/\brow1\b/)) {
        
        LIs[i].onmouseover=function() {
          this.className = "row1hovering";
          if ( this.getElementsByTagName("UL").length > 0 ) {
            var row1UL = this.getElementsByTagName("UL")[0];
            if ( row1UL.id !== "home-row1") {
                var homeRow1UL = document.getElementById("home-row1");
                var homeRow1 = homeRow1UL.parentNode;
                homeRow1.className = "row1" ;
            }
          }
        }
    
        LIs[i].onmouseout=function() {
          this.className = "row1" ;
          if ( this.getElementsByTagName("UL").length > 0 ) {
              var row1UL = this.getElementsByTagName("UL")[0];
              if ( row1UL.id !== "home-row1") {
                  var homeRow1UL = document.getElementById("home-row1");
                  var homeRow1 = homeRow1UL.parentNode;
                  homeRow1.className = "row1hovering";
              }
          }
        }
    }
    
    else if ( LIs[i].className.match(/\brow2\b/)) {
        
        LIs[i].onmouseover=function() {
          this.className = "row2hovering";
          if ( this.id !== "home-row2") {
            homeRow2 = document.getElementById("home-row2");
            homeRow2.className = "row2" ;
          }
        }
    
        LIs[i].onmouseout=function() {
          this.className= "row2";
           if ( this.id !== "home-row2") {
            homeRow2 = document.getElementById("home-row2");
            homeRow2.className = "row2hovering";
          }
        }
    }
  }
}



startupLoad = function() {
  getPageCoordinates();
  setHoveringMethods();
}

