CLOSED_IMAGE='style/list-plus.gif';
OPEN_IMAGE='style/list-minus.gif';
LEAF_IMAGE='style/list-leaf.gif';

/* makeCollapsible - makes a list have collapsible sublists
 * 
 * listElement - the element representing the list to make collapsible
 */
function makeCollapsible(listElementID)
{	
	var listElement = (typeof(listElementID) == 'string') ? document.getElementById(listElementID) : listElementID;
	// removed list item bullets and the space they occupy
	listElement.style.listStyle='none';
//	listElement.style.marginLeft='0';
//	listElement.style.paddingLeft='0';
	
	// loop over all child elements of the list
	var child=listElement.firstChild;
	while (child!=null)
	{
		// only process li elements (and not text elements)
		if (child.nodeType==1)
		{
			// build a list of child ol and ul elements and hide them
			var list=new Array();
			var grandchild=child.firstChild;
if (listElementID == 'sitemap_other_printers')
{
//	alert(child.innerHTML);
}
			while (grandchild!=null)
			{
				if (grandchild.tagName=='OL' || grandchild.tagName=='UL')
				{
					grandchild.style.display='none';
					list.push(grandchild);
					makeCollapsible(grandchild);
				}
				grandchild=grandchild.nextSibling;
			}

			// add toggle buttons
			var node=document.createElement('img');
			if (list.length)
			{
				node.setAttribute('src',CLOSED_IMAGE);
				node.setAttribute('width', 9);
				node.setAttribute('height', 12);
				node.setAttribute('class','closed');
				node.onclick=createToggleFunction(node,list);
//child.style.listStyleImage = 'url(' + CLOSED_IMAGE + ')';
//child.onclick=createToggleFunction(node,list);
			}
			else
			{
				node.setAttribute('src',LEAF_IMAGE);
				node.setAttribute('width', 9);
				node.setAttribute('height', 12);
				node.setAttribute('class','leaf');
//child.style.listStyleImage = 'url(' + LEAF_IMAGE + ')';
//child.onclick=createToggleFunction(node,list);
			}
			node.style.marginRight = '4px';
			child.insertBefore(node,child.firstChild);
		}
		child=child.nextSibling;
	}
}

/* createToggleFunction - returns a function that toggles the sublist display
 * 
 * toggleElement  - the element representing the toggle gadget
 * sublistElement - an array of elements representing the sublists that should
 *                  be opened or closed when the toggle gadget is clicked
 */
function createToggleFunction(toggleElement,sublistElements){
	
	return function()
	{
		// toggle status of toggle gadget
		if (toggleElement.getAttribute('class')=='closed')
		{
			toggleElement.setAttribute('class','opened');
			toggleElement.setAttribute('src',OPEN_IMAGE);
		}
		else
		{
			toggleElement.setAttribute('class','closed');
			toggleElement.setAttribute('src',CLOSED_IMAGE);
		}
		
		// toggle display of sublists
		for (var i=0;i<sublistElements.length;i++)
		{
			sublistElements[i].style.display = (sublistElements[i].style.display=='block')?'none':'block';
		}
	}	
}
