
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 coords;
	coords = {x: 0, y: 0};
	var element = document.images['POSER_'+id];
	while (element) {
		coords.x += element.offsetLeft;
		coords.y += element.offsetTop;
		element = element.offsetParent;
	}
	if (coords){
		var poserX = coords['x'];
		var poserY = coords['y'];
	}
	var MouseX=(poserX+1);
	var MouseY=(poserY+1);
	var whichEl = document.getElementById(el);
	whichEl.style.top = MouseY+"px";
	whichEl.style.left = MouseX+"px";
	whichEl.style.display = "block";
	whichEl.style.visibility = "visible";
	var MainNav = document.getElementById('MainNav');
        if ( MainNav) {
	  if (MouseX+parseInt(whichEl.offsetWidth)>MainNav.offsetWidth) {
	    whichEl.style.left = (MainNav.offsetWidth-parseInt(whichEl.offsetWidth)-parseInt(document.images['POSER_'+id].offsetWidth))+"px";
          }
	}
}

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

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

function setPointer(theRow, thePointerColor){
    theRow.style.backgroundColor = thePointerColor;
    return true;
} 

/**
 *
 */
function expandIt(el, path, id, OffsX, OffsY)
{
  var whichEl = document.getElementById(el);
  if (whichEl) {
    _expandIt(el, id);
  }
  else {
    setxmlMenu(path, id);
  }
}

function setxmlMenu(path, id)
{
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  document.getElementsByTagName('body')[0].style.cursor = "wait";
  var url = "http://www.vtb-bayern.de/content/"+path+"/ajaxGetChildNodesNav.xml";
  req.open("GET",url,true);
  req.onreadystatechange = processResponseMenu;
  req.send(null);
}

/**
 * Process response.
 */
function processResponseMenu() 
{
  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 div = document.createElement( "div");
    div.setAttribute( "id", el);
    div.setAttribute( "class", cn.toLowerCase());
    div.setAttribute( "className", cn.toLowerCase());
    var divMenuDD = document.createElement( "div");
    divMenuDD.setAttribute( "class", "menuDropdown");
    divMenuDD.setAttribute( "className", "menuDropdown");
    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 divNavDD = document.createElement( "div");
      divNavDD.setAttribute( "class", "navDropdown");
      divNavDD.setAttribute( "className", "navDropdown");
      divNavDD.onmouseover = Function("stopclose(); closeAllByClassName('"+("Sub"+cn).toLowerCase()+"');");
      divNavDD.onmouseout = Function("startclose();");
      divNavDD.onfocus = Function("stopclose(); closeAllByClassName('"+("Sub"+cn).toLowerCase()+"');");
      divNavDD.onblur = Function("startclose();");
      var a = document.createElement( "a");
      a.setAttribute( "href", page.getAttribute("index_html"));
      a.appendChild( document.createTextNode( page.getAttribute("titlealt")));
      divNavDD.appendChild( a)
      divMenuDD.appendChild( divNavDD);
      if (cn.indexOf("Sub")<0 && page_has_children) {
        var sec_id = page_id.substring( page_id.indexOf("_")+1);
        var divNavArr = document.createElement( "div");
        divNavArr.setAttribute( "class", "navArrow");
        divNavArr.setAttribute( "className", "navArrow");
        var a = document.createElement( "a");
        a.setAttribute( "href", page.getAttribute("index_html"));
        a.onmouseover = Function("stopclose(); closeAllByClassName('"+("Sub"+cn).toLowerCase()+"'); expandIt('el"+sec_id+("Sub"+cn)+"','"+id+'/'+sec_id+"','"+sec_id+"',8,4);");
        a.onmouseout = Function("startclose();");
        a.onfocus = Function("stopclose(); closeAllByClassName('"+("Sub"+cn).toLowerCase()+"'); expandIt('el"+sec_id+("Sub"+cn)+"','"+id+'/'+sec_id+"','"+sec_id+"',8,4);");
        a.onblur= Function("startclose();");
        
        divNavArr.appendChild( a);
        divMenuDD.appendChild( divNavArr);
      }
    }
    div.appendChild( divMenuDD);
    document.getElementsByTagName('body')[0].appendChild( div);
    _expandIt(el, id);
    document.getElementsByTagName('body')[0].style.cursor = "auto";
  }
}

function setPointer(theRow, thePointerColor){
    theRow.style.backgroundColor = thePointerColor;
    return true;
} 
