// debug.js v1.0 (c) concretegraphics.net

// var DEBUG_LEVEL = new Number();

function startDebugger(iDebugLevel) {
	var oDebug = new debug();
	oDebug.setLevel(iDebugLevel);
	if(oDebug.level !== false && oDebug.level > 0) {
		oDebug.createOutputWindow();
	}
	return oDebug;
}

function debug() {
}

debug.prototype.setLevel = function(iLevel) {
	if(!iLevel.isNaN) {
		this.level = iLevel;
	} else {
		this.level = false;	
		throw new Error('iLevel must be a number');
	}
}

debug.prototype.createOutputWindow = function() {
	this.outputWindow = document.createElement('div');
	this.outputWindow.setAttribute('id','debug');
	this.outputWindow.style.width = '460px'; 
	this.outputWindow.style.height = '200px';
	this.outputWindow.style.backgroundColor = 'black';
	this.outputWindow.style.color = 'white';
	this.outputWindow.style.position = 'absolute';
	this.outputWindow.style.top = 0;
	this.outputWindow.style.left = 0;
	this.outputWindow.style.fontSize = '10px'; 
	this.outputWindow.style.padding = '6px';
	this.outputWindow.style.opacity = '0.5';
	this.outputWindow.style.overflow = 'scroll';
	var str = "Debugger started:";
	var t = document.createTextNode(str);
	var br = document.createElement('br');
	this.outputWindow.appendChild(t);
	this.outputWindow.appendChild(br);
	document.body.appendChild(this.outputWindow);
}

debug.prototype.output = function (msg) {
	if(this.level > 0) {
		var br = document.createElement('br');
		this.outputWindow.insertBefore(br,this.outputWindow.childNodes[0]);
		var str = msg + "";
		var t = document.createTextNode(str);
		this.outputWindow.insertBefore(t,this.outputWindow.childNodes[0]);
	}
}

