/**
 * SimpleTuition Logger
 */
(function($){
 	
	var f = function(){};
	var p = f.prototype;

	/**
	 * @return true - if console exists & in debug mode
	 * @return false - if otherwise
	 */
	p.show = function(){
		// return false; // useful debugging switch
		return $T.global.debugMode
			&&(typeof(console)=="object")
			&&(typeof(console.log)=="function");
	};
 		
 	// log message format
    p.msg = "simpletuition - %d - %e";
    
    /**
     * DEBUG logger 
     * @param {Object} m - message desired
     * @param {Object} o - object you want to inspect
     */
    p.debug = function(m,o) {
 		if(this.show())console.log(this.msg,m,o);
 	};
    	
    /**
     * WARN logger
  	 * @param {Object} m - message desired
     * @param {Object} o - object you want to inspect
     */
 	p.warn = function(m,o) { 
 		if(this.show())console.warn(this.msg,m,o);
 	};
	
	
 	/**
 	 * ERROR logger
 	 * if in debug mode, show console and use o for object;
 	 * otherwise notify failure with e as error messag
 	 * @param {Object} e - error msg
 	 * @param {Object} o - object to inspect
 	 */
	p.error = function(e,o) { 
 		if(this.show())console.error(this.msg,e,o);
 		notify.failure(e);
 	};
 	
 	/**
 	 * Google Analytics:
 	 * 	log.ga.getTracker();
 	 * 	log.ga.page(pageName);
 	 * 	log.ga.event(category,action,label,value);
 	 */
 	p.ga = {};
 	
 	/**
 	 * Get the Google Analytics Tracker
 	 * Note: This utilizes the 'data-ga-id' on the body tag
 	 */
 	p.ga.getTracker = function(){
 		var id = $("body").attr("data-ga-id");
 		if(id && id!="") if(_gat) return _gat._getTracker(id);
 		return undefined;
 	};
 	
 	/**
 	 * Register a Google Analytics Page Request
 	 * @param sPage - the page to register
 	 */
 	p.ga.page = function(sPage){
 		var tracker = this.getTracker();
 		if(tracker){
 			tracker._trackPageview(sPage);
 			log.debug("GA PAGE: "+sPage);
 		}
 	};
 	
 	/**
 	 * Register a Google Analytics Event
 	 * @param sCategory - the category
 	 * @param sAction - the action 
 	 * @param sLabel - the label for the particular category/action
 	 * @param nValue - the value (numeric)
 	 * @returns - true if success
 	 */
 	p.ga.event = function(sCategory, sAction, sLabel, nValue){
 		var ret = false;
 		var tracker = this.getTracker();
 		if(tracker){
 			try {
	 			tracker._initData(); // init's events
	 			if(sLabel===undefined&&nValue===undefined)
	 				ret = tracker._trackEvent(sCategory, sAction);
	 			else if(nValue===undefined)
	 				ret = tracker._trackEvent(sCategory, sAction, sLabel);
	 			else  // passing in nValue instantiate new Number just to be safe
	 				ret = tracker._trackEvent(sCategory, sAction, sLabel, new Number(nValue));
	 			// log it out for Dev/QA
	 			log.debug("GA EVENT: category: "+sCategory+", action: "+sAction+", label: "+sLabel+", value: "+nValue + " [VALID:"+ret+"]");
 			} catch (e) { 
 				log.error("ERROR LOGGING GA EVENT " + e); 
 			}
 		}
 		return ret;
 	};

 	/**
     * SETUP $T.LOG as this function
     */
    log = $T.log = new f(); // remove log after refactoring
    	 
 })(jQuery);
 
