/*
	http://ejohn.org/blog/simple-javascript-inheritance/
*/
(function(){
	var isInitializing = false;
	var fnTest = /xyz/.test(function(){xyz;})? /\b_super\b/ : /.*/;
	
	// empty default constructor
	this.Obj = function(){};
	
	// function for extending other objects
	Obj.extend = function(prop){
		var _super = this.prototype;
		
		// instantiate a base class, do not run the init method
		isInitializing 	= true;
		var prototype 	= new this();
		isInitializing 	= false;
		
		for(var name in prop){
			// test if we overwriting an existing function 
			if(	typeof prop[name] 	== "function" &&
				typeof _super[name] == "function" &&
				fnTest.test(prop[name])){
	
				prototype[name] = (function(name, fn){
					return function(){
						var tmp = this._super;
						
						// add a new ._super() methode that is the same method
						// but on the super-class
						this._super = _super[name];

						// the method only have to be bound temporarily,
						// so we remove it when we're done executing
						var ret = fn.apply(this, arguments);
						this._super = tmp;
				
						return ret;
					};
        		})(name, prop[name]);
            }
            else{
            	prototype[name] = prop[name];
            }
		}
	
		// dummy constructor for the obj	
		function Obj(){
			// construct the obj in the init method
			if(	!isInitializing &&
				this.init){		
				this.init.apply(this, arguments);	
			}
		}
		
		// populate our constructed prototype object
		Obj.prototype = prototype;
		
		// enforce the constructor to be what we expect
		Obj.constructor = Obj;

		// make this class extendable
		Obj.extend = arguments.callee;

		return Obj;
	};
})();
