/**
 * Mocha Inheritance -- Javascript prototype inheritance reduced to the max.
 * 
 * Chris Zumbrunn <chris@zumbrunn.com> http://zumbrunn.com
 * version 0.3, March 26, 2007
 */

Function.prototype.inherit = function(fnc) {
    var constr = this;
    var Constructor = function(){
        if (fnc)
            fnc.apply(this, arguments);
        constr.apply(this, arguments);
    };
    Constructor.prototype = new (fnc || this)();
    Constructor.prototype.constructor = fnc || this;
    return Constructor;
};

Function.prototype.applySuper = function(method,obj,args) {
    var that = arguments.callee.caller.__parent || this;
    do {
        if (that.prototype[method] && that.prototype[method] != obj[method]
              && that.prototype[method] != arguments.callee.caller) {
            that.prototype[method].__parent = that;
            return that.prototype[method].apply(obj,args);
        }
        that = that.prototype.constructor;
    } while (that != Object);
};



// end of the magic 20 lines of code, the rest is just some additional syntactic sugar

Function.prototype.callSuper = function(method,obj) {
    var args = Array.prototype.slice.apply(arguments,[2]);
    var that = arguments.callee.caller.__parent || this;
    do {
        if (that.prototype[method] && that.prototype[method] != obj[method]
              && that.prototype[method] != arguments.callee.caller) {
            that.prototype[method].__parent = that;
            return that.prototype[method].apply(obj,args);
        }
        that = that.prototype.constructor;
    } while (that != Object);
};

Function.prototype.extend = function(arg) {
    for (var i in arg)
        this.prototype[i] = arg[i];
    return this;
};
