
var menuId = 'mainMenu';
var show_current_item = true;

/*****************************************************/
//window.onload=rollup;
//run();
rollup();



function run()
{
	var oldOnload = window.onload;

	if (typeof(window.onload) != "function")
	{
		window.onload = rollup;
	}
	else
	{
		window.onload = function()
		{
			oldOnload();
			rollup();
		}
	}
}

function rollout(objMenuitem, objEvent)
{
    var iKeyCode;

    // Check if from a keyboard - non IE, but
    // irrelevant as tab doesn't trigger the 
    // keypress event in IE
    if (objEvent && objEvent.type == 'keypress')
    {
        if (objEvent.keyCode)
            iKeyCode = objEvent.keyCode;
        else if (objEvent.which)
            iKeyCode = objEvent.which;

        // If it's not the enter key or space key, 
        // pass control back to the browser
        if (iKeyCode != 13 && iKeyCode != 32)
            return true;
    }

    if (objMenuitem.nextSibling.style.display == 'block'){
        objMenuitem.nextSibling.style.display = 'none';
        objMenuitem.parentNode.className='submenu';
    }else{
        objMenuitem.nextSibling.style.display = 'block';
        objMenuitem.parentNode.className+=' open';
	}
    // Stop the browser requesting the link
    return false;
}

function rollup()
{
    var bRollup, objLinks, objNode, objAnchor;

    // Check we're working with a DOM compliant browser
    if (document.getElementById && document.createElement)
    {
        var strLocation = window.location;

        var objMenu = document.getElementById(menuId);
        
        if(!objMenu)return;

        var objNested = objMenu.getElementsByTagName('ul');
	  
	  if (show_current_item ){
	  	objLinks = objMenu.getElementsByTagName('a');
	  	 for (var j=0; j<objLinks.length; j++){
	  	    if (objLinks[j].href == strLocation){
					objLinks[j].parentNode.parentNode.parentNode.className+=' open'; 
                    if(objLinks[j].parentNode.className !='')
                    	objLinks[j].parentNode.className+=' current';
                    else objLinks[j].parentNode.className='current';
                    break;	
                }
             }     
        }
                
        // Hide each of the nested unordered list
        for (var i=0; i<objNested.length; i++)
        {
            // Only hide, if the current location is not found in the list
            bRollup = true;
            objLinks = objNested[i].getElementsByTagName('a');

            for (var j=0; j<objLinks.length; j++)
            {
                if (objLinks[j].href == strLocation && show_current_item ){
                    bRollup = false;
                    //break;	
                }    
            }

            if (bRollup == true)
                objNested[i].style.display = 'none';
            else 
                objNested[i].style.display = 'block';
		 
	
            // Place the top-level text in an anchor tag
            objNode = objNested[i].parentNode;

            strContent = objNode.firstChild.data;
            if(!strContent)strContent = objNode.firstChild.firstChild.firstChild.data;

            objAnchor = document.createElement('a');
            objAnchor.href = '#';
		objAnchor.className = "fold";
            objAnchor.onclick = function(event){return rollout(this, event);}
            objAnchor.onkeypress = function(event){return rollout(this, event);}
		objAnchor.setAttribute('onfocus','this.blur()');
            objAnchor.appendChild(document.createTextNode(strContent));

            objNode.replaceChild(objAnchor, objNode.firstChild);
        }
    }
}

