(function() {
	FF.Debug = {};
	var callbacks = [];
	var on = true;
	
	FF.Debug.print = function() {
		if (on) {
			for (var i=0; i<callbacks.length; i++) {
				for (var j=0; j<arguments.length; j++) {
					callbacks[i]('' + arguments[j]);
				}
			}
		}
	};
	FF.Debug.printobj = function(obj) {
		var propVals = [];
		for (var k in obj) {
			if (obj.hasOwnProperty(k)) {
				propVals.push(k + ":'" + obj[k] + "'");
			}
		}
		FF.Debug.print("{" + propVals.join(", ") + "}");
	};
	FF.Debug.setEnabled = function(isOn) {
		on = isOn;
	};
	FF.Debug.on = function() { FF.Debug.setEnabled(true); };
	FF.Debug.off = function() { FF.Debug.setEnabled(false); };
	
	FF.Debug.connect = function(cb) {
		if (callbacks.indexOf(cb) == -1) {
			callbacks.push(cb);
		}
	};
	FF.Debug.disconnect = function(cb) {
		callbacks = callbacks.sans(cb);
	};
	
	FF.Debug.createElement = function() {
		var D = FF.Dom;
		
		var list = D.create('ul', {style: "font-family: monospace; font-size: 10pt; " +
				"white-space: pre; padding-left: 0; max-height: 185px; overflow: auto;"});
		list.style.display = 'none';
		var shown = false;
		
		var el = D.create('div', {style: "position: absolute; bottom: 0; left: 0; " +
				"width: 100%; border-top: 1px solid #999"}, [
			list,
			D.create('span', {style: "cursor: pointer;", onclick: function() {
				shown = !shown;
				list.style.display = shown ? 'block' : 'none';
			}}, ["***"])
		]);
		
		FF.Debug.connect(function(str) {
			list.appendChild(D.create('li', {}, [str]));
		});
		
		return el;
	};
})();

var Debug = FF.Debug;