/*******************************
     Tracking / Analytics 
*******************************/

chester.track = {
	
	/* Navigation Links */
	about: function() {
		this.track('/nav_about');	
	},
	cheetos: function() {
		this.track('/nav_cheetos');		
	},
	like: function(category, title) {
		//this.track('/like_' + title);	
		//this.trackEvent('like', title);	
		var category = this.getSubCategory(category);
		this.track('/' + category + '/' + title + '/Like/');		
	},
	search: function() {
		this.track('/nav_searchsubmit');	
	},
	/* Chester's Feed Share */
	share: function(category, title, type) {
		this.doubleClickShare();
		try {
			category = category.toLowerCase();
			type = type.substring(0,1).toUpperCase() + type.substring(1,type.length)
		}
		catch(e){}
		// find group/item name
		var category = this.getSubCategory(category);
		if(typeof type != 'undefined') { 
			this.track('/' + category + '/' + title + '/Share/' + type + '/');	
		}
		else {			
			this.track('/' + category + '/' + title + '/Share/');	
		}
		//this.trackEvent('share', category, type, title);
	},
	submission: function(category) {
		var subCategory = this.getSubCategory(category);
		//this.track('/submitcontent_' + category + '_confirm');
		this.trackEvent('submitcontent', subCategory);
	},
	subscribe: function() {
		this.track('/nav_subscribe');	
	},		
	
	/* Chester's Feed Views */	
	feedView: function(category, title) {
		try {
			category = category.toLowerCase();
		}
		catch(e){}
		// find group/item name
		category = this.getSubCategory(category);
		// track complete link
		this.track('/' + category + '/' + title + '/');
		//this.trackEvent(category,'click',title);
	},
	
	doubleClickShare: function() {
		// code generated by doubleclick
		// activity name for this tag is "Cheetos_Share"
		var axel = Math.random()+"";
 		var a = axel * 10000000000000;
 		$("#doubleclickTrack").html('<img src="http://ad.doubleclick.net/activity;src=1358061;type=2010c837;cat=cheet779;ord='+ a + '?" width="1" height="1" border="0" />'); 	
	},
	
	/* Retieve a name for an element of a category */
	getSubCategory: function(category) {
		try {
			category = category.toLowerCase()
			category = category.replace(':', '');
		}
		catch(e){}
		if(category == 'videos' || category == 'video' || category == 1) {
			return 'Video';
		}
		if(category == 'photos' || category == 'photo' ||category == 2) {
			return 'Photo';
		}
		if(category == 'games' || category == 'game' ||category == 3) {
			return 'Game';
		}
		if(category == 'news' || category == 4) {
			return 'News';
		}
		if(category == 'funstuff') {
			return 'Funstuff';
		}
		if(category == 'recipes' || category == 'recipe' || category == 5) {
			return 'Recipe';
		}
		return 'Item';
	},
	// Call tracking services
	track: function(trackingEvent) {
		//console.log(trackingEvent);
		try {
			//urchinTracker(trackingEvent);
			//pageTracker._trackPageview(trackingEvent);			
			// v2
			//console.log("_gaq.push(['_trackPageview']);");
			_gaq.push(['_trackPageview', trackingEvent]);
		}
		catch(e) {
			// log error	
		}
	},
	trackEvent: function(category, action, opt_label, opt_value){
		//console.log("_gaq.push(['_trackEvent', "+category+", "+action+", "+opt_label+", "+opt_value+"]);");
		_gaq.push(['_trackEvent', category, action, opt_label, opt_value]);
	}
};
