/**
 * The TOTECS global namespace object.  If TOTECS is already defined, the
 * existing TOTECS object will not be overwritten so that defined
 * namespaces are preserved.
 * @class TOTECS
 * @static
 */
if (typeof TOTECS == "undefined" || !TOTECS) {
    var TOTECS = {};
}

/**
 * Returns the namespace specified and creates it if it doesn't exist
 * <pre>
 * TOTECS.namespace("property.package");
 * TOTECS.namespace("TOTECS.property.package");
 * </pre>
 * Either of the above would create TOTECS.property, then
 * TOTECS.property.package
 *
 * Be careful when naming packages. Reserved words may work in some browsers
 * and not others. For instance, the following will fail in Safari:
 * <pre>
 * TOTECS.namespace("really.long.nested.namespace");
 * </pre>
 * This fails because "long" is a future reserved word in ECMAScript
 *
 * For implementation code that uses YUI, do not create your components
 * in the namespaces defined by YUI (
 * <code>TOTECS.util</code>, 
 * <code>TOTECS.admin</code>, 
 * <code>TOTECS.oos</code>, 
 *
 * @method namespace
 * @static
 * @param  {String*} arguments 1-n namespaces to create 
 * @return {Object}  A reference to the last namespace object created
 */
TOTECS.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; i=i+1) {
        d=(""+a[i]).split(".");
        o=TOTECS;

        // TOTECS is implied, so it is ignored if it is included
        for (j=(d[0] == "TOTECS") ? 1 : 0; j<d.length; j=j+1) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }

    return o;
};	

/**
 * Initializes the global by creating the default namespaces.
 * @method init
 * @static
 * @private
 */	
(function() {
    TOTECS.namespace("util", "admin", "oos");
	TOTECS.namespace('TOTECS.admin.product');
	TOTECS.namespace('TOTECS.admin.user');
	TOTECS.namespace('TOTECS.admin.order');
	TOTECS.namespace('TOTECS.admin.website');
	TOTECS.namespace('TOTECS.admin.marketing');
	TOTECS.namespace('TOTECS.admin.statistics');
	TOTECS.namespace('TOTECS.admin.cms');
	TOTECS.namespace("TOTECS.oos.marketing");
	TOTECS.namespace("TOTECS.oos.search");
	TOTECS.namespace('TOTECS.portal_util');
	TOTECS.namespace('TOTECS.portal_util.project');
	TOTECS.namespace('TOTECS.retail');
	TOTECS.namespace('TOTECS.locale');
})();

