/***************************************************************************************
        Nested list collapsing script written by Mark Wilton-Jones - 21/11/2003
Version 2.2.0 - this script takes existing HTML nested UL or OL lists, and collapses them
            Updated 13/02/2004 to allow links in root of expanding branch
                  Updated 09/09/2004 to allow state to be saved
          Updated 07/10/2004 to allow page address links to be highlighted
Updated 28/11/2004 to allow you to force expand/collapse links to use just the extraHTML
****************************************************************************************

Please see http://www.howtocreate.co.uk/jslibs/ for details and a demo of this script
Please see http://www.howtocreate.co.uk/jslibs/termsOfUse.html for terms of use
_________________________________________________________________________

You can put as many lists on the page as you like, each list may have a different format.

To use:
_________________________________________________________________________

Inbetween the <head> tags, put:

	<script src="PATH TO SCRIPT/listCollapse.js" type="text/javascript" language="javascript1.2"></script>
_________________________________________________________________________


selfLink(theRootID,newClass,shouldExpandBranch);
  theRootID = string: ID of root nest element, must be a UL or OL;
  newClass = string: new class name to add to any existing class names
  shouldExpandBranch = bool: expand branches to show the first matching link
  allows you to highlight links to the current page that appear in the list
  must be called _after_ collapsing the list
  address hash and port are not included in the comparison - links containing href="#" are always ignored

My cookie script is available on http://www.howtocreate.co.uk/jslibs/
	<body onload="compactMenu('someID',true,'&plusmn; ');stateToFromStr(theRootID,retrieveCookie('menuState'));"
	onunload="setCookie('menuState',stateToFromStr(theRootID),31536000);">
____________________________________________________________________________________________________*/
		var openLists = [], oIcount = 0;
		//*******************************************************************************
		// Nisad Sivcevic - 20050107
		var oPl = '<!--img src="images/sidebarNavli.gif" align="baseline" border="0" height="9" width="11"-->'
		var oPlImg = 'plus.gif';
		var oMnImg = 'minus.gif';

/*function clickSmack( oThisOb, oLevel, oBsID, oCol, oT ) {
			if( oThisOb.blur ) { oThisOb.blur(); }
			oThisOb = oThisOb.parentNode.getElementsByTagName( unescape(oT) )[0];
			if( oCol ) {
				for( var x = openLists[oBsID].length - 1; x >= oLevel; x-=1 ) { if( openLists[oBsID][x] ) {
					openLists[oBsID][x].style.display = 'none'; 
					//*******************************************************************************
					// Nisad Sivcevic - 20050107
					openLists[oBsID][x].previousSibling.innerHTML = openLists[oBsID][x].previousSibling.innerHTML.replace(oMnImg,oPlImg); 
					//*******************************************************************************
					if( oLevel != x ) { openLists[oBsID][x] = null; }
				} }
				if( oThisOb == openLists[oBsID][oLevel] ) { openLists[oBsID][oLevel] = null; }
				else {	oThisOb.style.display = 'block'; 
						//*******************************************************************************
						// Nisad Sivcevic - 20050107
						oThisOb.previousSibling.innerHTML = oThisOb.previousSibling.innerHTML.replace(oPlImg,oMnImg); 
						//*******************************************************************************
						openLists[oBsID][oLevel] = oThisOb; }
			} else { oThisOb.style.display = ( oThisOb.style.display == 'block' ) ? 'none' : 'block'; }
		}
*/		function stateToFromStr(oID,oFStr) {
			if( !document.getElementsByTagName || !document.childNodes || !document.createElement ) { return ''; }
			var baseElement = document.getElementById( oID ); if( !baseElement ) { return ''; }
			if( !oFStr && typeof(oFStr) != 'undefined' ) { return ''; } if( oFStr ) { oFStr = oFStr.split(':'); }
			for( var oStr = '', l = baseElement.getElementsByTagName(baseElement.tagName), x = 0; l[x]; x++ ) {
				if( oFStr && MWJisInTheArray( l[x].MWJuniqueID, oFStr ) && l[x].style.display == 'none' ) { l[x].parentNode.getElementsByTagName('a')[0].onclick(); }
				else if( l[x].style.display != 'none' ) { oStr += (oStr?':':'') + l[x].MWJuniqueID; }
			}
			return oStr;
		}
/*		function MWJisInTheArray(oNeed,oHay) { for( var i = 0; i < oHay.length; i++ ) { if( oNeed == oHay[i] ) { return true; } } return false; }
*/		function selfLink(oRootElement,oClass,oExpand) {
			if(!document.getElementsByTagName||!document.childNodes) { return; }
			oRootElement = document.getElementById(oRootElement);
			for( var x = 0, y = oRootElement.getElementsByTagName('a'); y[x]; x++ ) {
				if( y[x].getAttribute('href') && !y[x].href.match(/#$/) && getRealAddress(y[x]) == getRealAddress(location) ) {
					y[x].className = (y[x].className?(y[x].className+' '):'') + oClass;
					if( oExpand ) {
						oExpand = false;
						for( var oEl = y[x].parentNode, ulStr = ''; oEl != oRootElement && oEl != document.body; oEl = oEl.parentNode ) {
							if( oEl.tagName && oEl.tagName == oRootElement.tagName ) { ulStr = oEl.MWJuniqueID + (ulStr?(':'+ulStr):''); } }
						stateToFromStr(oRootElement.id,ulStr);
		} } } }
		function getRealAddress(oOb) { return oOb.protocol + ( ( oOb.protocol.indexOf( ':' ) + 1 ) ? '' : ':' ) + oOb.hostname + ( ( typeof(oOb.pathname) == typeof(' ') && oOb.pathname.indexOf('/') != 0 ) ? '/' : '' ) + oOb.pathname + oOb.search; }
