	
	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, October 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	

	/************************************************************************************************************
	(C) www.franksworkshop.com, October 2008
	
	This was originally from www.dhtmlgoodies.com, but I made significant changes to support hrefs on branches,
	and match the full URL path to locate the current menu item.  I couldn't really follow the code, so I rewrote
	most of it, but used the same concepts as the original.
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	************************************************************************************************************/	
	
	var activeNode = null;
	var bAutoClose = true;
	
	function isIE()
	{
      var ua = window.navigator.userAgent
      var msie = ua.indexOf ( "MSIE " )

      if ( msie > 0 )      // If Internet Explorer, return true
         return true;
      else                 // If another browser, return 0
         return false;
	}
   
    function getChildUL(node)
    {
        var ul = null;
        
        for ( var i = 0; i < node.childNodes.length; i++ )
        {
            if ( node.childNodes[i].tagName == 'UL' )
            {
                ul = node.childNodes[i];
                break;
            }
        }
        return ul;
    }
    
    function getParentUL(node)
    {
        while ( node != null )
        {
            if ( node.parentNode != null && node.parentNode.tagName == 'UL' )
                return node.parentNode;
            node = node.parentNode;
        }
        return null;
    }
    
    function toggleSubMenu(e)
    {
        var node = this;
        var ul = getChildUL(node);
     
        // first toggle this menu item.   
        if ( ul != null )
        {
            if ( ul.style.display == 'none' )
                ul.style.display = 'block';
            else
                ul.style.display = 'none';
        }
        
        // next, optionally close any open menu items at the same level
        if ( bAutoClose )
        {
            ul = getParentUL(node);
            if ( ul != null )
            {
                for ( var i = 0; i < ul.childNodes.length; i++ )
                {
                    var item = ul.childNodes[i];
                    if ( item != node )
                    {
                        var childUL = getChildUL(item);
                        if ( childUL != null )
                            childUL.style.display = 'none';
                    }
                }
            }
        }
        
        
        if (!e) 
            e = window.event;
	    e.cancelBubble = true;
	    if (e.stopPropagation) 
	        e.stopPropagation();
    }
    
    function showPath(node)
    {
        // May need to make child nodes visible
        var ul = getChildUL(node);
        if ( ul != null )
            ul.style.display = 'block';
           
        // make the path to the parent visibile.   
        while ( node != null )
        {
            ul = getParentUL(node);
            if ( ul != null )
                ul.style.display = 'block';
            node = ul;
        }
    }
    
    function GetAElement( node )
    {
        for ( var i = 0; i < node.childNodes.length; i++ )
        {
            var node = node.childNodes[i];
            if ( node.tagName == 'A' )
            {
                return node;
            }
        }
        return null;
    }
    
    function getHRefPath( node )
    {
        var s = node.pathname;
        while ( s != null && s.length > 0 && s.indexOf("/") == 0 )
        {
            s = s.substr(1);
        }
        return s;
    }

    function ProcessList( root, fileNameThis )
    {
        var hasChildren = false;
        for ( var i = 0; i < root.childNodes.length; i++ )
        {
            var node = root.childNodes[i];
            if ( node.tagName == 'LI' || node.tagName == 'UL' )
            {
                if ( node.tagName == 'LI' )
                {
                    hasChildren = true;
                    // if this item has an A tag, check if it is the current page
                    var atag = GetAElement( node );
                    if ( atag != null && atag.href.charAt(atag.href.length-1)!='#')
                    {
                        var path = getHRefPath(atag).toLowerCase();
                        if ( path == fileNameThis )
                        {
                            // match
                            activeNode = node;
                        }
                    }
                    else // No A tag.  Is either a branch or dead leaf
                    {
                    }
                }
                else // node.tagName == 'UL'
                {
                    node.style.display='none';
                }
                
                if ( ProcessList( node, fileNameThis ) )
                {
                    hasChildren = true;
                    // this is a branch node
                    if ( node.tagName == 'LI' )
                    {
                        node.onclick = toggleSubMenu;
                        
                    	var atag = node.firstChild;
                        var pointer = document.createElement("div");
                        if ( isIE() )
                        {
	                        pointer.style.position = 'absolute';
                        	pointer.style.left = "145px";
                        	pointer.style.top = "20px";
	                    }
	                    else
	                    {
	                        pointer.style.position = 'relative';
                        	pointer.style.left = "145px";
                        	pointer.style.top = "0px";
	                    }
                        pointer.style.width = "5px";
                        pointer.style.height = "5px";
                        pointer.style.borderStyle = "none";
                        pointer.style.padding = "0";
                        var img = document.createElement("img");
                        img.src = "/dot.png";
                        img.style.width = "5px";
                        img.style.height = "5px";
                        img.style.borderStyle = "none";
                        img.style.padding = "0";
                        atag.style.borderStyle = "none";
                        pointer.appendChild(img);
                        atag.appendChild(pointer);                    
                    }
                }
                
            }
        }
        return hasChildren;
    }
    
	function initMenu()
	{
	    // Find tree branch nodes and add onclick handlers
	    // Find the current node and select it

		var objMenuRoot = document.getElementById('dhtmlgoodies_listMenu');
		
		// We use the file path part of the URL to match A tag hrefs
		var fileNameThis = getHRefPath(location).toLowerCase();
		// strip any trailing guff
		if (fileNameThis.indexOf('?') > 0)
			fileNameThis = fileNameThis.substr(0,fileNameThis.indexOf('?'));
		if (fileNameThis.indexOf('#') > 0)
			fileNameThis = fileNameThis.substr(0,fileNameThis.indexOf('#'));
		
		

        // Recurse through the lists
        ProcessList( objMenuRoot, fileNameThis );

        if ( activeNode != null )
        {
	        activeNode.firstChild.className='activeMenuLink';
		    showPath(activeNode);	
        }
    
	}
	window.onload = initMenu;
	
