window.Debug = new function()
{
	this.logged_times = {};
	this.log_file = [];
	
	this.use_timer = false;
	
	this.log = function(a, b, func)
	{
		/* Sends a message to console.log (or console.info, etc., in case
		 * a different function is requested). This prints out the message
		 * in the browser's console. */
		
		if (func == null) {
			func = "log";
		}
		if (b == null) {
			b = [];
		}
		if (b.constructor.toString().indexOf("Array") == -1) {
			b = [b];
		}
		if (this.use_timer) {
			b.unshift(this.get_timer());
			a = "%d: "+a;
		}
		b.unshift(a);
		console[func].apply(console, b);
	}
	
	/* Disable the console function in case there is no console available. */
	if (!window["console"]) {
		this.log = function(a, b, func)
		{
			return false;
		}
	}
	
	this.info = function(a, b)
	{
		/* Shortcut for this.log(a, b, "info"). */
		return this.log(a, b, "info");
	}
	
	this.warn = function(a, b)
	{
		/* Shortcut for this.log(a, b, "warn"). */
		return this.log(a, b, "warn");
	}
	
	this.error = function(a, b)
	{
		/* Shortcut for this.log(a, b, "error"). */
		return this.log(a, b, "error");
	}
	
	this.timer_start = function(name)
	{
		/* Starts a named timer. This can be used to see how long a particular
		 * set of actions takes to complete. To get the result, call timer_stop()
		 * with the same argument. */
		this.logged_times[name] = this.get_timer();
	}
	
	this.timer_stop = function(name)
	{
		/* Returns the difference between now and the moment this timer was started. */
		return this.get_timer() - this.logged_times[name];
	}
	
	this.get_timer = function()
	{
		/* Returns the amount of milliseconds since this page was loaded. */
		return new Date().getMilliseconds();
	}
}

Debug.info("Debug class initialized.");
