Debug = new function()
{
	var self = this;

	self.logged_times = {};
	self.log_file = [];
	
	self.use_timer = false;
	
	self.log = function(a, b, func)
	{
		/* Sends a message to console.log (or console.info, etc., in case
		 * a different function is requested). self 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 (self.use_timer) {
			b.unshift(self.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"]) {
		self.log = function(a, b, func)
		{
			return false;
		}
	}
	
	self.info = function(a, b)
	{
		/* Shortcut for self.log(a, b, "info"). */
		return self.log(a, b, "info");
	}
	
	self.warn = function(a, b)
	{
		/* Shortcut for self.log(a, b, "warn"). */
		return self.log(a, b, "warn");
	}
	
	self.error = function(a, b)
	{
		/* Shortcut for self.log(a, b, "error"). */
		return self.log(a, b, "error");
	}
	
	self.timer_start = function(name)
	{
		/* Starts a named timer. self 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. */
		self.logged_times[name] = self.get_timer();
	}
	
	self.timer_stop = function(name)
	{
		/* Returns the difference between now and the moment self timer was started. */
		return self.get_timer() - self.logged_times[name];
	}
	
	self.get_timer = function()
	{
		/* Returns the amount of milliseconds since self page was loaded. */
		return new Date().getMilliseconds();
	}
}

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