﻿    var http_request = false;
 	var menueobj;
 	var divobj = new Array();
	var subNode = new Array();	
	var mapCount=0;	
	var subentries = 4;
	var strNoWords = "";
	
    function Map(ind) {
 		mapCount=ind;
	 	subentries = 8;
 		menueobj = document.getElementById("menue");
	 	clearChilds(menueobj);
 		divobj[ind] = menueobj;
 
		switch (ind) {
		  case 0:
			macheRequest('http://www.elsenaju.de/elsenaju.xml');
		    break;
		  case 1:
			macheRequest('http://www.elsenaju.de/wiki.xml');
		    break;
		  case 2:
			macheRequest('http://www.elsenaju.de/magazine.xml');
		    break;
		  case 3:
			macheRequest('http://www.elsenaju.de/internet.xml');
		    break;
		  case 4:
			macheRequest('http://www.elsenaju.de/Woerterbuecher.xml');
		    break;
		  case 5:
			macheRequest('http://www.elsenaju.de/dmoz.xml');
		    break;
		  case 6:
			macheRequest('http://www.elsenaju.de/yahoo.xml');
		    break;
		  case 7:
			macheRequest('http://www.elsenaju.de/noWords.xml');
		    break;
		  default:
		    break;
		}
	}

    function singleMap(ind) {
	 	clearChilds(divobj[ind]);
		neueEbene(divobj[ind], subNode[ind], 3, ind);
	}
	
    function macheRequest(url) {
        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
            return false;
        }
        http_request.onreadystatechange = alertInhalt;
        http_request.open('GET', url, true);
        http_request.send(null);

    }

    function alertInhalt() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				var xmldoc = http_request.responseXML;
				if (mapCount==7) {
					setNoWords(xmldoc.getElementsByTagName('root')[0]);
				} else {
					subNode[mapCount] = xmldoc.getElementsByTagName('root')[0];
					neueEbene(divobj[mapCount], subNode[mapCount], 3, mapCount);
				}
            } else {
                alert('Bei dem Request ist ein Problem aufgetreten.');
            }
        }
    }
    
     function setNoWords(node) {
		var i=0;
		strNoWords = "\\b";
		for(i = 0; i < node.getElementsByTagName('a0').length-1; i++)
        {
			strNoWords += node.getElementsByTagName('a0')[i].attributes[0].firstChild.nodeValue + "\\b|\\b";
		}
		strNoWords += node.getElementsByTagName('a0')[node.getElementsByTagName('a0').length-1].attributes[0].firstChild.nodeValue + "\\b";
	 }
	
     function neueEbene(obj, node, ebene, ind) {

		for(var i = 0; i < node.getElementsByTagName('a0').length; i++)
        {			
			a0= node.getElementsByTagName('a0')[i];

			var myText = document.createTextNode(a0.attributes[1].firstChild.nodeValue);
			var elp = document.createElement("h3");
			elp.appendChild(myText);
			obj.appendChild(elp);

			for(var j = 0; j < a0.getElementsByTagName('a1').length; j++)
	        {
				a1= a0.getElementsByTagName('a1')[j];
				var obj1= insertDiv(obj, 4, i, j, ind);
				myText = document.createTextNode(a1.attributes[1].firstChild.nodeValue);
				elp = document.createElement("p");
				elp.className = "index";
				insertWElement(elp, a1.attributes, 1, 2);
				obj1.appendChild(elp);
				var elp1 = document.createElement("p");
				elp1.className = "index1";
				for(var k = 0; k < a1.getElementsByTagName('a2').length; k++)
		        {
					insertWElement(elp1, a1.getElementsByTagName('a2')[k].attributes, 1.3, 3);
		        }
				obj1.appendChild(elp1);
		    }
			obj.appendChild(obj1);
		}
    }

	function clearChilds(obj) {
	 	while (obj.hasChildNodes()) {
	 		obj.removeChild(obj.firstChild)};
	}
	
	function insertDiv(Ziel, width, i, j, ind) {
		var div = document.createElement( 'div' );
			div.className = "element";
		Ziel.appendChild( div );
		return div;
	}

	function insertWElement(Ziel, element, fontSize, ebene) {
		var newA = document.createElement("a");
		var newText = document.createTextNode(element[1].firstChild.nodeValue + " ");
		newA.appendChild(newText);
		Ziel.appendChild(newA);
		newA.href = element[0].firstChild.nodeValue;
		newA.target= "_blank";
	}
	
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	}
	
  function empty() {
	document.getElementById("menue").innerHTML= "";
	if (document.getElementById("menueL")) {document.getElementById("menueL").innerHTML= ""};
	document.getElementById("searchResults").innerHTML= "";}

  function initKopf() {
	document.getElementById("menuekopf").innerHTML= "<div style=\"float:left;margin-left:5px\" onclick=\"Map(0)\"><p class=\"tabp\" onmouseover=\"this.style.color='fuchsia'\" onmouseout=\"this.style.color='#CC0066'\">elsenaju</p></div><div style=\"float:left;margin-left:5px\" onclick=\"Map(1)\"><p class=\"tabp\" onmouseover=\"this.style.color='fuchsia'\" onmouseout=\"this.style.color='#CC0066'\">Wikipedia</p></div><div style=\"float:left;margin-left:5px\" onclick=\"Map(2)\"><p class=\"tabp\" onmouseover=\"this.style.color='fuchsia'\" onmouseout=\"this.style.color='#CC0066'\">Nachrichten</p></div><div style=\"float:left;margin-left:5px\" onclick=\"Map(3)\"><p class=\"tabp\" onmouseover=\"this.style.color='fuchsia'\" onmouseout=\"this.style.color='#CC0066'\">Web-Suche</p></div><div style=\"float:left;margin-left:5px\" onclick=\"Map(4)\"><p class=\"tabp\" onmouseover=\"this.style.color='fuchsia'\" onmouseout=\"this.style.color='#CC0066'\">Wörterbücher</p></div><div style=\"float:left;margin-left:5px\" onclick=\"Map(5)\"><p class=\"tabp\" onmouseover=\"this.style.color='fuchsia'\" onmouseout=\"this.style.color='#CC0066'\">dmoz</p></div><div style=\"float:left;margin-left:5px\" onclick=\"Map(6)\"><p class=\"tabp\" onmouseover=\"this.style.color='fuchsia'\" onmouseout=\"this.style.color='#CC0066'\">yahoo</p></div><div style=\"float:right;margin-left:5px\" onclick=\"empty()\"><p class=\"tabp\" onmouseover=\"this.style.color='fuchsia'\" onmouseout=\"this.style.color='#CC0066'\">clear</p></div>";
	Map(7);
	}
