<!--
/******************************************************************************
* this script generates and animates the navigation tree, following this order:
* 1.) NavMenuItem(...)  --> called from navigation.html for each item: instantiates a new data object for each item
* 2.) initNavigation()  --> set init parameters for the navigation
* 3.) printNavigation() --> write layers to navigation frame: uses resetLoop(), printTips(), printItems()
* 4.) clickItem(), refreshNavigation(), collapseAll(), collapse(), mouseOver(), mouseOut() --> methods called during animation
*******************************************************************************
*/

/**********************************************************************
* Global parameters
***********************************************************************/
    var design = null;//getURLParameter("design");
    var levels = 0;                          // holds the number of hierarchy levels of the tree. It is calculated in countLevels() at the beginning
    var count = 0;                           // numbers all items continously without regarding their hierarchie
    var startpos = 0;                       // top position of first visible item
    var pos = startpos;                      // top position of an item in px
    var step = 0;                            // height of one an item in px0
        if (UTILS.nav47) step = 25;
        else if (UTILS.nav5up) step = 20;
        else step = 20;
    var leftWidth = 20;
    var navmenu = new Object();              // top level container for for all items
    navmenu.items = new Array();             // the first level of the navigation which is always visible
    var clickedItem = new Object();          // holds the name and the original backgroundColor of the visualization layer of the latest clicked Item
    var Icons = new Object()                 // holds image objects for animated icons
    var background_active = new Image();     // holds the background image used to highlight an active item
    background_active.src = ImgDir + "bg_active_item.gif";

    var first = true; // only for debugging
    var navigation = self; //eval("parent."+NavigationFrame);
    var breakSign = "<br>";
    var RelTopFrame = UTILS.main;
    var foundItem = null;
    var BaseURL = (BaseURL!=null) ? BaseURL : "";
    var ContentFrame = (ContentFrame==null) ? self : ContentFrame;

