/**
 * Copyright (C) 2010 Mark Gardner of the Ayzenberg Group
 *
 * MIT/X11 License
 *
 * jQuery.logger v1.1.1 - A jQuery cross-browser logger based on Jonathan Azoff jquery.log and
 * John Griffiths jquery.log. Supported by Opera, Firebug and newer WebKit browsers.
 *
 * ChangeLog
 *	2010-08-17	v1.1.1	Added assert method and loggerAlertFallback property.
 *	2010-08-16	v1.1.0	Pass all calls to the new echo command to do the heavy lifting.
 *	2010-07-??	v1.0.0	Initial script creation.
 * 
 * @usage		Call jQuery.assert([expression, args...]) to write assert level to the console if expression evaluations to true of any browser.
 *				Call jQuery.log([args...]) to attempt to write log level to the console of any browser.
 *				Call jQuery.debug([args...]) to attempt to write debug level to the console of any browser.
 *				Call jQuery.info([args...]) to attempt to write info level to the console of any browser.
 *				Call jQuery.warn([args...]) to attempt to write warn level to the console of any browser.
 *				Call jQuery.error([args...]) to attempt to write error level to the console of any browser.
 * @param 		args...	one or more javascript objects to be written to the console
 * @returns 	true if a console was detected and successfully used, false if the plug-in had to resort to alert boxes
 * @note 		if a plug-in cannot be located then an alert is called with the arguments you wish to log. Multiple 
 *              arguments are separated with a space.
 * @depends 	just make sure you have jQuery and some code you want to debug.
 */
(function($)
{
	$.extend(
		{
			"loggerAlertFallback":false,
			"assert":function()
				{
					if(arguments.length>1)
					{
						var args=[];
						for(var i=0; i<arguments.length; i++)
						{
							args.push(arguments[i]);
						}
					
						var expr=args.shift();
						args=(args.length>1)?Array.prototype.join.call(args," "):args[0];
					
						try
						{
							console.assert(expr,args);
							return true;
						}
						catch(e)
						{
							if(expr==false)
							{
								this.echo('ASSERT: '+args);
							}
						}
						return false;
					}
				},
			"echo":function(args)
				{
					try
					{
						console.log(args);
						return true;
					}
					catch(e)
					{
						try
						{
							opera.postError(args);
							return true;
						}
						catch(e)
						{
							if(this.loggerAlertFallback)
							{
								alert(args);
							}
						}
					}
					return false;
				},
			"log":function()
				{
					if(arguments.length>0)
					{
						var args=(arguments.length>1)?Array.prototype.join.call(arguments," "):arguments[0];
						try
						{
							console.log(args);
							return true;
						}
						catch(e)
						{
							this.echo('  LOG: '+args);
						}
						return false;
					}
				},
			"debug":function()
				{
					if(arguments.length>0)
					{
						var args=(arguments.length>1)?Array.prototype.join.call(arguments," "):arguments[0];
						try
						{
							console.debug(args);
							return true;
						}
						catch(e)
						{
							this.echo('DEBUG: '+args);
						}
						return false;
					}
				},
			"info":function()
				{
					if(arguments.length>0)
					{
						var args=(arguments.length>1)?Array.prototype.join.call(arguments," "):arguments[0];
						try
						{
							console.info(args);
							return true;
						}
						catch(e)
						{
							this.echo(' INFO: '+args);
						}
						return false;
					}
				},
			"warn":function()
				{
					if(arguments.length>0)
					{
						var args=(arguments.length>1)?Array.prototype.join.call(arguments," "):arguments[0];
						try
						{
							console.warn(args);
							return true;
						}
						catch(e)
						{
							this.echo(' WARN: '+args);
						}
						return false;
					}
				},
			"error":function()
			{
				if(arguments.length>0)
				{
					var args=(arguments.length>1)?Array.prototype.join.call(arguments," "):arguments[0];
					try
					{
						console.error(args);
						return true;
					}
					catch(e)
					{
						this.echo('ERROR: '+args);
					}
					return false;
				}
			}
		});
})(jQuery);

