// AUTHOR: Christoph Rasulis, Tim Zylinski, Genevieve Cory
// ABSTRACT: macht die Kontext-Navigation der HSS

var gtmp = "";
var oAktivNP

document.write('<link rel="stylesheet" href="_styles/da_kontext_navigation.css" type="text/css">');

    
    // Funktion: NP
    // Aufgabe: Diese Funktion ist die "Klasse" NavigationsPunkt.
    
    function NP(level,idname,url,title,target,pictureOn,pictureOff,pictureheader,parentNP,objReferenz)
    {
        this.level = level;
        this.url = url;
        this.title = title;
        if (!target)
            this.target = '_top';
        else
            this.target = target;
        this.pictureOn = new Image();
        this.pictureOn.src = pictureOn;
        this.pictureOff = new Image();
        this.pictureOff.src = pictureOff;
        this.pictureheader = new Image();
        this.pictureheader.src = pictureheader;
        this.UP = new Array();
        this.parentNP = parentNP;
        this.i = 0;
        this.idname = idname;
        this.aktiv = '';
        this.objReferenz = objReferenz;
    }
    
    // Funktion: addNav
    // Aufgabe: ?
    
    function addNav(level,idname,url,title,target,pictureOn,pictureOff,pictureheader)
    {
        sTmp = "oTreeRoot"
        for(i=0;i<level;i++)
        {
            sTmp2 = sTmp+'.UP'
            if (level != i+1)
            {
                nTmpNumber = eval(sTmp2+'.length')-1
            }
            else
            {
                nTmpNumber = eval(sTmp2+'.length')
                nTmpParent = eval(sTmp)
            }
            sTmp += '.UP['+nTmpNumber+']'
        }
        eval(sTmp + ' = new NP(level,idname,url,title,target,pictureOn,pictureOff,pictureheader,nTmpParent,"'+sTmp+'")')
    }
    

    
    // Funktion: setAktiv
    // Aufgabe: ?
    
    function setAktiv(oTmp4Aktiv,aktividname)
    {
        if (oTmp4Aktiv.idname == aktividname)
        {
            oAktivNP = oTmp4Aktiv
            oTmp4Aktiv.aktiv = 'aktiv'
            while(oAktivNP.parentNP)
            {
                oAktivNP = oAktivNP.parentNP
                oAktivNP.aktiv = 'aktiv_parent'
            }
            oAktivNP = oTmp4Aktiv
            //break;
        }
        if (oAktivNP)
        {
            if (getParentObject(oTmp4Aktiv,oAktivNP.level) == oAktivNP && oTmp4Aktiv != oAktivNP)
            {
                oTmp4Aktiv.aktiv = 'aktiv_child'
            }
        }
        
        for (oTmp4Aktiv.i=0;oTmp4Aktiv.i<oTmp4Aktiv.UP.length;oTmp4Aktiv.i++)
        {
            setAktiv(oTmp4Aktiv.UP[oTmp4Aktiv.i],aktividname)
        }
    }

	function setAktivAll(oTmp4Aktiv)
	{
			aktividname = '0'
	        oAktivNP = oTmp4Aktiv
            oTmp4Aktiv.aktiv = 'aktiv'
            while(oAktivNP.parentNP)
            {
                oAktivNP = oAktivNP.parentNP
                oAktivNP.aktiv = 'aktiv_parent'
            }
            oAktivNP = oTmp4Aktiv
            //break;
        if (oAktivNP)
        {
            if (getParentObject(oTmp4Aktiv,oAktivNP.level) == oAktivNP && oTmp4Aktiv != oAktivNP)
            {
                oTmp4Aktiv.aktiv = 'aktiv_child'
            }
        }
        
        for (oTmp4Aktiv.i=0;oTmp4Aktiv.i<oTmp4Aktiv.UP.length;oTmp4Aktiv.i++)
        {
            setAktiv(oTmp4Aktiv.UP[oTmp4Aktiv.i],aktividname)
        }
	}
    
    // Funktion: getParentObject
    // Aufgabe:  ?
   
    function getParentObject(oParentObject,tmplevel)
    {
        while(oParentObject.level != tmplevel)
        {
            if (!oParentObject.parentNP)
            {
                break;
            }
            oParentObject = oParentObject.parentNP
        }
        return oParentObject
    }

    
    // Funktion: clearAktiv
    // Aufgabe: ?
    
    function clearAktiv(oTmpRoot)
    {
        oAktivNP.aktiv = ''
        while(oAktivNP.parentNP)
        {
            oAktivNP = oAktivNP.parentNP
            oAktivNP.aktiv = ''
        }
    }

    
    // Funktion: inittree
    // Aufgabe: ?
    
    function inittree(oTmpRoot,aktividname)
    {
		if(aktividname == 'sitemap') {
			setAktivAll(oTmpRoot);
		}
		else {
        	setAktiv(oTmpRoot,aktividname)
        }
		for (oTmpRoot.i=0;oTmpRoot.i<oTmpRoot.UP.length;oTmpRoot.i++)
        {
            //  setIdName(oTmpRoot.UP[oTmpRoot.i])
            
            if (oTmpRoot.UP[oTmpRoot.i].UP.length > 0)
            {
                inittree(oTmpRoot.UP[oTmpRoot.i],aktividname)
            }
        }
    }

    
    // Funktion: cutURL
    // Aufgabe: ?
    
    function cutUrl(tmpUrl)
    {
        tmpcutUrl = tmpUrl
        if (tmpcutUrl.indexOf("//") != -1)
            tmpcutUrl = tmpcutUrl.substr(tmpcutUrl.indexOf("/",tmpcutUrl.indexOf("//")+2)+1,tmpcutUrl.length)
        else
            tmpcutUrl = tmpcutUrl.substr(tmpcutUrl.indexOf('')+1,tmpcutUrl.length)
            
            tmpcutUrl = tmpcutUrl.substr(0,tmpcutUrl.lastIndexOf('/'))
            
            return tmpcutUrl
    }
    
    // Funktion: schreibNavLevel1
    // Aufgabe: schreibt Navigationsbaum
    
    function schreibNavLevel1(oTmpRoot)
    {
		// Jede Menüzeile besteht aus einem TR. Bild immer vorhanden, also TR Anfang hier

		var gLevel_first = '<div class="first">\n'; //for the blue Linkgroup
		var gLevel_second = '</div>\n<div class="second">\n'; //for the green Linkgroup
		var gLevel_third = '</div>\n<div class="third">\n';//for the gray Linkgroup

		var gLevel_00 = ''; // only for when you don't want the homepage to show
		var gLevel_01 = 		''; //01
		var gLevel_01_line = 	'';
		var gLevel_02_a = '';
		var gLevel_02_p = '';
		var gLevel_02_line_a = '';
		var gLevel_02_line_p = '';
		var gLevel_03 = '';
		var gLevel_03_last = '';
			
		var tmp = "";
		
        var tmptitle = "";
		var urlstring = "";
		var urlstring2 = "";

//		if (ReddotAnsicht)
//		{
//			tmptitle = 'title="Ebene:'+oTmpRoot.level+';Seite:'+oTmpRoot.url+';IDName:'+oTmpRoot.idname+'"';
//		}
		urlstring = oTmpRoot.url+'" '+tmptitle+' target="'+oTmpRoot.target+'">'+oTmpRoot.title+'</a>\n';
		urlstring2 = oTmpRoot.url+'" '+tmptitle+' target="'+oTmpRoot.target+'">'+oTmpRoot.title+'</a>\n';

		switch(oTmpRoot.level)
		{

			// Für Abstand zw. den Arrays

			// Für Root-/Homepageknoten
			case(0): 
			
			// Wenn Homepage nicht angezeigt werden soll
			if(oTmpRoot.title == 'nichts')
			{
			tmp += gLevel_00;
			}
			// sonst
			else
			{
				tmp += gLevel_01;
				// Auf der Homepage
				if(oTmpRoot.aktiv == 'aktiv')
				{
					tmp += '<a class="navfirstselected" href="'+urlstring;
				}
				// sonst
				else
				{
					tmp += '<a class="navfirst" href="'+urlstring;
				}
			}
			break;
			
			// Knoten des Level 1
			case(1):
		
			// Wenn Menüpunkt Level 1 oder Children davon ausgewählt andere Grafik anzeigen
				if((oTmpRoot.UP.length > 0) && (oTmpRoot.aktiv == 'aktiv') || (oTmpRoot.aktiv == 'aktiv_parent'))
				{
					tmp += gLevel_01_line;
				}
				else
				{
					tmp += gLevel_01;
				}
			
			
			// Auf einem Knoten des Level1
			if(oTmpRoot.aktiv == 'aktiv')
			{
				tmp += '<a class="navfirstselected" href="'+urlstring;
			}
			// sonst
			else
			{
				tmp += '<a class="navfirst" href="'+urlstring;
			}

			//wenn Abstand gemacht werden soll und kein eigentlicher Navipunkt erscheinen soll:

				switch(oTmpRoot.title) 
				{
				case "first":
					tmp = gLevel_first;
				break;
				case "second":
					tmp = gLevel_second;
				break;
				case "third":
					tmp = gLevel_third;
				break;

				}
			
			break;
			
			// Knoten des Level 2
			case(2):
			
			var helper = oTmpRoot.parentNP.UP[oTmpRoot.parentNP.UP.length-1].title;
			
			// Knoten Level 1 ausgewählt, daher nur passive Childknoten anzeigen
			if((oTmpRoot.parentNP.aktiv == 'aktiv') && (oTmpRoot.aktiv == 'aktiv_child'))
			{
				// Wenn Knoten letzter von Children der gleichen Ebene andere Grafik anzeigen
				if(helper == oTmpRoot.title)
				{
					tmp += gLevel_02_line_p;
				}
				else
				{
					tmp += gLevel_02_p;
				}
				tmp += '<a class="navsecond" href="'+urlstring;
			}
			
			// Knoten Level 2 ausgewählt und aktiv
			if((oTmpRoot.parentNP.aktiv == 'aktiv_parent') && (oTmpRoot.aktiv == 'aktiv'))
			{
				// Wenn Knoten letzter von Children der gleichen Ebene andere Grafik anzeigen
				if(helper == oTmpRoot.title)
				{
					tmp += gLevel_02_line_a;
				}
				else
				{
					tmp += gLevel_02_a;
				}
				tmp += '<a class="navsecondselected" href="'+urlstring;
			}
			
			// Knoten Level 2 ausgewählt aber nicht aktiv
			if((oTmpRoot.parentNP.aktiv == 'aktiv_parent') && (oTmpRoot.aktiv != 'aktiv'))
			{
				// Wenn Knoten letzter von Children der gleichen Ebene andere Grafik anzeigen
				if(helper == oTmpRoot.title)
				{
					tmp += gLevel_02_line_p;
				}
				else
				{
					tmp += gLevel_02_p;
				}
				tmp += '<a class="navsecond" href="'+urlstring;
			}
			break;
			
			// Knoten des Level 3
			case(3):
			
			var NPup = oTmpRoot.parentNP;
			helper3 = NPup.parentNP.UP[NPup.parentNP.UP.length-1].title;
			
			// Knoten Level 2 ausgewählt, daher nur passive Childknoten anzeigen
			if((oTmpRoot.parentNP.aktiv == 'aktiv') && (oTmpRoot.aktiv == 'aktiv_child'))
			{
				if(helper3 == oTmpRoot.parentNP.title)
				{
					tmp += gLevel_03_last;
				}
				else
				{
					tmp += gLevel_03;
				}
			
				tmp += '<a class="navthird" href="'+urlstring2;
			}
			
			// Knoten Level 3 ausgewählt und aktiv
			if((oTmpRoot.parentNP.aktiv == 'aktiv_parent') && (oTmpRoot.aktiv == 'aktiv'))
			{
				if(helper3 == oTmpRoot.parentNP.title)
				{
					tmp += gLevel_03_last;
				}
				else
				{
					tmp += gLevel_03;
				}
				tmp += '<a class="navthirdselected" href="'+urlstring2;
			}
			
			// Knoten Level 3 ausgewählt aber nicht aktiv
			if((oTmpRoot.parentNP.aktiv == 'aktiv_parent') && (oTmpRoot.aktiv != 'aktiv'))
			{
				if(helper3 == oTmpRoot.parentNP.title)
				{
					tmp += gLevel_03_last;
				}
				else
				{
					tmp += gLevel_03;
				}
				tmp += '<a class="navthird" href="'+urlstring2;
			}
			break;
			
			// Sonst
			default: break;
		}
		
		
					
			// makes the end of each line of code

			switch(oTmpRoot.title){
			
					
			case "Konferenzzentrum M&uuml;nchen": //here -- the last linktext in the navigation to close the last div.  VERY IMPORTANT!
			tmp += '</div>\n';
			break;
						
			default:
 			tmp += '\n';
			break;
			}
      
        gtmp += tmp; //necessary for sitemap_ausschreiben.htm to write out the static sitemap


        document.write(tmp);
        for (oTmpRoot.i=0;oTmpRoot.i<oTmpRoot.UP.length;oTmpRoot.i++)
        {
            schreibNavLevel1(oTmpRoot.UP[oTmpRoot.i])
        }
      
    }
	     
	//Ende des Scripts
   