
/**
 * The MarketWatch global namespace
 * @constructor
 */
var MKTW = window.MKTW || {};

/**
 * Returns the namespace specified and creates it if it doesn't exist
 *
 * MKTW.namespace("property.package");
 * MKTW.namespace("MKTW.property.package");
 *
 * Either of the above would create MKTW.property, then
 * MKTW.property.package
 *
 * @param  {String} sNameSpace String representation of the desired 
 *                             namespace
 * @return {Object}            A reference to the namespace object
 */
MKTW.namespace = function( sNameSpace ) {

    if (!sNameSpace || !sNameSpace.length) {
        return null;
    }

    var levels = sNameSpace.split(".");

    var currentNS = MKTW;

    // MKTW is implied, so it is ignored if it is included
    for (var i=(levels[0] == "MKTW") ? 1 : 0; i<levels.length; ++i) {
        currentNS[levels[i]] = currentNS[levels[i]] || {};
        currentNS = currentNS[levels[i]];
    }

    return currentNS;
};

