//  http://www.crockford.com/javascript/inheritance.html

Function.prototype.method = function (name, func)
{
    this.prototype[name] = func;
    return this;
};

Function.method('inherits', function (parentClass)
{
    var depthsByMethodName = {};
    var bottommostPrototype = (this.prototype = new parentClass());
    this.inkinruParentClass = parentClass;
    var currentClass = this;

    this.method('uber', function uber (name) {

        if (!(name in depthsByMethodName))
            depthsByMethodName[name] = 1;

        var method = currentClass.prototype[name];
        var currentDepth = depthsByMethodName[name], v = parentClass.prototype;
        var c = currentClass.inkinruParentClass;

        while (true)
        {
            if (c.prototype[name] != method)
            {
                method = c.prototype[name];

                if (--currentDepth == 0)
                    break;
            }

            c = c.inkinruParentClass;
        }

//        if (currentDepth)
//        {
//            var cls = currentClass.inkinruParentClass;
//
//            while (currentDepth--)
//                cls = cls.inkinruParentClass;
//
//            method = cls.prototype[name];
//        }
//        else
//        {
//            method = bottommostPrototype[name];
//
//            if (method == this[name])
//                method = v[name];
//        }

        depthsByMethodName[name] += 1;
        var result = method.apply(this, Array.prototype.slice.apply(arguments, [1]));
        depthsByMethodName[name] -= 1;
        return result;
    });
    return this;
});

