function Debugger () {
	
	var canvas = null;
	var panel = null;
	var list = null;
	var clearButton = null;
	var hideButton = null;
	var showButton = null;
	
	this.create = function () {
		canvas = document.createElement("DIV");
		panel = document.createElement("DIV");
		list = document.createElement("DIV");
		
		clearButton = document.createElement("BUTTON");
		hideButton = document.createElement("BUTTON");
		showButton = document.createElement("BUTTON");
		
		canvas.className = "debug-canvas";
		panel.className = "debug-panel";
		list.className = "debug-list";
		
		clearButton.innerHTML = "clear";
		hideButton.innerHTML = "hide";
		showButton.innerHTML = "show";
		
		panel.appendChild(clearButton);
		panel.appendChild(hideButton);
		panel.appendChild(showButton);
		
		canvas.appendChild(panel);
		canvas.appendChild(list);
		document.body.appendChild(canvas);

		clearButton.onclick = new Function("_debugger.clear()");
		hideButton.onclick = new Function("_debugger.hide()");
		showButton.onclick = new Function("_debugger.show()");
		
		this.show();
	}
	
	this.push = function (message) {		
		list.innerHTML += "<div class='debug-message'>" + message + "</div>";
	}
	
	this.clear = function () {
		list.innerHTML = "";
	}
	
	this.hide = function () {
		list.style.display = "none";
		hideButton.style.display = "none";
		showButton.style.display = "block";
	}

	this.show = function () {
		list.style.display = "block";
		hideButton.style.display = "block";
		showButton.style.display = "none";		
	}

	this.create();
}

var _debugger = null;

function getDebugger() {
	if (!_debugger) {
		_debugger = new Debugger();
	}
	
	return _debugger;
}

function debug(message) {
	getDebugger().push(message);
}