/**********************************************************************
* Classes and generic methods
***********************************************************************/
    function NavMenuItem(text, url, target, myIcon, myIconExpanded, myIconActive, tip, onclick) {
        this.text = text;                    // name of the link to diplay on screen
        this.url = (url!=null && url.indexOf("http://")==-1) ? BaseURL+url : url;
        this.onclick = (onclick.toUpperCase()=="<CALLHREF>") ? "ContentFrame.href='"+this.url+"';" : onclick;              // (optional): javascript code to be executed when clicking (in addition to href)
        this.target = (target=="" || target==null || target=="mainframe") ? TargetFrame : target; // target frame ("main" per default)
        this.tip = tip;                      // tooltip to be displayd on mouseover
        this.items = new Array();            // container for all subitems of this item
        this.expanded = false;               // is this item currently expanded or folded?
        this.divId = null;                   // reference to the <div> object that viualizes this item
        this.divTipId = null;                // reference to the <div> object that viualizes the tooltip of this item
        this.imgId = null;                   // reference to the <img> object of the visualization of this item
        this.style = null;                   // holds the hierarchical name of the style for the visualization of this item ("item0", "item1", "item2", ...)
        this.clickItem = clickItem;          // function that handles the clicking of an item
        this.expand = expand;                // function that handles the expanding/folding
        this.mouseOver = mouseOver;          // function that handles mouseover events
        this.mouseOut = mouseOut;            // function that handles mouseout events
        this.highlightItem = highlightItem;  // function that handles markup of clicked/selected items
        this.unhighlightPreviousItem = unhighlightPreviousItem;  // function that handles markup of clicked/selected items
        this.registerAsClickedItem = registerAsClickedItem;  // function that stores which item is currently clicked
        this.divheight = step;
        if (this.text.indexOf(breakSign) > -1)
            this.divheight = step*1.5;
        if (myIcon != "") {
            this.myIcon = new Image();       // (optional) image to be used instead of default image
            this.myIcon.src = ImgDir + myIcon;
        }
        if (myIconExpanded != "") {
            this.myIconExpanded = new Image();// (optional) image to be used instead of default image
            this.myIconExpanded.src = ImgDir + myIconExpanded;
        }
        if (myIconActive != "") {
            this.myIconActive = new Image();// (optional) image to be used for mouseOver animation and when an item is clicked
            this.myIconActive.src = ImgDir + myIconActive;
        }
    }

    function initNavigation() {
             if (ShowTips) {
             	var tooltipSrc = "";
             	tooltipSrc += "<html><head><link rel=stylesheet type=text/css href="+CSS+"></link><script language=JavaScript type=text/javascript src="+JSDir+UTILS_JS+"></script></head><body class=tooltip background=pics/back/back-li.jpg>";
             	tooltipSrc += makeDivLayer("emptytip", "tooltip", 0, 0, null, null, "visible", 1, null)+"&nbsp;</"+divlayer+">\n"
             	if (!UTILS.nav) {
                 tooltipSrc += makeDivLayer("waitMessage", "tooltip", 0, 0, null, null, "visible", 10, null);
                 tooltipSrc += "<font class='tooltip'>Loading navigation.<br>Please wait a moment...</font>"+
                               "</" + divlayer + ">\n";
             	}
             	eval("RelTopFrame."+TipFrame+".document.write(tooltipSrc);");
             }
             setDefaults();
             countLevels(navmenu, 1);
             preloadIcons();
             printNavigation();
             if (!UTILS.nav && ShowTips)
                 eval("RelTopFrame."+TipFrame+".document."+dom+domObj.replace("id","waitMessage")+"."+css+"visibility = 'hidden';");
             //navmenu.items[0].clickItem(); // this expands first item
    }

    function setDefaults() {
             // place initial values here, such as default expansion
             //navmenu.items[1].expanded = true;
    }

    function countLevels(currentNode, currentLevel) {
        if (currentNode.items.length > 0) {
           if (currentLevel > levels) levels = currentLevel++;
           for (var i=0; i<currentNode.items.length; i++) {
               countLevels(currentNode.items[i], currentLevel);
           }
        }
    }

    function searchItemByURL(currentNode, url) {
        if (eval(currentNode+".items")!=null) {
            for (var j=0; j<eval(currentNode+".items.length"); j++) {
               var cURL = eval(currentNode+".items["+j+"].url");
               if (cURL.lastIndexOf("/")!=-1)
                   cURL = cURL.substring(cURL.lastIndexOf("/")+1);
               else if (cURL.lastIndexOf("\\")!=-1)
                   cURL = cURL.substring(cURL.lastIndexOf("\\")+1);
               if (cURL==url) {
                   foundItem = eval(currentNode+".items["+j+"]");
               } else if (eval(currentNode+".items["+j+"]")!=null)
                 searchItemByURL(currentNode+".items["+j+"]",url);
            }
        }
   }

    function preloadIcons() {                    // preload the images for animated icons for each levels
        for (var i=0; i<levels; i++) {
            eval("Icons.item"+i+" = new Image();");
            eval("Icons.item"+i+"Expanded = new Image();");
            eval("Icons.item"+i+"Active = new Image();");
            eval("Icons.item"+i+"Clicked = new Image();");
            eval("Icons.item"+i+".src = '"+ImgDir+"item"+i+".gif';");
            eval("Icons.item"+i+"Expanded.src = '"+ImgDir+"item"+i+"expanded.gif';");
            eval("Icons.item"+i+"Active.src = '"+ImgDir+"item"+i+"active.gif';");
            eval("Icons.item"+i+"Clicked.src = '"+ImgDir+"item"+i+"clicked.gif';");
        }
    }

