/**
 * StarLight - A client side webpage framework
 *
 * @package StarLight
 * @author Icewind <icewind (at) derideal (dot) com>
 * @copyright 2009
 * @license http://www.gnu.org/licenses/gpl.html GNU Public License
 * @url http://blacklight.metalwarp.com/starlight
 * @version 0.1
 */

SLObject=function(){
	for(var name in this){
		if(name!='prototype'){
			this[name]=false;
		}
	}
	var newObject=function(param1,param2,param3){
		this.__init();
		ret=this.__construct(param1||false.param2||false,param3||false);
		if(ret){
			for(var name in this){
				ret[name]=this[name];
			}
		}
		return ret;
	};
	for(var name in SLObject.prototype){
		newObject.prototype[name]=SLObject.prototype[name];
	}
	newObject['extend']=SLObject.prototype['extend'];
	newObject['inherit']=SLObject.prototype['inherit'];
	return newObject;
}

SLObject.prototype={
	extend:function(){
		var newObject=new SLObject();
		newObject.inherit(this);
// 		var newObject=this.clone();
// 		newObject.prototype.__super=this.prototype.clone();
		return newObject;
	},
	inherit:function(object){
		this.prototype=object.prototype.clone();
		this.prototype.__super=this.prototype.clone();
		for(var name in object){
			if(name!='prototype' && name!='triggers' && name!='slots'){
				this[name]=object[name];
			}
		}
	},
	__construct:function(){
	},
	clone:function(){
		var newObject=new SLObject();
		for(var name in this){
			if((this[name].clone||false) && (name!="clone")){
				newObject[name]=this[name].clone();
			}else{
				newObject[name]=this[name];
			}
		}
		return newObject;
	},
	triggers:Object(),
	slots:Object(),
	addTrigger:function(name){
		this.triggers[name]=new SLTrigger();
	},
	removeTrigger:function(name){
		this.triggers[name]=false;
	},
	addSlot:function(name,funcName){
		this.slots[name]=new Object();
		this.slots[name].func=this[funcName];
		this.slots[name].call=function(){
			this.func.call(this.classObject);
		};
		this.slots[name].add=function(trigger){
			if(trigger){
				trigger.add(this);
			}
		};
		this.slots[name].remove=function(trigger){
			if(trigger){
				trigger.remove(this);
			}
		};
		this.slots[name].classObject=this;
	},
	removeSlot:function(name){
		this.slots[name]=false;
	},
	__init:function(){
		//this.addSlot('destruct','__destruct')
	},
	__destruct:function(){
		alert('destruct');
	}
}

SLTrigger=new SLObject();

SLTrigger.prototype.__construct=function(){
}

SLTrigger.prototype.callBacks=Array();
SLTrigger.prototype.trigger=function(){
	for(var name in this.callBacks){
		var callBack=this.callBacks[name];
		if(callBack){
			if(callBack['function']){
				callBack['function'].call(callBack['class']);
			}
		}
	}
}
SLTrigger.prototype.add=function(func,classObject){
	if(func){
	var callBack=Array();
	if((func.func||false) && (func.classObject||false)){
		callBack['function']=func.func;
		callBack['class']=func.classObject;
	}else{
		callBack['function']=func;
		callBack['class']=classObject;
	}
	this.callBacks[this.callBacks.length]=callBack;
	return callBack;
}

SLTrigger.prototype.remove=function(func,classObject){
	for(var name in this.callBacks){
		var callBack=this.callBacks[name];
		if(callBack['function']==func && callBack['class']==classObject){
			this.callBack[name]=false;
		}
	}
}}