
function ExpandMenu()
{
	
	var obj_list = new Array();
	var _itemElement;
	
	this.add = function (obj) {
		obj_list.push(obj);
		obj.setParent(this);
	}
	
	this.getItemElement = function () {
		return _itemElement;
	}
	
	this.i_view = function (pair, index) {
		pair.view(_itemElement);
	}
	
	this.view = function () {
		
		var str = '';
		
		var ExpandMenuID = Math.floor(Math.random() * 0x1000000).toString(16);
		
		document.write("<span id=\"ExpandMenu_" + ExpandMenuID + "\"></span>");
		
		_itemElement = document.getElementById("ExpandMenu_" + ExpandMenuID);
		
		obj_list.each(this.i_view);
	}
	
	this.count = function () {
		return obj_list.length;
	}
	
	this.i_collapseAll = function (pair, index) {
		pair.collapseAll();
	}
	
	this.collapseAll = function () {
		obj_list.each(this.i_collapseAll);
	}
	
	this.nodeExpand = function (node) {
		node.expand();
	}
	
	this.expand = function () {
		return true;
	}
	
}

/*
 *  innerHTML
 *  params
 */
function ExpandMenuItem(innerHTML,params)
{
	
	var obj_list = new Array();
	var _innerHTML;
	var _params;
	var _parent;
	var _elementBody;
	
	_innerHTML = innerHTML;
	_params = params;
	
	this.setValues = function (innerHTML,params) {
		_innerHTML = innerHTML;
		_params = params;
	}
	
	this.add = function (obj) {
		obj_list.push(obj);
		obj.setParent(this);
	}
	
	this.count = function () {
		return obj_list.length;
	}
	
	this.setParent = function (obj) {
		_parent = obj;
	}
	
	this.getBody = function () {
		return _elementBody;
	}
	
	this.i_view = function (pair, index) {
		pair.view(_elementBody);
	}
	
	this.toggle = function () {
		Element.toggle(_elementBody);
	}
	
	this.view = function (parentObject) {
		
		var elementHead = document.createElement('span');
		elementHead.innerHTML = _innerHTML;
		
		parentObject.appendChild(elementHead);
		
		if( obj_list.length > 0 ) {
			
			_elementBody = document.createElement('span');
			
			parentObject.appendChild(_elementBody);
			
			obj_list.each(this.i_view);
			
			elementHead.onclick = this.toggle.bindAsEventListener(this);
			
		}
		
	}
	
	this.i_collapseAll = function (pair, index) {
		Element.hide(_elementBody);
		pair.collapseAll();
	}
	
	this.collapseAll = function () {
		obj_list.each(this.i_collapseAll);
	}
	
	this.expand = function () {
		if(_elementBody) {
			Element.show(_elementBody);
		}
		_parent.expand();
	}
	
} // function ExpandMenuItem
