﻿function Hash(){
	for( var i=0; i < arguments.length; i++ )
		for( n in arguments[i] )
			if( arguments[i].hasOwnProperty(n) )
				this[n] = arguments[i][n];
}

	// Hash.version = 1.00;	// Original version
	// Hash.version = 1.01;	// Added ability to initialize in the constructor
	// Hash.version = 1.02;	// Fixed document bug that showed a non-working example (thanks mareks)
	//Hash.version = 1.03;	// Removed returning this from the constructor (thanks em-dash)
	Hash.version = 1.04;	// Missed some 'var' declarations (thanks Twey)


	Hash.prototype = new Object();

	Hash.prototype.keys = function(){
		var rv = [];
		for( var n in this )
			if( this.hasOwnProperty(n) )
				rv.push(n);
		return rv;
	}

	Hash.prototype.length = function(){
		return this.keys().length();
	}

	Hash.prototype.values = function(){
		var rv = [];
		for( var n in this )
			if( this.hasOwnProperty(n) )
				rv.push(this[n]);
		return rv;
	}

	Hash.prototype.slice = function(){
		var rv = [];
		for( var i = 0; i < arguments.length; i++ )
			rv.push(
				( this.hasOwnProperty( arguments[i] ) )
					? this[arguments[i]]
					: undefined
			);
		return rv;
	}

	Hash.prototype.concat = function(){
		for( var i = 0; i < arguments.length; i++ )
			for( var n in arguments[i] )
				if( arguments[i].hasOwnProperty(n) )
					this[n] = arguments[i][n];
		return this;
	}
				
						
function CCollection() {
/* --CCollection object-- */
     var lsize = 0;

     this.add = _add;
     this.remove = _remove;
     this.isEmpty = _isEmpty;
     this.size = _size;
     this.clear = _clear;
     this.clone = _clone;
     this.getElementAt = _getElementAt;

     function _add(newItem) {
     /* --adds a new item to the collection-- */
          if (newItem == null) return;

          lsize++;
          this[(lsize - 1)] = newItem;
     }

     function _remove(index) {
     /* --removes the item at the specified index-- */
          if (index < 0 || index > this.length - 1) return;
          this[index] = null;

          /* --reindex collection-- */
          for (var i = index; i <= lsize; i++)
               this[i] = this[i + 1];

          lsize--;
     }

     function _isEmpty() { return lsize == 0 }     /* --returns boolean if collection is/isn't empty-- */

     function _size() { return lsize }     /* --returns the size of the collection-- */

     function _clear() {
     /* --clears the collection-- */
          for (var i = 0; i < lsize; i++)
               this[i] = null;

          lsize = 0;
     }

     function _clone() {
     /* --returns a copy of the collection-- */
          var c = new CCollection();

          for (var i = 0; i < lsize; i++)
               c.add(this[i]);

          return c;
     }
     
     function _getElementAt(index) 
     {
		/* --retrieves the element at the index in the collection-- */
		if (index < 0 || index > this.length - 1) return;
		return this[index];
     }
}


