/*
Script: dbug.js
Wrapper for the firebug console.log() function.

Dependancies:
	 no dependencies
	
Author:
	Aaron Newton, <aaron [dot] newton [at] cnet [dot] com>

Class: dbug
		dbug is a wrapper for the firebug console plugin for
		firefox. The syntax for logging is the same as documented
		at http://getfirebug.com, though only the .log() command
		is supported.
		
		You can leave dbug.log() statements in your code and 
		they will not be echoed out to the screen in any way. 

		To display the dbug statements, you have two options:
		include *"jsdebug=true"* in the query string of the page
		and all your dbug statements will be printed as they
		occur OR *type into the firebug console dbug.enable()*
		and the debug statements that have occurred up until
		that point will be echoed, and all others from that
		point will be printed as they occur. You can also
		*put dbug.enable() in your javascript* to turn it on.
		
		dbug.disable() will turn it back off.

Arguments:
	args - collection of things to log to the console.
	
Examples:
	(start code)
	dbug.log("message");
	> message
	dbug.log("my var is %s", myVar)
	> my var is x
	dbug.log($('myelement'));
	> <div id="myelement"></div>
	dbug.log("myelement: %s, some value: %s", $('myelement'), somevalue);
	> myelement: <div id="myelement"></div>, some value: blah
	(end)
	
	more at <http://getfirebug.com>
	*/
dbug = {
/*	Property: logged

		Array with any messages logged that have not been sent to the console; 
		happens when dbug is not enabled. when you enable it again,
		these messages will be dumped to the console.
	*/
	logged: [],	
	timers: {},
	loadtimers: {},
	loadtimerlogged: [],
	
/*	property: debug
		boolean; whether or not the debugger is enabled.
	*/	
	firebug: false, 
	debug: false, 

/*	property: log

		sends a message to the console if dbug is enabled, otherwise
		it stores this info until dbug is enabled.
		
		Parameters:
			message - the message to log, includes various substition options, see <http://www.getFirebug.com>

		Syntax: 
		> dbug.log("message");
		> > message
		> dbug.log("my var is %s", myVar)
		> > my var is x

		for more examples, see <http://www.getFirebug.com>
	*/
	log: function() {
		this.logged.push(arguments);
	},
	nolog: function(msg) {
		this.logged.push(arguments);
	},
/*	Property: time
		Starts a console timer with the given name if dbug is enabled.
		See <http://www.getFirebug.com> for details.
	*/
	time: function(name){
		this.timers[name] = new Date().getTime();
	},
	loadtime: function(name){
		this.loadtimers[name] = new Date().getTime();
	},
/*	Property: timeEnd
		Ends a console timer with the given name if dbug is enabled.
		See <http://www.getFirebug.com> for details.
	*/
	timeEnd: function(name){
		if (this.timers[name] > 0) {
			var end = new Date().getTime() - this.timers[name];
			this.log('%s: %s', name, end);
			this.timers[name] = false;
		} else this.log('no such timer: %s', name);
	},
/*	Property: enable

		turns on the dbug functionality so that messages will show up
		in the firebug console. any messages sent to dbug.log() 
		previously will be displayed in the console immediately and
		all future logging statements will echo to the console.

		See also: 
		<dbug.log>, <dbug.disable>
		
		Example:
		>dbug.enable()
		> > enabling dbug
		
	*/	
	enable: function() { 
		if(this.firebug) {
			try {
				this.debug = true;
				this.log = console.debug || console.log;
				this.time = console.time;
				this.timeEnd = console.timeEnd;
				this.log('enabling dbug');
				for(i=0;i<this.logged.length;i++){ this.log.apply(console, this.logged[i]); }
				this.logged=[];
			} catch(e) {
				this.enable.delay(400);
			}
		}
	},
/*	Property: disable

		turns the dbug functionality off. all future logging calls
		will be stored in the logged array until dbug is enabled again.
		
		See also: 
		<dbug.log>, <dbug.enable>, <dbug.logged>
		
		Example:
		>dbug.disable()
	*/
	disable: function(){ 
		if(this.firebug) this.debug = false;
		this.log = this.nolog;
		this.time = function(){};
		this.timeEnd = function(){};
	}
};

if (typeof console != "undefined" && console.warn){
	dbug.firebug = true; 
	if(window.location.href.indexOf("jsdebug=true")>0) dbug.enable();
}
/* do not edit below this line */   
/* Section: Change Log 

$Source: /cvs/main/flatfile/html/rb/js/global/cnet.global.framework/common/utilities/dbug.js,v $
$Log: dbug.js,v $
Revision 1.2  2007/01/23 00:12:23  newtona
tweaks to work with Debugger.js

Revision 1.1  2007/01/09 02:39:35  newtona
renamed addons directory to "common" directory

Revision 1.6  2006/12/06 20:14:59  newtona
carousel - improved performance, changed some syntax, actually deployed into usage and tested
cnet.nav.accordion - improved css selectors for time
multiple accordion - fixed a typo
dbug.js - added load timers
element.cnet.js - changed syntax to utilize mootools more effectively
function.cnet.js - equated $set to $pick in preparation for mootools v1

Revision 1.5  2006/12/06 17:52:50  newtona
making this file have no dependencies

Revision 1.4  2006/11/22 00:21:01  newtona
docs update

Revision 1.3  2006/11/21 23:56:08  newtona
added dbug.time and debug.timeEnd

Revision 1.2  2006/11/02 21:26:42  newtona
checking in commerce release version of global framework.

notable changes here:
cnet.functions.js is the only file really modified, the rest are just getting cvs footers (again).

cnet.functions adds numerous new classes:

$type.isNumber
$type.isSet
$set

*/



