if (!Framework.Debugging)
{
	Framework.Debugging = {};
}

Framework.Debugging.Console = {

	_debugData: [],
	_startDate: new Date(), 
	
	log: function(m, type)
	{
		if (!Framework.Debugging.Environment.isDebugMode())
		{
			return;
		}
		
		try 
		{
			if (!type) 
			{
				type = 'log';
			}
			var now = new Date();
			Framework.Debugging.Console._debugData[Framework.Debugging.Console._debugData.length] = {
				t: now.getTime(), 
				m: m, 
				type: type 
			};
			
			if (window.console)
			{
				if (typeof(m) === 'string')
				{
					now = new Date();
					m = "[" + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + "." + now.getMilliseconds() + "] " + m;
				}
				
				if (type === 'info') 
				{
					window.console.info(m);
				}
				else if (type === 'warning') 
				{
					window.console.warn(m);
				}
				else if (type === 'error') 
				{
					window.console.error(m);
				}
				else 
				{
					window.console.log(m);
				}
			}
		}
		catch(ex) 
		{
			/*
			console.log(ex);
			if (typeof (m) == 'string') 
			{
				console.log(m);
			} else if (typeof (m) == 'object') 
			{
				for (var t in m) 
				{
					console.log(m.t);
				}
			}
			*/
		}
	},
	
	info: function(m)
	{
		this.log(m, 'info');
	},
	
	warning: function(m)
	{
		this.log(m, 'warning');
	},
	
	error: function(m, options)
	{
		options = Object.extend(options, {
			postError: false
		});
		
		// increment counter
		if (Framework.Instances.get('debugBar'))
		{
			Framework.Instances.get('debugBar').incrementErrorCount();
		}
		
		// post it
		if (options.postError) 
		{
			Framework.Debugging.Environment.postError(m);
		}
		
		// write to console
		this.log(m, 'error');
	},
	
	clear: function()
	{
		this._debugData = [];
	},
	
	toString: function()
	{
		var all = '<table style="width: 100%; clear: both; padding-top: 5px"><tbody>';
		var previousTime = this._startDate.getTime();
		var i = 0;
		var value = null;
		this._debugData.each(function(d) {
			i = i + 1;
			value = "";
			
			if (typeof(d.m) === 'string' || typeof(d.m) === 'number')
			{
				value = d.m.toString().wordWrap(200, "- ", true);
			}
			else
			{
				for (var message in d.m)
				{
					if (typeof(d.m[message]) === 'string')
					{
						value += message + ": " + d.m[message].toString().wordWrap(200, "- ", true) + "<br />";
					}
				}
			}
			
			all += '<tr class="' + d.type + '">';
			all += '<td class="rowcount">' + i + '.</td>';
			all += '<td class="value">' + value;
			if (d.trace)
			{
				all += ' - ' + d.trace;
			}
			all += '</td>';
			all += '<td>' + ((d.t - previousTime) / 1000).toFixed(3) + 's</td>';
			all += '<td>' + ((d.t - this._startDate) / 1000).toFixed(3) + 's</td>';
			all += '</tr>';
			previousTime = d.t; 
		}, this);
		all += "</tbody></table>";
		
		return all;
	},
	
	_eoo: true
};

var debug = Framework.Debugging.Console.log;