/**
 * 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
 */

function SLErrorHandler(error){
	new SLError(error.level,error.discription);
	return true;
}

BLErrorHandler.register('',SLErrorHandler);

var SLErrorList=Array();
var SL_ERROR_DEBUG=0;
var SL_ERROR_USER=1;
var SL_ERROR_WARNING=2;
var SL_ERROR_ERROR=3;
var SL_ERROR_CRITICAL=4;
SLError=function(level,discription){
	this.level=level;
	this.discription=discription;
	this.holder=false;
	this.notification=false;
	SLErrorList[SLErrorList.count]=this;
	this.notify();
}

SLError.prototype={
	alert:function(){
		var type=this.getTypeName();
		alert('Error('+type+'): '+this.discription);
	},
	getTypeName:function(){
		type="undefined";
		switch(this.level){
			case SL_ERROR_DEBUG:
				type="Debug Message";
				break;
			case SL_ERROR_USER:
				type="User Error";
				break;
			case SL_ERROR_WARNING:
				type="Warning";
				break;
			case SL_ERROR_ERROR:
				type="Error";
				break;
			case SL_ERROR_CRITICAL:
				type="Critical Error";
				break;
		}
		return type;
	},
	notify:function(){
		var time=(this.level==SL_ERROR_DEBUG && this.level)?2000:0;
		var type=this.getTypeName();
		var text=type+': '+this.discription;
		this.notification=new SLNotification(text,time);
	}
}