//= require <mootools-core-1.3-full-nocompat>
//= require <uiframework/EventDispatcher>
//= require <uiframework/UICEvent>
/**
 * @class A factory used to create instances of objects
 * with default properties.
 *
 * @param {Class} generator The <code>Class</code> to be used when creating new instances.
 * @param {Object} properties The properties to set as defaults for all new instances.
 */
var ClassFactory = function(generator /* Class */, properties /* Object */){
	/**
	 * @ignore
	 */
	this.Extends = EventDispatcher;

	/**
	 * The <code>Class</code>  to be used when creating new instances.
	 * @type Class
	 */
	this.generator = null;
	/**
	 * The properties to set as defaults for all new instances.
	 * @type Object
	 */
	this.properties = null;
	/**
	 * The method called after a new instance 
	 * is created.  Passes the instance as the first 
	 * argument.
	 */
	this.callBack = null;

	/**
	 * @ignore
	 */
	this.initialize = function(generator /* Class */, properties /* Object */, callBack /* Function */)
	{
		this.generator = generator;
		this.properties = properties || {};
		this.callBack = callBack;
	};

	/**
	 * Creates a new instance of the <code>Class</code>
	 * specified in the <code>generator</code> property.
	 */
	this.newInstance = function()
	{
		var instance = new generator();
		for (var prop in this.properties)
		{
			instance[prop] = this.properties[prop];
		}
		if (this.callBack != null)
			this.callBack(instance);
		this.dispatchEvent(new UICEvent("instanceCreated", false, false, instance));
		return instance;
	}
};
