/////////////////////////////////////////////////////////////////////////
//  Dictionary, find object by using key, key is stored in an array list
/////////////////////////////////////////////////////////////////////////
Dictionary = function()
{ 
	this.keys = new Array();
	this.count = 0;
}
Dictionary.prototype.objType == "Dictionary";
Dictionary.prototype.add = function(key, value)
{	
	if(this[key] == null)	
	{
		this.keys[this.keys.length] = key;
		this.count ++;
	}	
	this[key] = value;	
}

Dictionary.prototype.clone = function(clonedObj, parentObject)
{
	var tmpDictionary = new Dictionary();
	for (var i = 0; i < this.keys.length; i++)
		tmpDictionary.add(this.keys[i], this[this.keys[i]]);
	return tmpDictionary;
}

Dictionary.prototype.addAtIndex = function(key, value, idx)
{	
	if(this[key] == null)	
	{
		if(!idx) idx = 0;
		var a1 = this.keys.slice(0, idx);	
		var a2 = this.keys.slice(idx);
		a1.push(key);
		this.keys = a1.concat(a2);
		this.count ++;
	}	
	this[key] = value;	
}
Dictionary.prototype.remove = function(key)
{	
	this[key] = null;
	var idx = null;
	
	for (var i = 0; i < this.keys.length; i++) 
	{
		if(this.keys[i] == key)
			idx = i;
	}
	
	if (idx != null)
	{
		var a1 = this.keys.slice(0, idx);	
		var a2 = this.keys.slice(idx);
		a2.shift();
		this.keys = a1.concat(a2);
		this.count --;
	}
}
Dictionary.prototype.clear = function()
{
	for(var i = 0; i<this.keys.length; i++)
	{
		key = this.keys[i];			
		this[key] = null;
	}
	this.keys = new Array();
	this.count = 0;
}

Dictionary.prototype.copy = function()
{
	var val = new Dictionary();
	for (var i = 0; i < this.keys.length; i++) 
	{
		val.add(this.keys[i],this[this.keys[i]]);
	}
	
	return val;
}

Dictionary.prototype.containsKey = function(key)
{
	for (var i = 0; i < this.keys.length; i++) 
	{
		if(this.keys[i] == key)
			return true;
	}
	return false;
}

Dictionary.prototype.containsValue = function(value)
{
	for (var i = 0; i < this.keys.length; i++) 
	{
		if(this[this.keys[i]] == value)
			return true;
	}
	return false;
}

//End Dictionary

