/**
 * Get reference to nested object starting from "window" using a dotted notation.
 * 
 * @param {String} name refernce name in dotted notation.
 */
Object.getFromDotRef = function (name) {
    var names = name.split(".");
    for (var i = 0, nl = names.length, cObj = window; i < nl && (cObj = cObj[names[i++]]);) {}
    return cObj || null;
};

Object.setToDotRef = function (name, value) {
    var names = name.split("."),
        i,
        nl = names.length - 1,
        cObj = window,
        nextObj;

    for (i = 0; i < nl; i++) {
        nextObj = cObj[names[i]];
        if (nextObj === undefined) {
            nextObj = {};
            cObj[names[i]] = nextObj;
        }
        cObj = nextObj;
    }

    if (cObj[names[i]] !== undefined) {
        console.error("registerModule: possible namespace collision object %s overwritten!", name);
    }
    cObj[names[i]] = value;
    return value;
};

/**
 * Extend a class.
 *
 * Example:
 *
 * var A, B; // two classes, B will subclass A.
 *
 * A = function() {
 *     this.a = "a's constructor";
 * };
 *
 * A.prototype = {
 *     aMethod: function () {
 *        console.debug("a method on class A");
 *     },
 *
 *     // B class will override this method
 *     bMethod: function () {
 *         this.bProperty = "alma";
 *     }
 * };
 *
 * B = $.extend(A, {
 *     constructor: function () {
 *         // superclass' construcor call, also passing arguments:
 *         B.superclass.constructor.apply(this, arguments);
 *
 *         console.asert(this.a === "a's constructor");
 *         console.debug("object with class B constructed, prev. assertion should pass");
 *     },
 *
 *     bMethod: function () {
 *         B.superclass.bMethod.call(this); // call superclass' method
 *
 *         this.cMethod(); // call "do nothing" method...
 *
 *         console.assert(this.bProperty === "alma");
 *         console.debug("bMethod() on class B prev. assertion should pass");
 *     },
 *
 *     cMethod: function () {
 *         // do nothing...
 *     }
 * });
 *
 * var b = new B();
 * b.aMethod(); // aMethod inherited form A object
 * b.bMethod(); // bMethod of B object
 */
Object.extendClass = function (superCls, overrides) {
    var defaultConstructor = Object.prototype.constructor,
        subCls = overrides.constructor !== defaultConstructor ?
            overrides.constructor :
            function () {
                superCls.apply(this, arguments);
            },
        SuperClone = function () {},
        subClsProto,
        method,
        superClsProto = superCls.prototype;

    SuperClone.prototype = superClsProto;
    subClsProto = subCls.prototype = new SuperClone(); // clone superclass' prototype
    subClsProto.constructor = subCls;
    subCls.superclass = superClsProto;

    if (superClsProto.constructor === defaultConstructor) {
        superClsProto.constructor = superCls;
    }

    for (method in overrides) if (overrides.hasOwnProperty(method)) {
        subClsProto[method] = overrides[method];
    }

    return subCls;
}
