function Debugger(){}

Debugger.prototype.trace = function(str){
	if(typeof this.debugpanel == "undefined"){
		var debugpanel = document.createElement("DIV");
		debugpanel.setAttribute("id", "debug_panel");
		debugpanel.setAttribute("style", "top:10px; padding:0; left:10px; position:absolute; background:#FFF; z-index:999999; border:1px solid #000;");
		
		var titlebar = document.createElement("DIV");
		titlebar.setAttribute("id", "debug_title");
		titlebar.setAttribute("style", "padding:0; background:#000; width:100%; color:#FFF; text-align:center; font-size:8pt; cursor:pointer;");
		debugpanel.appendChild(titlebar);
		
		var textarea = document.createElement("TEXTAREA");
		textarea.cols = (this.numcols) ? this.numcols : 40;
		textarea.rows = (this.numrows) ? this.numrows : 10;
		textarea.setAttribute("style", "color:#000; background:#FFF; font-size:8pt; font-family:Arial; margin:5px; padding:3px;");
		debugpanel.appendChild(textarea);
		
		var _body = document.getElementsByTagName("body")[0];
		_body.appendChild(debugpanel);
		titlebar.innerHTML = "Debug panel";
		
		this.rowcounter = 0;
		this.globalcounter = 0;
		this.textarea = textarea;
		this.title = titlebar;
		this.debugpanel = debugpanel;
	}
	this.rowcounter++;
	this.globalcounter++;	
	
	if(this.rowcounter == this.textarea.rows){
		this.rowcounter = 0;
		this.textarea.value = "";
	}
	
	this.textarea.value += this.globalcounter + ":  " + str.toString() + "\n";
	//if(doc != null && typeof(doc) != "undefined")doc.draggable(this.debugpanel);
}

Debugger.prototype.clear = function(){
	if(this.rowcounter)		this.rowcounter = 0;
	if(this.textarea)		this.textarea.value = "";
	if(this.globalcounter)	this.globalcounter = 0;
}

Debugger.prototype.rows = function(val){(this.textarea) ? this.textarea.rows = val : this.numrows = val;}
Debugger.prototype.cols = function(val){(this.textarea) ? this.textarea.cols = val : this.numcols = val;}

var debug = new Debugger();

//debugging console in firefox
if(jQuery){
	jQuery.fn.log = function (msg) {
		console.log("%s: %o", msg, this);
		return this;
	};
}
