
var lmenu_zMENU;
var lmenu_zDD;
var lmenu_zDT;
var lmenu_zSKIPid="skip_1";
function lmenu_SlideMENU(menu){
// we check first if the browser can handle our script, if it does not then we stop right there
if (!document.getElementById || !document.getElementsByTagName) return; 
// the parameter we pass through the function is assigned to the variable 
lmenu_zMENU=menu;
// an array that contains all our DTs
lmenu_zDD =document.getElementById(lmenu_zMENU).getElementsByTagName('dd');
// an array that contains all our DDs
lmenu_zDT =document.getElementById(lmenu_zMENU).getElementsByTagName('dt'); 
// we go through the whole array to do what we have to do
for(var i=0;i<lmenu_zDT.length;i++){
// we create a new DT
	var newDT = document.createElement('dt');
// we grab the text the original one contains
	var stringOfText = lmenu_zDT[i].firstChild.data;
// we create a A element
	var newAnchor = document.createElement('a');
// we wrap the text in the DT into the new anchor	
	newAnchor.appendChild(document.createTextNode(stringOfText));
// we plug the anchor into the new DT
	newDT.appendChild(newAnchor);	
// we set a href attribute
	newAnchor.href = "#";
// we set an ID to use it as a named anchor	(to be used with the skip links)
//	newAnchor.id=lmenu_zSKIPid;	
//	newAnchor.name=lmenu_zSKIPid;
// we set a title	
    newAnchor.title="Show/hide the sub-menu";
// we use redundant mechanisms to call the function that will do the job
	newAnchor.onclick = function(event){return lmenu_doSlideMENU(this,event)};
	newAnchor.onkeypress = function(event){return lmenu_doSlideMENU(this,event)};
// we replace the old one with the one we have just created
    lmenu_zDT[i].parentNode.replaceChild(newDT,lmenu_zDT[i]);
// we plug a skip link in all DTs but the last one. this skip link contains some static text + a BR element + the text found in the next DT 
	if(i<lmenu_zDT.length-1){
// we start by creating an A element
	var newSkipLink = document.createElement("a");
// now we set some static text
	var startString = "Skip to:";
// we include a BR element to create a line break after the above static text
	var newBR = document.createElement("br");
// we fetch the text within the next DT
	var endString = lmenu_zDT[i+1].firstChild.data;
// we start to put everything together, first the static text
	newSkipLink.appendChild(document.createTextNode(startString));
// now the BR element			
	newSkipLink.appendChild(newBR);
// and now the text inside the next DT			
	newSkipLink.appendChild(document.createTextNode(endString));			
// we apply a class name to the "skip link" (used to hide/reveal with active/focus)
    newSkipLink.className = "lmenu_Skipper";
// we set a href attribute so it is possible to "jump" to the next "skip link"		
	newSkipLink.href= "#";
	newSkipLink.id=lmenu_zSKIPid;	
// we cannot use the "href" above to navigate to the named anchors because that would feed the history object. We could use replace(), but using focus() is a better approach.
		if(i==lmenu_zDT.length-2){newSkipLink.onclick=function(){this.parentNode.parentNode.getElementsByTagName("dd")[lmenu_zDT.length-1].getElementsByTagName("a")[0].focus();};}else{newSkipLink.onclick=function(){lmenu_SKIPtoLINK(this.id+"1");};}
// 	we call lmenu_removeSkipLink() onblur and onfocus to "help" MS IE do the job
	newSkipLink.onblur=function(){lmenu_removeSkipLink(this)};
	newSkipLink.onfocus=function(){lmenu_removeSkipLink(this)};
	lmenu_zDT[i].appendChild(newSkipLink);
	}
// we set the class for all the DTs and the DDS in there
	lmenu_zDT[i].className='lmenu_SlideMenu_DTopen';
	lmenu_zDD[i].className='lmenu_SlideMenu_HideDD';
// we call "lmenu_revealOnFocus()" on all nested links
		var zAnchors = lmenu_zDD[i].getElementsByTagName('a');
		for(var j=0;j<zAnchors.length;j++){
			lmenu_zDD[i].getElementsByTagName("a")[j].onfocus= lmenu_revealOnFocus;
		}
		
	lmenu_zSKIPid=lmenu_zSKIPid+"1";		
	}
// we create one more anchor to help keyboard users jump back at the very top of the menu
	var newSkipBackLink = document.createElement("a");
	newSkipBackLink.appendChild(document.createTextNode("Skip To:"));
// now the BR element			
	newSkipBackLink.appendChild(newBR);
// and now the text inside the next DT			
	newSkipBackLink.appendChild(document.createTextNode("Top of the Menu"));			
// we apply a class name to the "skip link" (used to hide/reveal with active/focus)
    newSkipBackLink.className = "lmenu_Skipper";
// we set a href attribute so it is possible to "jump" to the very first anchor in the Menu
	newSkipBackLink.href="#";
	newSkipBackLink.onclick=function(){document.getElementById("skip_1").focus();};
// we call lmenu_removeSkipLink() onblur and onfocus to "help" MS IE do the job
	newSkipBackLink.onblur=function(){lmenu_removeSkipLink(this)};
	newSkipBackLink.onfocus=function(){lmenu_removeSkipLink(this)};
// we plug this new anchor in the DL	
	lmenu_zDD[lmenu_zDD.length-1].appendChild(newSkipBackLink);			
}
function lmenu_SKIPtoLINK(z_thisSKIP){document.getElementById(z_thisSKIP).focus();return false;}
function lmenu_doSlideMENU(zItem,objEvent){
// to take care of "onkeypress": see http://juicystudio.com/article/ecmascriptmenu.php
    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 is not the enter key or space key, pass control back to the browser
        if (iKeyCode != 13 && iKeyCode != 32) return true;
    }
// we do the stuff - swapping classes for the DTs and the DDs
zItem.parentNode.className=(zItem.parentNode.className=='lmenu_SlideMenu_DTopen')?'lmenu_SlideMenu_DTclose':'lmenu_SlideMenu_DTopen'; 
// we swap the class of the DDs differently depending on the browser
if(zItem.parentNode.nextSibling.nodeType==1){
// for MSIE
zItem.parentNode.nextSibling.className=(zItem.parentNode.nextSibling.className=='lmenu_SlideMenu_HideDD')?'lmenu_SlideMenu_ShowDD':'lmenu_SlideMenu_HideDD';	
}else{
zItem.parentNode.nextSibling.nextSibling.className=(zItem.parentNode.nextSibling.nextSibling.className=='lmenu_SlideMenu_HideDD')?'lmenu_SlideMenu_ShowDD':'lmenu_SlideMenu_HideDD';	
}
// to make sure the browser does not load the href value
return false;
}
function lmenu_revealOnFocus(){
// we swap DD class to reveal them when the user hits a nested (hidden) link
	this.parentNode.parentNode.parentNode.className='lmenu_SlideMenu_ShowDD';
// we swap the related DT class (the previous sibling)

if(this.parentNode.parentNode.parentNode.previousSibling.nodeType==1){
// for MSIE	
	this.parentNode.parentNode.parentNode.previousSibling.className='lmenu_SlideMenu_DTclose';	
}else{
	this.parentNode.parentNode.parentNode.previousSibling.previousSibling.className='lmenu_SlideMenu_DTclose';	
}
}
function lmenu_removeSkipLink(zObject){
// this is to avoid an IE bug with the skip links when tabbing backward/forward
	zObject.className='lmenu_Skipper';
}