
function initIt(){
	tempColl = document.getElementsByTagName("a");
	for (i=0;i<tempColl.length; i++) {
		tempColl[i].addEventListener("mouseover", mousePos, true);
	}
}

function mousePos(Ereignis){
	MouseX = Ereignis.pageX;
	MouseY = Ereignis.pageY;
}

var active;
function startclose(){
     active = window.setTimeout("closeAll()",1000);
}
function stopclose(){
     if(active){
		window.clearTimeout(active);
	}
}
function _expandIt(el, id) {
	var whichEl = document.getElementById(el);
	whichEl.style.display = "block";
	whichEl.style.visibility = "visible";
}

function closeAll(){
  closeAllByClassName("child");
  closeAllByClassName("subchild");
}

function closeAllByClassName(name){
	stopclose();
	tempColl = document.getElementsByTagName("ul");
	for (i=0; i<tempColl.length; i++) {
		whichEl = tempColl[i];
		if (whichEl.className == name) {
                         whichEl.style.display = "none";
                         whichEl.style.visibility = "hidden";
                       }
	}
}

function expandIt(el, id)
{
  var path = id;
  var i = id.lastIndexOf( '/');
  if ( i >= 0) {
    id = id.substr( i+1);
  }
  var whichEl = document.getElementById(el);
  if (whichEl) {
    _expandIt(el, id);
  }
  else {
    setxml(path, id);
  }
}

function setxml(path, id)
{
  document.getElementsByTagName('body')[0].style.cursor = "wait";
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  var url = "http://www.mba-usa.de/"+path+"/ajaxGetChildNodes?id="+id+"&meta_types:int=0&lang=ger&manage_lang=ger";
  req.open("GET",url,true);
  req.onreadystatechange = processResponse;
  req.send(null);
}

function processResponse() 
{
  if (req.readyState == 4 && req.status == 200) 
  {
    document.getElementsByTagName('body')[0].style.cursor = "auto";
    var id = req.responseXML.getElementsByTagName('pages')[0].getAttribute('id');
    var level = parseInt(req.responseXML.getElementsByTagName('pages')[0].getAttribute('level'));
    var cn = "Child";
    for (var i = 1; i < level; i++) {
      cn = "Sub" + cn;
    }
    var el = "el"+id+cn;
    var ul = document.createElement( "ul");
    ul.setAttribute( "id", el);
    ul.setAttribute( "class", cn.toLowerCase());
    ul.setAttribute( "className", cn.toLowerCase());
    var pages = req.responseXML.getElementsByTagName('page');
    for (var i = 0; i < pages.length; i++) {
      var page = pages[i];
      var page_id = page.getAttribute("id");
      var page_has_children = page.getAttribute("has_children")=="True";
      var page_active = page.getAttribute("active")=="True";

      if (page_active) {

      var li = document.createElement( "li");
      li.setAttribute( "id", page_id.substring( page_id.indexOf("_")+1));
      li.setAttribute( "class", "navDropdown");
      li.setAttribute( "className", "navDropdown");
      var a = document.createElement( "a");
      a.setAttribute( "href", page.getAttribute("index_html"));
      a.appendChild( document.createTextNode( page.getAttribute("titlealt")));
      if (page_has_children) {
        a.setAttribute( "class", "drop");
        var sec_id = page_id.substring( page_id.indexOf("_")+1);
        a.onmouseover = Function("stopclose(); closeAllByClassName('"+("Sub"+cn).toLowerCase()+"'); expandIt('el"+sec_id+("Sub"+cn)+"','"+id+'/'+sec_id+"');");
        a.onmouseout = Function("startclose();");
        a.onfocus = Function("stopclose(); closeAllByClassName('"+("Sub"+cn).toLowerCase()+"'); expandIt('el"+sec_id+("Sub"+cn)+"','"+id+'/'+sec_id+"');");
        a.onblur = Function("startclose();");
        }
      else {
        a.onmouseover = Function("stopclose(); closeAllByClassName('"+("Sub"+cn).toLowerCase()+"');");
        a.onmouseout = Function("startclose();");
        a.onfocus = Function("stopclose(); closeAllByClassName('"+("Sub"+cn).toLowerCase()+"');");
        a.onblur = Function("startclose();");
      }
      li.appendChild( a);
      ul.appendChild( li);
      }
    }
    document.getElementById(id).appendChild(ul);
    _expandIt(el, id);
  }
}


