He.Log = function(){};
He.Error = function(){};
He.CPush = function(){};
He.CPop = function(){};
He.LogClear = function(){};

if(He.Config.Debug.Enabled)
{
	if(He.IsObject(window.console) && He.IsFunction(window.console.debug))
 	{
		if(Prototype.Browser.WebKit)
		{
			window._console = window.console;
			window.console = {
				log : function(){window._console.log($A(arguments).join(", "));},
				error : function(){window._console.error($A(arguments).join(", "));},
				warn : function(){window._console.warn($A(arguments).join(", "));},
				info : function(){window._console.info($A(arguments).join(", "));},
				count : function(){window._console.count.apply(this,arguments);},
				debug : function(){window._console.debug($A(arguments).join(", "));},
				profileEnd : function(){window._console.profileEnd.apply(this,arguments);},
				trace : function(){window._console.trace.apply(this,arguments);},
				dir : function(){window._console.dir.apply(this,arguments);},
				dirxml : function(){window._console.dirxml.apply(this,arguments);},
				assert : function(){window._console.assert.apply(this,arguments);},
				time : function(){window._console.time.apply(this,arguments);},
				profile : function(){window._console.profile.apply(this,arguments);},
				timeEnd : function(){window._console.timeEnd.apply(this,arguments);},
				group : function(){window._console.group($A(arguments).join(", "));},
				groupEnd : function(){window._console.groupEnd($A(arguments).join(", "));}
			};
		}

		He.Log = window.console.debug;
		He.Error = window.console.error;

		He.LogClear = function(){};

		if(He.IsFunction(window.console.group))
		{
			He.CPush = window.console.group;
			He.CPop = window.console.groupEnd;
		}
		else
		{
			He.CPush = function(){};
			He.CPop = function(){};
		}
 	}
/* 	else if(He.IsObject(Sys) && He.IsObject(Sys.Debug) && He.IsFunction(Sys.Debug.trace)) //
 	{
 		He.Log = Sys.Debug.trace;
 		He.Error = Sys.Debug.trace;

 		He.LogClear = function(){};

 		He.CPush = function(){};
 		He.CPop = function(){};
 	}*/
 	else
	{
		He.LogClear = function()
		{
			if(He.RConsole)
			{
				He.OnDOMReady(function()
				{
					document.body.removeChild(He.RConsole);
				});
			}
			He.Console = He.RConsole = document.createElement('div');
			He.CPush(/*He.Application.GetName() + */'Application Log :');
			He.OnDOMReady(function()
			{
				document.body.appendChild(He.RConsole);
			});
		}
		He.Log = function()
		{
			if(!He.RConsole)
			{
				He.LogClear();
// 				He.Console = He.RConsole = document.createElement('div');
// 				He.CPush('Application Log :');
// 				He.OnDOMReady(function()
// 				{
// 					document.body.appendChild(He.RConsole);
// 				});
			}

// 			if(He.Console.childNodes.length > 10)
// 			{
// 				delete(He.Console.firstChild.nextSibling);
// 			}

			var html = He.ToString.apply(this,He.Log.arguments);
			var p = document.createElement('pre');
			p.style.margin = "1px";
			p.style.paddingLeft = "4px";
			p.style.border = "1px outset #321";
			p.style.background = "#321";
			p.style.fontSize = '14px';
			p.style.color = '#F60';
			p.style.whiteSpace = 'pre';

// 			p.innerHTML = '<pre>'.html.'</pre>';
			p.appendChild(document.createTextNode(html));
			He.Console.appendChild(p);
		};

		He.Error = function()
		{
			var a = Array.prototype.slice.call(arguments);
			a.unshift('!ERROR! : ');
			He.Log.apply(this,a);
		};

		He.CPush = function()
		{
			if(!He.RConsole)
			{
				He.LogClear();
// 				He.Console = He.RConsole = document.createElement('div');
// 				He.CPush('Application Log :');
// 				He.OnDOMReady(function()
// 				{
// 					document.body.appendChild(He.RConsole);
// 				});
			}

			var html = '+'
			if(He.CPush.arguments.length > 0)
			{
				html += ' ' + He.ToString.apply(this,He.CPush.arguments);
			}

			var p = document.createElement('pre');

			p.style.margin = "1px";
			p.style.paddingLeft = "4px";
			p.style.border = "1px outset #321";
			p.style.background = "#A50";
			p.style.fontSize = '14px';
			p.style.color = '#321';
			p.style.whiteSpace = 'pre';
			p.style.fontStyle = 'italic';
			p.style.fontWeight = 'bold';
			p.style.textAlign = 'left';

			p.appendChild(document.createTextNode(html));

			He.Console.appendChild(p);

			p.open = false;
			p.onclick = function(_lap)
			{
				if(this.open === true)
				{
					Effect.BlindUp(this.nextSibling,{duration:0});
					this.open = false;
					p.style.marginBottom = '1px';
					this.innerHTML = '+' + this.innerHTML.substr(1)
				}
				else
				{
					Effect.BlindDown(this.nextSibling,{duration:0});
					this.open = true;
					p.style.marginBottom = '1px';
					this.innerHTML = '-' + this.innerHTML.substr(1)
				}
			}

			var bq = document.createElement('blockquote');

			bq.style.padding = "1px 1px 1px 20px";
			bq.style.margin = "1px";
			bq.style.border = "1px inset #310";
			bq.style.background = "#310";
			bq.style.textAlign = 'left';
			bq.style.display = 'none';

			bq.className = 'log_block'

			He.Console.appendChild(bq);

			He.Console = bq;
		};

		He.CPop = function()
		{
			if(He.Console != He.RConsole)
			{
				He.Console = He.Console.parentNode;
			}
		};
	}
}

