//
// GlobalScope
//

Framework.GlobalScope = {
	
	counter: 1,
	prefix: 'frameworkGlobalScope',
	maxTries: 10,
	
	/**
	 * Safely add an object to the global scope.
	 * The global name of the object will be returned.
	 * 
	 *  @param object Object
	 *  @return string
	 */
	register: function(object, objName) 
	{
		// debug("Framework.GlobalScope.register()");
		var i = 0;
		if (objName)
		{
			if (window[objName])
			{
				throw "Couldn't register object with name " + objName + " in Framework.GlobalScope.register()";
			}
		}
		else
		{
			do
			{
				i = i + 1;
				this.counter = this.counter + 1;
				objName = this.prefix + this.counter;
				if (i > this.maxTries)
				{
					// debug(object);
					throw "Couldn't register object in Framework.GlobalScope.register()";
				}
			}
			while(window[objName]);
		}
		
		window[objName] = object;
		
		//debug(objName);
		return objName;
	},
	
	_eoo: true

};