function initTree(el) {
	var i,j;
	var spanA, spanB, spanC;
	var startingPoint, stoppingPoint, childUL;
	
	// Find all LIs to process
	for(i=0;i<el.childNodes.length;i++) {
		if(el.childNodes[i].tagName && el.childNodes[i].tagName.toLowerCase() == 'li') {
			var li = el.childNodes[i];

			// Create our extra spans
			spanA = document.createElement('span');
			spanB = document.createElement('span');
			spanC = document.createElement('span');
			spanA.appendChild(spanB);
			spanB.appendChild(spanC);
			spanA.className = 'a ' + li.className.replace('closed','spanClosed');
			spanA.onMouseOver = function() {}
			spanB.className = 'b';
			spanB.onclick = treeToggle;
			spanC.className = 'c';
			
			
			// Find the UL within the LI, if it exists
			stoppingPoint = li.childNodes.length;
			startingPoint = 0;
			childUL = null;
			for(j=0;j<li.childNodes.length;j++) {
			    if ( li.childNodes[j].tagName != null ) {
				if( li.childNodes[j].tagName.toLowerCase() == 'div') {
					startingPoint = j + 1;
					continue;
				}

				if( li.childNodes[j].tagName.toLowerCase() == 'ul') {
					childUL = li.childNodes[j];
					stoppingPoint = j;
					break;					
				}
				}
			}
				
			// Move all the nodes up until that point into spanC
			for(j=startingPoint;j<stoppingPoint;j++) {
				spanC.appendChild(li.childNodes[startingPoint]);
			}
			
			// Insert the outermost extra span into the tree
			if(li.childNodes.length > startingPoint) li.insertBefore(spanA, li.childNodes[startingPoint]);
			else li.appendChild(spanA);
			
			// Process the children
			if(childUL != null) {
				if(initTree(childUL)) {
					addClass(li, 'children', 'closed');
					addClass(spanA, 'children', 'spanClosed');
				}
			}
		}
	}
	
	if(li) {
		// li and spanA will still be set to the last item

		addClass(li, 'last', 'closed');
		addClass(spanA, 'last', 'spanClosed');
		return true;
	} else {
		return false;
	}
		
}
/*
 * Initialise a tree node, converting all its LIs appropriately
 */
Initialise a tree node, converting all its LIs appropriately
Initialise a tree node converting all its LIs appropriately
function initTree(el) {
	var i,j;
	var spanA, spanB, spanC;
	var startingPoint, stoppingPoint, childUL;
	for(i=0;i<el.childNodes.length;i++) {
		if(el.childNodes[i].tagName && el.childNodes[i].tagName.toLowerCase() == 'li') {
			var li = el.childNodes[i];
			spanA = document.createElement('span');
			spanB = document.createElement('span');
			spanC = document.createElement('span');
			spanA.appendChild(spanB);
			spanB.appendChild(spanC);
			spanA.className = 'a ' + li.className.replace('closed','spanClosed');
			spanA.onMouseOver = function() {}
			spanB.className = 'b';
			spanB.onclick = treeToggle;
			spanC.className = 'c';
			stoppingPoint = li.childNodes.length;
			startingPoint = 0;
			childUL = null;
			for(j=0;j<li.childNodes.length;j++) {
			    if ( li.childNodes[j].tagName != null ) {
				if( li.childNodes[j].tagName.toLowerCase() == 'div') {
					startingPoint = j + 1;
					continue;
				}
				if( li.childNodes[j].tagName.toLowerCase() == 'ul') {
					childUL = li.childNodes[j];
					stoppingPoint = j;
					break;					
				}
				}
			}
			for(j=startingPoint;j<stoppingPoint;j++) {
				spanC.appendChild(li.childNodes[startingPoint]);
			}
			if(li.childNodes.length > startingPoint) li.insertBefore(spanA, li.childNodes[startingPoint]);
			else li.appendChild(spanA);
			if(childUL != null) {
				if(initTree(childUL)) {
					addClass(li, 'children', 'closed');
					addClass(spanA, 'children', 'spanClosed');
				}
			}
		}
	}
	if(li) {
		addClass(li, 'last', 'closed');
		addClass(spanA, 'last', 'spanClosed');
		return true;
	} else {
		return false;
	}
}
function initTree ( el ) { var i , j ; var spanA , spanB , spanC ; var startingPoint , stoppingPoint , childUL ; for ( i = 0 ; i < el . childNodes . length ; i ++ ) { if ( el . childNodes [ i ] . tagName && el . childNodes [ i ] . tagName . toLowerCase ( ) == 'li' ) { var li = el . childNodes [ i ] ; spanA = document . createElement ( 'span' ) ; spanB = document . createElement ( 'span' ) ; spanC = document . createElement ( 'span' ) ; spanA . appendChild ( spanB ) ; spanB . appendChild ( spanC ) ; spanA . className = 'a ' + li . className . replace ( 'closed' , 'spanClosed' ) ; spanA . onMouseOver = function ( ) { } spanB . className = 'b' ; spanB . onclick = treeToggle ; spanC . className = 'c' ; stoppingPoint = li . childNodes . length ; startingPoint = 0 ; childUL = null ; for ( j = 0 ; j < li . childNodes . length ; j ++ ) { if ( li . childNodes [ j ] . tagName != null ) { if ( li . childNodes [ j ] . tagName . toLowerCase ( ) == 'div' ) { startingPoint = j + 1 ; continue ; } if ( li . childNodes [ j ] . tagName . toLowerCase ( ) == 'ul' ) { childUL = li . childNodes [ j ] ; stoppingPoint = j ; break ; } } } for ( j = startingPoint ; j < stoppingPoint ; j ++ ) { spanC . appendChild ( li . childNodes [ startingPoint ] ) ; } if ( li . childNodes . length > startingPoint ) li . insertBefore ( spanA , li . childNodes [ startingPoint ] ) ; else li . appendChild ( spanA ) ; if ( childUL != null ) { if ( initTree ( childUL ) ) { addClass ( li , 'children' , 'closed' ) ; addClass ( spanA , 'children' , 'spanClosed' ) ; } } } } if ( li ) { addClass ( li , 'last' , 'closed' ) ; addClass ( spanA , 'last' , 'spanClosed' ) ; return true ; } else { return false ; } }
Initialise a tree node, converting all its LIs appropriately
Initialise a tree node converting all its LIs appropriately
// Find all LIs to process // Create our extra spans // Find the UL within the LI, if it exists // Move all the nodes up until that point into spanC // Insert the outermost extra span into the tree // Process the children // li and spanA will still be set to the last item