/**
	debug class
	use dump to see variable
	use clear to clear debug window
	"debug_window" class of window, prefer it by your needs.
*/

Debug = {
	debugMode : true,
	dump : function(data, file, func)
	{
		if(!this.debugMode)
		{
			return;
		}
		if(!this.body)
		{
			this.construct();
		}
		
		var msg = document.createElement("DIV");
		var str = this.var_dump(data);
		msg.appendChild(document.createTextNode(str));
		this.body.appendChild(msg);
		this.body.scrollTop = this.body.clientHeight;
	},
	
	construct : function()
	{
		if(!this.debugMode)
		{
			return;
		}
		var div_body = document.createElement("DIV");
		div_body.className = "debug_window";
		
		document.body.appendChild(div_body);
		this.body = div_body;
	},
	
	clear : function()
	{
		if(!this.debugMode)
		{
			return;
		}
		this.body.innerHTML = "";
	},
	
	var_dump : function(data, rec, prefix, onlytype)
	{
		if(!this.debugMode)
		{
			return;
		}
		if(!prefix)
			prefix = "";
		prefix+="    ";
			
		if(!onlytype)
			onlytype = false;

		if(!rec)
			rec = false;

		if(typeof data == "undefined")
			return "undefined";
		if(typeof data == "null")
			return "null";
		if(typeof data == "string")
			return data;
		if(typeof data == "number")
		{
			return data;
		}
		if(typeof data == "function")
		{
			return "function";
		}
		if(typeof data == "object")
		{
			if(onlytype)
			{
				return "object";
			}
			var str = "object : ";
			for(var id in data)
			{
				str+="\r\n";
				str+=prefix;
				str+=id + "=";
				str+=this.var_dump(data[id], rec, prefix, !rec);
			}
			return str;
		}
		return typeof data;
	}
}

if (Debug.debugMode)
{
	if(navigator.userAgent.toLowerCase().indexOf('msie') > -1)
	{
	    console = {
	        info : window.alert
	    }
	}
}