/******************************************************
 * JKow
 *	New JKow with namespacing modelled on Yahoo UI
 ******************************************************/

/******************************************************
 * JKow
 *	The root JKow object
 ******************************************************/
if (typeof JKow == "undefined" || JKow == null){
	var JKow = {};
	var JKOW_ROOT_NAMESPACE = "JKow";
}

/******************************************************
 * JKow
 *	Configuration functions	
 ******************************************************/
JKow.setConfig = function(name, value){
	JKow.Config[name] = value;
}

JKow.getConfig = function(name){
	return ("undefined" != typeof JKow.Config[name]) ? JKow.Config[name] : null;
}

JKow.setDebug = function(enable){
	JKow.setConfig('DEBUG', enable);
}


/******************************************************
 * Initialize namespaces 
 ******************************************************/
JKow.namespace = function(namespaces){
	var J = null;	
	var segs = null;

	for (var i = 0; i < namespaces.length; ++i){
		segs = namespaces[i].split('.');
		J = JKow;
		for (var j = 0; j < segs.length; ++j){
			if ((j == 0) && (segs[j] == JKOW_ROOT_NAMESPACE)) continue;

			if (typeof J[segs[j]] == "undefined"){ J[segs[j]] = {}; }
			J = J[segs[j]];
		}
	}		
}

/******************************************************
 * JKow.extend
 *
 *	Provides basic single class inheritance	
 *
 *	Note: fix up behaviour of _super as it creates
 *	it's own scope
 ******************************************************/
JKow.extend = function(parent_class, child_members){
	var f = function(params){
		//alert('extending');
		var _parent_class = parent_class;
		var _child_members = child_members;
		result_object = new _parent_class(params);
		result_object._super = {};
		/* copy the child members and preserve functions of the super class */
		for(var k in _child_members){
			if (typeof result_object[k] != "undefined"){ result_object._super[k] = result_object[k]; }
			result_object[k] = _child_members[k];
		}	
		//alert('extended');
		return result_object;
	}
	return f; 
}

/******************************************************
 * Initialize namespaces 
 ******************************************************/
JKow.namespace(["Config", "Widget", "Util"]);
JKow.setDebug(true);
