/**	
	@author			nathaniel skulic <nate@skulic.name>
	@copyright 		Copyright 2007, Nathaniel Skulic. All Rights Reserved.
	@fileOverview	
*/

/* function _debug(foo) {
  var arg;
  for (var i = 0; i < arguments.length; i++) {
    arg = arguments[i];
    if (window.console) window.console.log(arg);
    else if (window.opera) window.opera.postError(arg);
    else if (window.Log) {
      if (!window._logger)
        window._logger = new Log(Log.INFO, Log.popupLogger);
      window._logger.debug(arg);
    } else alert(arg);       
  }
}
 */
function _consout(type, args) {
	if(!oil.debug) return false;
  var arg, self = arguments.callee;
  for (var i = 0; i < args.length; i++) {
    arg = args[i];
	 //var ConsSrv = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService);
		// ConsSrv.logStringMessage(arg);
    if (window['console'])
      (console[type])(arg);
    else if (window.opera) { window.opera.postError(arg); }
    else if (window.Log) {
       self._logger = self._logger || new Log(Log.INFO, Log.popupLogger);
       self._logger[type](arg);
    }
  }
}

function _error() { return _consout("error", arguments); }
function _warn()  { return _consout("warn",  arguments); }
function _info()  { return _consout("info",  arguments); }
function _debug() { return _consout("debug", arguments); }
function _log() { return _consout("log", arguments); }

function _assert(condition, message, ErrorClass) {
  if (!condition) {
    throw new (ErrorClass || Error)(message || "Assertion failed.");
  }
};

error = _error;
warning = _warn;
information = _info;
debug = _debug;
log = _log;  
assert = _assert;


function assertArity(args, arity, message) {
  if (arity == null) arity = args.callee.length;
  if (args.length < arity) {
    throw new SyntaxError(message || "Not enough arguments.");
  }
};

function assertType(object, type, message) {
  if (type && (typeof type == "function" ? !instanceOf(object, type) : typeOf(object) != type)) {
    throw new TypeError(message || "Invalid type.");
  }
}