/**
 * The TOWNHALL object is the single global object used by the Townhall Library.  It
 * contains utility function for setting up namespaces.
 * @module townhall
 * @title  TOWNHALL Global
 */
/**
 * The TOWNHALL global namespace object.  If TOWNHALL is already defined, the
 * existing TOWNHALL object will not be overwritten so that defined
 * namespaces are preserved.
 * @class TOWNHALL
 * @namespace 
 * @static
 */
var TOWNHALL = function() {


    return {
		/**
		 * Returns the namespace specified and creates it if it doesn't exist
		 * <pre>
		 * TOWNHALL.namespace("util");
		 * </pre>
		 * The above would create TOWNHALL.util
		 *
		 * Be careful when naming packages. Reserved words may work in some browsers
		 * and not others. For instance, the following will fail in Safari:
		 * <pre>
		 * TOWNHALL.namespace("really.long.nested.namespace");
		 * </pre>
		 * This fails because "long" is a future reserved word in ECMAScript
		 *
		 * @method namespace
		 * @static
		 * @param  {String} arguments 1-n namespaces to create 
		 * @return {Object}  A reference to the last namespace object created
 		*/		
        namespace: function() {
            var a = arguments, o = null, i, j, d;
            for (i = 0; i < a.length; i = i + 1) {
                d = a[i].split(".");
                o = TOWNHALL;

                // TOWNHALL is implied, so it is ignored if it is included
                for (j = (d[0] == "TOWNHALL") ? 1 : 0; j < d.length; j = j + 1) {
                    o[d[j]] = o[d[j]] ||
							{};
                    o = o[d[j]];
                }
            }
        }
    };
} ();

