/**
 * 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
 */
 
SLBase=new SLObject();

SLBase.prototype.__init=function(){
	this.addTrigger('loaded');
	this.addTrigger('parsed');
	this.addSlot('destruct','__destruct');
	this.addSlot('load','load');
	this.addSlot('render','render');
}

SLBase.prototype.__construct=function(source){
	this.loadSource(source);
}

SLBase.prototype.type='';
SLBase.prototype.loaded=false;
SLBase.prototype.childs=Array;
SLBase.prototype.element=false;
SLBase.prototype.loadSource=function(source){
	if (source){
		if (source.tagName){
			this.loadNode(source);
		}else if(source.substr){
			this.loadXML(source)
		}
	}
}
SLBase.prototype.loadXML=function(url){
	url=parseUri('%slroot%/'+url);
	this.loader=new BLXMLLoader(this);
	this.loader.setCallBack(this.parseXML);
	this.loader.load(url);
}
SLBase.prototype.parseXML=function(request){
	dom=request.responseXML;
	node=dom.documentElement;
	if (node.tagName==this.type){
		this.loadNode(node);
	}else{
		new SLError(SL_ERROR_ERROR,'XML File('+request.url+') does not contain valid '+this.type+' definition');
	}
}
SLBase.prototype.loadNode=function(node){
	if (node.tagName==this.type){
		if (node.getAttribute('src')){
			this.loadXML(node.getAttribute('src'));
		}else{
			this.node=node;
		}
		this.loaded=true;
		this.triggers.parsed.trigger();
	}else{
		new SLError(SL_ERROR_ERROR,'Supplied DOM Node does not contain valid '+this.type+' definition');
	}
}
SLBase.prototype.load=function(){
}
SLBase.prototype.render=function(){
	if (!this.isLoaded()){
		new SLError(SL_ERROR_WARNING,this.type+' object is not loaded yet');
	}else{
	}
}
SLBase.prototype.isLoaded=function(){
	loaded=this.loaded;
	childs=this.getChilds();
	if (loaded){
		for(index in childs){
			loaded=loaded & childs[index].isLoaded;
		}
	}
	return loaded;
}

SLBase.prototype.__destruct=function(){
	alert(this.type);
}

SLBase.prototype.getContentBox=function(){
	var contentBox=(document.getElementsById('contentBox')||document.getElementsByTagName('body').item(0));
}