/*__________________________________________________________________________
	Adds an instance method to a class.
*/
Function.prototype.method = function (name, func) {
	this.prototype[name] = func;
	return this;
};

/*__________________________________________________________________________
	Indicates that one class inherits from another.
	It should be called after both classes are defined,
	but before the inheriting class's methods are added.
*/
Function.method('inherits', function (parent) {
	var d = 0, p = (this.prototype = new parent());
	
	/*__________________________________________________________________________
		Looks for the named method in its own prototype.
	*/
	this.method('superClass', function superClass(name) {
		var f, r, t = d, 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 += 1;
		r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
		d -= 1;
		return r;
	});
	return this;
});

/*__________________________________________________________________________
	Loops through the arguments; for each name, it copies a member
	from the parent's prototype to the new class's prototype. */
Function.method('swiss', function (parent) {
	for (var i = 1; i < arguments.length; i += 1) {
		var name = arguments[i];
		this.prototype[name] = parent.prototype[name];
	}
	return this;
});

