var _typeof = function(x){
	return x && x._type ? x._type : typeof x;
}

var _extend = function(x, y){
	for (var p in y){
		try {
			x[p] = y[p];
		
			if (x[p] != null && typeof x[p] == 'object' && p != '_owner'){
				try { x[p]._owner = x; } catch (e){}
			}
		} catch (ex){}
	}

	return x;
}

var _merge = function(x, y){
	return _extend(extend({}, x), y);
}

var _indexof = function(a, x, n){
	if (!n){ n = 0; }
	for (var i = n; i < a.length; i++){
		if (a[i] == x){
			return i;
		}
	}
	
	return -1;
}

var isnumber = function(x){
	return (typeof x == 'number');
}

var NameSpace = function(p){
	_extend(p, {
		_type : 'namespace',
		extend : function(x){
			return _extend(this, x);
		},
		merge : function(x){
			return merge(this, x);
		}
	});
	
	for (var a in p){
		if (p[a] != null && typeof p[a] == 'object' && a != '_owner'){
			p[a]._owner = p;
		}
	}
	
	if (p._initialize){
		var n = p._initialize();
	}
	
	return (n ? _extend(n, p) : p);
}

var Class = function(p){
	var n = function(){
		if (this._initialize){
			var n = this._initialize.apply(this, arguments);
			
			if (n && n != this){
				return _extend(n, this);
			}
		}
	}
	
	_extend(n, {
		_type : 'class',		
		_constructor : 	Class
	});
	
	n.prototype = _extend(p, {
		_constructor : n,		
		extend : function(x){
			return _extend(this, x);
		},		
		merge : function(x){
			return merge(this, x);
		}
	});
	
	return n;
}
