function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('(^| )'+classname+'( |$)');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function setMouseOvers(obj) {
	for (i=0; i<obj.getElementsByTagName("LI").length; i++) {
		node = obj.getElementsByTagName("LI")[i];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {
        obj = document.getElementById("nav");
        col = obj.getElementsByTagName("LI");
        for (i=0; i<col.length; i++) {
          col[i].className = col[i].className.replace(" over", "");
        }
        
        col = getElementsByClassName(document, '');
        col = getElementsByClassName(document, 'subnav');
        for(j=0;j<col.length; j++) {
          if (col[j].tagName == "DIV") {
            col[j].className = col[j].className.replace(" over", "");
          }
        }        
        col = getElementsByClassName(document, this.className.replace(" over", ""));
        
        for(j=0;j<col.length; j++) {
          if (col[j].tagName == "DIV") {
            col[j].className += " over";
          }
        }
        this.className += " over";
			}

			node.onmouseout=function() {
                if (this.className.indexOf('none') >= 0) {
                    this.className = this.className.replace(" over", "");
                }
        /*
        col = getElementsByClassName(document, this.className.replace(" over", ""));
        for(j=0;j<col.length; j++) {
          if (col[j].tagName == "DIV") {
            col[j].className = col[j].className.replace(" over", "");
          }
        }      
        */
			}
		}
	}
}
function setSubMouseOvers(obj) {
	for (i=0; i<obj.getElementsByTagName("LI").length; i++) {
		node = obj.getElementsByTagName("LI")[i];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {
        this.className += " over";
      }
			node.onmouseout=function() {
        this.className = this.className.replace("over", "");
			}
    }
  }
}

function setCurrentSubnav() {    
    thisPage = location.href;
    if (thisPage.indexOf('mortgageplans.MyMortgageCommunity.com', 0) > 0) {
        planNav = getElementsByClassName(document, 'plan');    
        for(j=0;j<planNav.length; j++) {
            if (node.nodeName=="LI") {
                //planNav[j].className += " over";
            }
        }      
    }
}

startList = function() {
  navRoot = document.getElementById("nav");
  setMouseOvers(navRoot);	
  
  subNavRoot = document.getElementById("subnav");
  setSubMouseOvers(subNavRoot);

  setCurrentSubnav();
}
window.onload=startList;