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";
}

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, id, OffsX, OffsY)
{
  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.yogaschule-mannheim.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);
}

/**
 * Process response.
 */
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 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 (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+"',8,4);");
        a.onmouseout = Function("startclose();");
        a.onfocus = Function("stopclose(); closeAllByClassName('"+("Sub"+cn).toLowerCase()+"'); expandIt('el"+sec_id+("Sub"+cn)+"','"+id+'/'+sec_id+"',8,4);");
        a.onblur= Function("startclose();");
        var img = document.createElement( "img");
        img.setAttribute( "name", "POSER_"+sec_id);
        img.setAttribute( "src", "http://www.yogaschule-mannheim.de/common/common/icon_menu_arrow.gif");
        img.setAttribute( "alt", "");
        a.appendChild( img);
        divNavArr.appendChild( a);
        divMenuDD.appendChild( divNavArr);
      }
    }
    div.appendChild( divMenuDD);
    document.getElementsByTagName('body')[0].appendChild( div);
    _expandIt(el, id);
  }
}

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


