//-- Create a "list" class based upon the standard javascript array, but extended.
//-- nice for collections.

function CList ()
{

	// properties
	this.items = new Array()
	
	// methods
	this.item = _item;
	this.replace = _replace;
	this.length = _length;
	this.add = _add;
	this.remove = _remove;
	this.removeAll = _removeAll;	
	this.toString = _toString;
		
	function _toString ()
	{
		var s = '';
	
		for(var i=0; i < this.items.length; i++) {
			if (this.items[i].toString) {
				s += this.items[i].toString();
			}
		}
		
		return s;
	}


	function _replace (idx, obj)
	{
		this.items[idx] = obj;
		return obj;
	}

	function _item (idx)
	{
		return (this.items[idx]);
	}


	function _length ()
	{
		return (this.items.length);
	}


	function _add (obj)
	{
		this.items[this.items.length] = obj;
		return obj;	
	}


	function _remove (idx)
	{
		idx = parseInt(idx);

		if (!this.items[idx]) {return null;}

		var obj = this.items[idx];

		if ((idx + 1) == this.items.length) {
			if (this.items.length == 1) {
				this.removeAll();
			} else {
				this.items = this.items.slice(0, -1); // remove last array element
			}
		} else if (idx == 0) {
				this.items = this.items.slice(1);
		} else {		
			var arr1 = this.items.slice(0, idx);		
			var arr2 = this.items.slice(idx+1);
			this.items = arr1.concat(arr2);
		}

		return obj;	
	}


	function _removeAll ()
	{
		this.items = new Array();
	}

		
}
