/*
Copyright (c) 2007, Meltmedia. All rights reserved.
version: 0.0.1
*/
/**
 * The meltmedia object is the single global object used by meltmedia's YAHOO YUI
 * Library extentions.  It contains utility function for setting up namespaces,
 * inheritance, and logging.  meltmedia.util, meltmedia.widget, meltmedia.example,
 * meltmedia.component are namespaces created automatically for and used by the library.
 *
 * @module meltmedia
 * @title  meltmedia Global
 */

if (typeof meltmedia == "undefined") {
    /**
     * The meltmedia global namespace object
     * @class meltmedia
     * @static
     */
    var meltmedia = {};
}

/**
 * Returns the namespace specified and creates it if it doesn't exist
 * <pre>
 * meltmedia.namespace("property.package");
 * meltmedia.namespace("meltmedia.property.package");
 * </pre>
 * Either of the above would create meltmedia.property, then
 * meltmedia.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>
 * meltmedia.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
 */
meltmedia.namespace = function() {
    var a=arguments, o=null, i, j, d;
    for (i=0; i<a.length; ++i) {
        d=a[i].split(".");
        o=meltmedia;

        // meltmedia is implied, so it is ignored if it is included
        for (j=(d[0] == "meltmedia") ? 1 : 0; j<d.length; ++j) {
            o[d[j]]=o[d[j]] || {};
            o=o[d[j]];
        }
    }

    return o;
};

meltmedia.namespace("util", "widget", "example", "component", "xml");
