/**
 * This code was originally created by http://www.qloud.com/. Some of the code might have been added or changed.
 * You can view the original source here: http://www.qloud.com/js/Model/Environment.js
 */

/**
 * The environment object is the central data storage object
 * Note: this is a singleton object
 */
function Environment()
{
	this.vars = new Array();
	
	/**
	 * Sets a variable named <key> with value <data>
	 * @param key The name of the variable
	 * @param data The value to assign to the variable
	 */
	this.set = function(key, data)
	{
		this.vars[key]=data;
		if (Config.debug==2)
		{
			trace('Environment.set('+key+', '+data+'), type: '+typeof(data));
		}
	}
	
	/**
	 * Returns the value of the variable named <key>
	 * @param key The name of the variable
	 */
	this.get = function(key)
	{
		return this.vars[key];
	}
	
	/**
	 * Imports an array into the environment. This function acts like an interface 
	 * for the Environment.set method
	 * @param array arr
	 */
	this.importArray = function (arr)
	{
		if (typeof(arr)!='object')
		{
			return;
		}
		for (var i in arr)
		{
			Environment.getInstance().set(i,arr[i]);
		}
		return;
	}
}

// Initialize the __instance__ variable
Environment.__instance__ = null;

/**
 * Returns a reference to the instance of the Environment object
 */
Environment.getInstance = function()
{
	if (Environment.__instance__==null)
	{
		Environment.__instance__ = new Environment();
	}
	return Environment.__instance__;
}
