function twoCols(src, type)
{
	// Ratios for leftHand rightHand columns.  Set to equal
	// The smaller the leftWeight relative to rightWeight,
	// the less items on the left column relative to the right column.
	var leftWeight = 100;
	var rightWeight = 100;

	var origList = src;
	
	var leftList = document.createElement(type);
  	var rightList = document.createElement(type);
  	var container = document.createElement('div');

  	var items = origList.getElementsByTagName('LI');

	var ratio = (leftWeight + rightWeight) / leftWeight;
	var itemsLength = items.length/ratio;
	//alert(itemsLength);
	//Now find the parent of the middle element.
	var middleItem = items[Math.round(itemsLength) - 1];
	
	var listItems = origList.childNodes;
	var i = 0;

	// Copy first to left
	while (listItems.length > 1) {
		if (contains(listItems[0], middleItem)) {
			break;
		}
		leftList.appendChild(listItems[0]);
	}

	// Only split the child elements if child elements exist
	var leftHalf = listItems[0].cloneNode(true);	
	if (0 < leftHalf.getElementsByTagName("UL").length) {
		trimTree(leftHalf, middleItem, false, false)
		leftList.appendChild(leftHalf);

		var rightHalf = listItems[0].cloneNode(true);
		trimTree(rightHalf, middleItem, true, false)
		rightList.appendChild(rightHalf);
	}
	else {
		leftList.appendChild(listItems[0].cloneNode(true));
	}
	//leftList.appendChild(listItems[0].cloneNode(true));
	// Copy to right
	while (listItems.length > 1) {
		rightList.appendChild(listItems[1]);
	}	
	
	
	//rightList.appendChild(listItems[0].cloneNode(true));
	/*
	for (i = 0; i < itemsLength; i++)
	{
		leftList.appendChild(items[0]);
	}
	
	itemsLength = items.length;
	for (i = 0; i < itemsLength; i++)
    {
    	rightList.appendChild(items[0]);
    }
    */
  	container.appendChild(leftList);
  	container.appendChild(rightList);

  	leftList.setAttribute('class', 'left');
  	rightList.setAttribute('class', 'right');
  	container.setAttribute('class','twocol');
  	if (document.all)
    {
      leftList.setAttribute('className', 'left');
      rightList.setAttribute('className', 'right');
    	container.setAttribute('className','twocol');
    }
  	if (type == 'ol')
    {
    	rightList.setAttribute('start', leftList.getElementsByTagName('LI').length + 1 );
    }
  	origList.parentNode.replaceChild(container, origList);
}

function allTwoCols (whichclass, type)
{
  	var uls = document.getElementsByTagName(type);
  	for (var i=0; i< uls.length; i++)
    {
    	if (uls[i].getAttribute('class') == whichclass || 
        	uls[i].getAttribute('className') == whichclass)
      	{
      		twoCols(uls[i], type.toLowerCase());
      	}
    }
}

function contains(tree, node) {
	if (tree == node) {
		return true;
	}
	
	var found = false;
	for (var i = 0; i < tree.childNodes.length; i++) {
		found |= contains(tree.childNodes[i], node);
	}
	return found;
}

// Depth first search.  The algorithm may seem complicated
// but the logic is pretty simple.  DPS through the tree,
// and get rid of nodes before or after found.  If trim_before
// is set to true, then nodes before up to and including
// "node" are trimmed from the tree.  If trim_before is set to false
// the nodes are trimmed
function trimTree(tree, node, trim_before, found) {
	var firstFound = (tree.className == node.className)
	found |= firstFound;
	//if (firstFound) alert(tree.innerHTML);	
	//if (!tree.hasChildNodes()) return found;
	var nextUl = tree.getElementsByTagName("ul");
	var firstUl;
	
	if (nextUl.length > 0 ){
		firstUl = nextUl[0];
			
		var curNode = firstUl.firstChild;
		
		while ( curNode != null){
			var nextNode = curNode.nextSibling;
			if (curNode.tagName == "LI") {
				found |= trimTree(curNode, node, trim_before, found);
			}
			curNode = nextNode;
			//alert(curNode);
		}
	}
	
	if (firstFound && !trim_before) return found;

	var liLength =  (nextUl.length > 0) ? firstUl.getElementsByTagName("li").length : 0;
	
	if (nextUl.length == 0 || liLength == 0) {
		if ( (trim_before && ( !found || firstFound)) ||
			 (!trim_before && found) ) {
			//alert("removing tree");
			var parent = tree.parentNode;
			if (parent != null) {
				parent.removeChild(tree);	
				//alert("removing: " + nextUl.length + " " + tree.innerHTML);
			}
		}
	}
	
	return found;
}