/**
	* file: rf_core
	* author: Matryoshka Ltd.
	* date: June 6th, 2006
	* description:
	*     Core reusable components
	*    
 */

/// Common base class
function rf_Core() {
	
}
// methods
rf_Core.prototype.dispatchEvent = function(e) {
	return setTimeout(e, 0);
}
rf_Core.prototype.callIn = function(f, t) {
	return setTimeout(f, t);
}

/// Inheritance additions
/// June 7th, 2006

// Class inhertiance helper
// http://kevlindev.com/tutorials/javascript/inheritance/
function rf_extends(child, base) {
	function inheritance() {}
	inheritance.prototype = base.prototype; 
	
	child.prototype = new inheritance(); 
	child.prototype.constructor = child;
	child.baseConstructor = base;
	child.baseClass = base.prototype;
}
/// Array modifications
/// June 6th, 2006

// New Array alternative
function rf_Array() {
	// original array
	var a = new Array(rf_Array.arguments);
	
	// add the following methods:
	// getDefault
	a.getDefault = function(key, value) {
		return rf_get_default(this, key, value);	
	};
	// setDefault
	a.setDefault = function(key, value) {
		return rf_set_default(this, key, value);	
	};
	
	// return this array
	return a;
}

/// Array manipulation fuctions
/// June 6th, 2006

// Retrieve element or if not found, passed default value.
// 'null' in array is allowed by default.
// 	@param		container		- array
// 	@param		key				- array key
// 	@param		value			- default value
// 	@optional	exclusion		- list of values for which default can be returned 
function rf_get_default(container, key, value) {
	// TO DO: implement exclusion list
	var ret = container[key];
	if(typeof ret == "undefined") {
		ret = value;
	}
	return ret;
}
	
// Retrieve element or if not found, set with default and return value.
// 'null' in array is allowed by default.
//	@param		container		- array
//	@param		key				- array key
//	@param		value			- default value
//	@optional	exclusion		- list of values for which default can be returned
function rf_set_default(container, key, value) {
	// TO DO: implement exclusion list
	var ret = container[key];
	if(typeof ret == "undefined") {
		container[key] = value;
		ret = value;
	}
	return ret;
}