/**********************************************************************
* Display methods
***********************************************************************/
    function makeNavHtml(menuitem, level) {
       document.write(
       "<noscript>\n"+
       "<div class=\"item0"+level+"\">\n"+
            "<ilayer class=\"item0"+level+"\">\n"+
            	"<img alt=\""+menuitem.text+"\" src=\""+ImgDir+"item"+level+".gif\">&nbsp;\n"+
               "<a class=\"item0"+level+"\""+
            	((menuitem.onClick=="") ? "href=\""+menuitem.url+"\"" : "href=\"\" onClick=\""+menuitem.onclick+"\" ") +
               "target=\""+menuitem.target+"\">"+menuitem.text+"</a>\n"+
            "</ilayer>\n"+
        "</div>\n"+
        "</noscript>\n\n");
    }

    function printNavigation() {
        resetLoop();
        if (ShowTips) {
            printTips("navmenu");                 // call recursive method to loop through all items and generate output string for hidden tooltips
            eval("RelTopFrame."+TipFrame+".document.write('</body></html>');");
        }
        //var height = pos;
        first = true;
        resetLoop();
        printItems("navmenu", 0, "visible"); // call recursive method to loop through all items and generate output string for clickable links
        //document.writeln("<img src='pics/empty.gif' width='1' height='"+height+"' border='0'>");
    }

    function resetLoop() {                        // required before each looping of items: resets loop parameters
             count = 0;
             pos = startpos;
    }

    function printTips(currentNode) {             // loop through all items and generate output string
        if (eval(currentNode+".items") != null) {
            for (var j=0; j<eval(currentNode+".items.length"); j++) {
               var new_output = "";
               var divname = "tip"+count;
               count++;
               new_output += makeDivLayer(divname, "tooltip", 10, 0, null, null, "hidden", 1, null);
               //new_output += "\n<center>";       // a tribute to Netscape 4.7
               new_output += "\n<font class=\"tooltip\">";
               new_output += "\n"+eval(currentNode+".items["+j+"].tip");
               new_output += "\n</font>";
               //new_output += "\n</center>";      // a tribute to Netscape 4.7
               new_output += "\n</"+divlayer+">\n";
               if (ShowTips) {
               	eval("RelTopFrame."+TipFrame+".document.write(new_output);");
               }
               //if (first) { alert("tip:\n"+new_output); first = false;}
               pos += eval(currentNode+".items[j].divheight");       //this serves only for counting the amount of vertical space that will be required by the navigation tree when it's completely expanded
               eval(currentNode+".items["+j+"].divTipId = divname"); // link tip layer to corresponing item object
               printTips(currentNode+".items["+j+"]");
           }
        }
    }

    function printItems(currentNode, style, visibility) { //loop through all items and generate output string
        if (eval(currentNode+".items") != null) {
            for (var j=0; j<eval(currentNode+".items.length"); j++) {
               var divname = "item"+count;
               var vis_divheight;
               if (design=="alternate")
                   vis_divheight = (eval(currentNode+".items[j].divheight")==step) ? null : eval(currentNode+".items[j].divheight");
               else vis_divheight = step*2;
               count++;
               var new_output = "";
               new_output += makeDivLayer(divname, "item"+style, pos, 0, null, vis_divheight, visibility, 2, null);
               new_output += "\n<table cellpadding='0' cellspacing='0'>";
               new_output += "\n<tr><td valign='middle' width='"+leftWidth+"'>";
               new_output += "\n<a class=\"item"+style+"\" ";
               new_output += "href=\""+eval(currentNode+".items[j].url")+"\" ";
               new_output += "target=\""+eval(currentNode+".items[j].target")+"\" ";
               new_output += "onClick=\"navigation."+currentNode+".items["+j+"].clickItem();"
                if (eval(currentNode+".items[j].url")=="") new_output += "return false;";
               new_output += "\" ";
               new_output += "onMouseover=\""+currentNode+".items["+j+"].mouseOver()\" ";
               new_output += "onMouseout=\""+currentNode+".items["+j+"].mouseOut()\" ";
               new_output += ">";
               new_output += "<img "+ID+"='"+divname+"Img' src='";

               if (eval(currentNode+".items["+j+"].expanded")) {
                   if (eval(currentNode+".items["+j+"].myIconExpanded")!=null) {
                        new_output +=  eval(currentNode+".items["+j+"].myIconExpanded.src");
                   } else {
                        new_output +=  eval("Icons.item"+style+"Expanded.src");
                   }
               } else {
                   if (eval(currentNode+".items["+j+"].myIcon")!=null) {
                        new_output +=  eval(currentNode+".items["+j+"].myIcon.src");
                   } else {
                        new_output +=  eval("Icons.item"+style+".src");
                   }
               }

               new_output += "' border='0' alt='"+eval(currentNode+".items["+j+"].text")+"'>";
               new_output += "</a></td><td valign='top'>";
               new_output += "\n<a class=\"item"+style+"\" ";
               new_output += "href=\""+eval(currentNode+".items[j].url")+"\" ";
               new_output += "target=\""+eval(currentNode+".items[j].target")+"\" ";
               new_output += "onClick=\"navigation."+currentNode+".items["+j+"].clickItem();"
                if (eval(currentNode+".items[j].url")=="") new_output += "return false;";
               new_output += "\" ";
               new_output += "onMouseover=\""+currentNode+".items["+j+"].mouseOver()\" ";
               new_output += "onMouseout=\""+currentNode+".items["+j+"].mouseOut()\" ";
               new_output += ">";
               new_output += eval(currentNode+".items["+j+"].text");
               new_output += "</a>";
               new_output += "</td></tr></table>";
               if (design!="alternate" && UTILS.nav47) new_output += "<br>";
               new_output += "\n</"+divlayer+">\n";
               document.write(new_output);
               eval(currentNode+".items["+j+"].divId = divname;");              // link layer to corresponding item object
               eval(currentNode+".items["+j+"].imgId = divname+'Img';");        // link icon img to corresponding item object
               eval(currentNode+".items["+j+"].style = 'item'+style;");         // save name of style class in corresponding item object
               // check if there are children of the current item to be displayed
               var visibility_child = (eval(currentNode+".items["+j+"].expanded")) ? "visible" : "hidden";
               //if (first) {alert(new_output);first = false;}
               if (visibility == "visible") pos += eval(currentNode+".items[j].divheight");
               if (style<levels) printItems(currentNode+".items["+j+"]", style+1, visibility_child);
           }
        }
    }

    function clickItem() {
             // update navigation
             this.mouseOut();
             if (this.url!=null && this.url!="")
                 updateNavigation(this.url);

             // toggle icon between "expanded" and "collapsed"
             this.expand();
             // refresh display for all items
             resetLoop();                            // required before each looping of items
             refreshNavigation("navmenu", "visible"); // call recursive method to adjust position and visibility of all items

             // check if there is additional javascript code to be executed after click
             if (this.onclick != "") {
                eval(this.onclick);
             }
    }


    function expand() {
             // toggle icon between "expanded" and "collapsed"
             this.expanded = (this.expanded) ? false : true;
             var expanded = (this.expanded && this.items.length>0) ? "Expanded" : "";
             if (this.expanded) {
                 if (this.myIconExpanded != null) {
                     eval("document."+dom+this.imgId+".src = '"+this.myIconExpanded.src+"';");
                 } else {
                     eval("document."+dom+this.imgId+".src = '"+eval("Icons."+this.style+expanded+".src")+"';");
                 }
             } else {
                 if (this.myIcon != null) {
                     eval("document."+dom+this.imgId+".src = '"+this.myIcon.src+"';");
                 } else {
                     eval("document."+dom+this.imgId+".src = '"+eval("Icons."+this.style+expanded+".src")+"';");
                 }
             }
    }


    function unhighlightPreviousItem() {
             // un-highlight previosly clicked item (only if it's not a "blind" item)
             if (this.url != "" || this.onclick != "") {
                if (clickedItem.iconObj != null) {
                   clickedItem.iconObj.src = clickedItem.iconSrc;
                }
                if (clickedItem.background != null && !UTILS.nav47) {
                   eval("document."+dom+domObj.replace("id",clickedItem.divId)+"."+css+bgImage.replace("path",clickedItem.background)+";");
                }
             }
     }

     function highlightItem() {
            if (this.url != "" || this.onclick != "") {
                // highlight new item (if it's not "blind")
                if (!UTILS.nav47) eval("document."+dom+domObj.replace("id",this.divId)+"."+css+bgImage.replace("path",background_active.src)+";");
                if (this.myIconActive != null) {
                    clickedItem.iconObj.src = this.myIconActive.src;
                } else {
                    clickedItem.iconObj.src = eval("Icons."+this.style+"Clicked.src");
                }
             }
             // expand parent folders, if necessary
             if (this.parent != null) {
                 if (!this.parent.expanded && this.parent.expand) {
                     this.parent.expand();
                 }
             }
    }

    function registerAsClickedItem() {
             // register new item as clickedItem and store its visible values
             clickedItem.obj = this;
             clickedItem.divId = this.divId;
             clickedItem.background = eval("document."+dom+domObj.replace("id",this.divId)+"."+css+bgImage.substring(0,bgImage.indexOf(" ")));
             if (!UTILS.nav47) clickedItem.background = clickedItem.background.substring(clickedItem.background.indexOf("(")+1,clickedItem.background.indexOf(")"));
             clickedItem.iconObj = eval("document."+dom+this.imgId);
             clickedItem.iconSrc = clickedItem.iconObj.src;
    }


    function refreshNavigation(currentNode, visibility) { // loop through all items and adjust position and visibility after clicking
        if (eval(currentNode+".items") != null) {
           for (var j=0; j<eval(currentNode+".items.length"); j++) {
               var divname = "item"+count;
               count++;
               eval("document."+dom+domObj.replace("id",divname)+"."+css+"visibility = '"+visibility+"';");
               eval("document."+dom+domObj.replace("id",divname)+"."+css+"top = '"+pos+"';");
               if (visibility == "visible") {
                  pos += eval(currentNode+".items[j].divheight");
               }
               // check if there are children of the current item to be displayed
               if (eval(currentNode+".items["+j+"].expanded") && visibility == "visible")
                  refreshNavigation(currentNode+".items["+j+"]", "visible");
               else
                  refreshNavigation(currentNode+".items["+j+"]", "hidden");
           }
        }
    }

    function collapseAll() {                           // reset the navigation tree by collapsing all items and their subitems
        if (clickedItem.obj!=null)
            clickedItem.obj.unhighlightPreviousItem(); // remove markup from previously clicked item
        collapse("navmenu",0);                           // needs to call a recursive method
        setDefaults();
        resetLoop();
        refreshNavigation("navmenu", "visible");        // refresh display for all items
        self.scrollTo(0,0);
    }


    function collapse(currentNode, style) {                   // loop through all items and set property "expanded" to "false"
        if (eval(currentNode+".items") != null) {
           for (var j=0; j<eval(currentNode+".items.length"); j++) {
               eval(currentNode+".items["+j+"].expanded = false;");
               eval("document."+dom+eval(currentNode+".items["+j+"].imgId")+".src = '"+eval("Icons.item"+style+".src")+"';");
               collapse(currentNode+".items["+j+"]",style+1);
           }
        }
        setDefaults();
    }

    function mouseOver() {                              // show an item's tooltip when mouse moves over it
             if (ShowTips) eval("RelTopFrame."+TipFrame+".document."+dom+domObj.replace("id",this.divTipId)+"."+css+"visibility = 'visible';");
             if (this.divId!=clickedItem.divId) {
                 if (this.myIconActive != null) {
                     this.imgId.src = this.myIconActive.src;
                 } else {
                     eval("document."+dom+this.imgId+".src = Icons."+this.style+"Active.src;");
                 }
             }
    }

    function mouseOut() {                             // hide tooltip again when mouse moves away
             if (ShowTips) eval("RelTopFrame."+TipFrame+".document."+dom+domObj.replace("id",this.divTipId)+"."+css+"visibility = 'hidden';");
             if (this.divId!=clickedItem.divId) {
                 var expanded = (this.expanded && this.items.length>0) ? "Expanded" : "";
                 if (expanded) {
                     if (this.myIconExpanded != null) {
                         eval("document."+dom+this.imgId+".src = '"+this.myIconExpanded.src+"';");
                     } else {
                         eval("document."+dom+this.imgId+".src = '"+eval("Icons."+this.style+expanded+".src")+"';");
                     }
                 } else {
                   if (this.myIcon != null) {
                       eval("document."+dom+this.imgId+".src = '"+this.myIcon.src+"';");
                   } else {
                       eval("document."+dom+this.imgId+".src = '"+eval("Icons."+this.style+expanded+".src")+"';");
                   }
                 }
             }
    }


    function updateNavigation(url) {
         //if (navFrame==null) return;
         // url = path of file in content frame (relative to navigation.html)
         // url nur mitgeben, wenn aktuelle Seite über keinen eigenen Navigationspunkt
         // verfügt, sondern ein anderer verwendet werden soll
         // (url ist dann der rel. Pfad der anderen Datei)
         if (url==null) {
             var l = top.main.nav.location.href;
             var pos = (l.lastIndexOf("/")==-1) ? l.lastIndexOf("\\") : l.lastIndexOf("/");
             url = l.substring(pos+1);
             // chop off query string from url (if present)
             if (url.indexOf("?")!=-1)
                 url = url.substring(0,url.indexOf("?"));
         }
         foundItem = null;
         searchItemByURL("navmenu",url);
         if (foundItem!=null) {
             foundItem.unhighlightPreviousItem();
             foundItem.registerAsClickedItem();
             foundItem.highlightItem();
             resetLoop();                            // required before each looping of items
             refreshNavigation("navmenu", "visible"); // call recursive method to adjust position and visibility of all items
         }
   }

/**********************************************************************
* Utility methods
***********************************************************************/
     function getURLParameter(name) {
              var search;
              search = name + "=";
              offset = top.location.search.indexOf(search);
              if (offset != -1) {
                  offset += search.length ;
                  end = top.location.search.indexOf(";", offset) ;
                  if (end == -1)
                      end = top.location.search.length;
                  return unescape(top.location.search.substring(offset, end));
              } else return "";
     }


// -->
