// This file is a compact, standalone, version of grvClass.js
// This file only supports the single inheritance version of Extends()

Class(GrvObject); //special root class
function GrvObject(){
  this.souper = function() {
    var superMethod = this.souper.caller.souper;
    return (superMethod) ? superMethod.apply( this, arguments ) : null;
  }
}

function grvExtends( superClass ){ //link super and sub classes
  this.baseClass.prototype = (this==GrvObject) ? null : superClass.prototype;
  this.prototype           = new this.baseClass();
  if (this.baseClass.prototype)
    for (var x in this.prototype) { // iterate over all properties
      var m = this          .prototype[x]; // the method
      var s = this.baseClass.prototype[x]; // its super
      if (s && (s!=m) && (m instanceof Function) && (s instanceof Function))
        m.souper = s;
  }
}

function grvFuncName(f){ //extract name from function source
  var s = f.toString().match(/function\s*(\S*)\s*\(/)[1];
  return s ? s : "anonymous";
}

function Class( theClass ){
  var originalClass = theClass;
  self[ grvFuncName(theClass) ] = theClass = function(){
    arguments.callee.prototype.konstructor.apply( this, arguments );
  }
  theClass.baseClass = originalClass;
  theClass.Extends   = grvExtends;//so we can call Extends as a method
  theClass.Extends(GrvObject);//required here even if overridden later
  return theClass;
}
