/*************************************************************************

Name:	CoreJS
Desc:	Base for all JAVA classes
		allows class inheritance, extension, supering, etc
		
		
*************************************************************************/


Function.prototype._extends = function(parent) {

	var d = {};
	var p = (this.prototype = new parent());
	
	//call using: this._super('func');
	this.prototype._super = function(name) {
		if (!(name in d)) {
			d[name] = 0;
		}
		var f;
		var r;
		var t = d[name];
		var v = parent.prototype;
		
		if (t) {
			while (t) {
				v = v.constructor.prototype;
				t -= 1;
			}
			f = v[name];
		} else {
			f = p[name];
			if (f == this[name]) {
				f = v[name];
			}
		}
		d[name] += 1;
		r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
		d[name] -= 1;
		return r;
	}
}

//this is how you extend a class
//ControlJS._extends(myclass);

//this is how you call a super function
//this._super("funcName", arg)

/*
function BaseClass(config) {this.construct(config);}
BaseClass.prototype.construct = function(config) {	if(config){alert('construct'+config);}}
BaseClass.prototype.getId = function() {	return 1;	}
BaseClass.prototype.getName = function() {	return "BaseClass(" + this.getId() + ")";	}

function SubClass(config) {this.construct(config);}
SubClass._extends(BaseClass);
SubClass.prototype.getId = function() {		return 2;	}
SubClass.prototype.getName = function() {	return "SubClass(" + this.getId() + ") extends " + this._super("getName");}

function TopClass(config) {this.construct(config);}
TopClass._extends(SubClass);
TopClass.prototype.getId = function() {		return this._super("getId");	}
TopClass.prototype.getName = function() {	return "TopClass(" + this.getId() + ") extends " + this._super("getName");}

var x = new TopClass('x');
alert(x.getName());
/**/






/*

//core constructor
//NOTE: CoreJS does not construct, but extended classes do
function CoreJS() {}

CoreJS.prototype.construct = function(obj) {}

//extend is a function thats called on the constructor, ie: CoreJS.extend()
CoreJS.extend = function(def) {
	var classDef = function() {
		if (arguments[0] !== CoreJS) {
			this.construct.apply(this, arguments);
		}
	}
	
	var proto = new this(CoreJS);
	var superClass = this.prototype;
	
	for (var n in def) {
		var item = def[n];                      
		if (item instanceof Function) {
			item['_super'] = superClass;
		}
		proto[n] = item;
	}
	
	classDef.prototype = proto;
	
	//Give this new class the same static extend method    
	classDef.extend = this.extend;      
	return classDef;
	
}



/**/