// JavaScript Document
function ListLegion() {
	this.aLegions = new Array();
	
	this._newLegion = function(oUL) {
		var sId = oUL.id;
		this.aLegions[sId] = new ListLegionList(oUL);
	}
	
	this._changeSelected = function(sGroup, iId) {
		//if(!this.aLegions[sGroup])
	}
	
	this.getCurrent = function(sGroup) {
		
	}
}

function ListLegionList(oUL) {
	this.oUL = oUL;
	this.aElements = new Array();
	this.sCurrent  = null;
	this._processUL(oUL);		
}
ListLegionList.prototype.reCurrent    = /\bcurrent\b/g;
ListLegionList.prototype.reExpandable = /\bexpandable\b/g;
ListLegionList.prototype.reExpanded   = /\bexpanded\b/g;

ListLegionList.prototype._processUL = function(oUL) {
	if (!oUL.childNodes || oUL.childNodes.length==0) { return; }
	for(var i=0; i<oUL.childNodes.length; i++) {
		if(oUL.childNodes[i].nodeName == 'LI') {
			var oLI = oUL.childNodes[i];
			this.aElements[i] = oLI;
			var bSubs = false;
			for(j in oLI.childNodes) {
				if(oLI.childNodes[j].nodeName == 'UL') {
					bSubs = true;
					this._processUL(oLI.childNodes[j]);
				}
			}
			var oBullet = document.createElement("SPAN");
			var sText   = '\u00A0\u00A0\u00A0\u00A0';
			oBullet.className = 'bullet';
			if(bSubs) {
				changeClass(oLI, 'expandable', this.reExpanded);
				oBullet.onclick = function() {
					swapClass(this.parentNode, 'expandable', 'expanded');
					//this.parentNode.className = (this.parentNode.className == 'expandable') ? 'expanded' : 'expandable';
				};
			} else {
				removeClass(oLI, this.reExpandable);
				changeClass(oLI, 'nochildren', this.reExpanded);
			}
			oBullet.appendChild(document.createTextNode(sText));
			oLI.insertBefore(oBullet,oLI.firstChild);
		}
	}
}

ListLegionList.prototype._changeSelected = function(iId) {
	
}

function ListLegionInit() {
	if (!document.createElement) { return; }
	ListLegionAddEvents(fGEOBJLI('ul', /\blist_legion\b/));
}

function ListLegionAddEvents(aElems) {
	for(i in aElems) {
		if(isnumeric(i))
			oListLegion._newLegion(aElems[i]);
	}
}

function ListLegionChangeSelected(oEvent) {
	
}


var oListLegion = new ListLegion();
WindowOnload(ListLegionInit);
