
function Debug(){
		this.load();
}

Debug.prototype.load = function(){
		this._debugWindowOpened = false;
		this._debugWindow = new Object();
		this._debugNode = new Object();
		try{
			if(debugVar !== undefined){
				this._debugVar = debugVar;
				this.addDebug();
			}
		}catch(e){}
}

Debug.prototype.addDebug = function(){
	this._openDebugWindow();
	for (var i in this._debugVar){
		this.writeln(this._debugVar[i]);
	}
}

Debug.prototype._openDebugWindow = function(){
	if(this._debugWindowOpened ==  false){
		try{
			this._debugWindow = window.open("","debugWin","toolbar=no,scrollbars=no,resizable=yes,width=800,height=600");
			this._debugNode = this._debugWindow.document.getElementById('DebugNode');
			if(this._debugNode !== undefined && this._debugNode !== null){
				this._focusOnDebug();
				this._debugWindowOpened = true;

				var _this = this;
			//	this._debugWindow.opener.onunload = function(){_this._closeDebugWindow();};
			}else{

				var debugNode = this._debugWindow.document.createElement('div');
				var preNode = this._debugWindow.document.createElement('pre');
				preNode.innerHTML = "<h1 style='font-size:12px;color:#666'>DEBUG</h1><hr style='color:#666' size=1 width='100%'>";
				preNode.id = 'DebugNode';
				debugNode.style.width='780px';
				debugNode.style.height='560px';
				debugNode.style.overflow='auto';
				debugNode.style.borderBottom='#666 1px solid';
				debugNode.appendChild(preNode);
				
				
				/*var debugNode = this._debugWindow.document.createElement('pre');*/
				
				this._debugWindow.document.getElementsByTagName('body')[0].appendChild(debugNode);
				this._debugNode = this._debugWindow.document.getElementById('DebugNode');
				this._focusOnDebug();
				this._debugWindowOpened = true;
				
				var _this = this;
			//	this._debugWindow.opener.onunload = function(){_this._closeDebugWindow();};
			}
		}catch(e){
			alert(e);
		}
	return true;
	}
	return false;
}

Debug.prototype._closeDebugWindow = function(){
	if(this._debugWindowOpened)this._debugWindow.close();
}

Debug.prototype.writeln = function(sMesg){
		this._debugNode.innerHTML += sMesg+"<br />";
}

Debug.prototype.colorize_string = function(sMesg){
	var s = new String(sMesg);
	s = s.replace("[","[<font color='red'>");
	s = s.replace("]","[</font>");
	s = s.replace("Array","<font color='blue'>Array</font>");
	s = s.replace("=>","<font color='#556F55'>=></font>");
	return s;
}

Debug.prototype._focusOnDebug = function(){
	this._debugWindow.focus()
}

addLoadEvent(
	function(){
			var debug = new Debug();
	}
)
