/**
 * Primary controller for analytics such as Omniture
 *
 *
 */
AnalyticsManager = Class.create();
Object.extend(AnalyticsManager.prototype, {

	/**
	*	define member vars for this class
	*
	*/
	initialize: function(deactivate) {
		this.deactivate = deactivate || false;
		this.omnitureAccount = "";
		this.campaignCode = "";
		this.isCampaignCodeSet = false;
		this.CAMPAIGN_CODE_COOKIE_NAME = 'omnitureCampaignCode';
		
								
		var qs = document.location.search.substring(1);
		var vars = qs.split("&");
		
		for (var i=0; i<vars.length; i++)
		{
			var pair = vars[i].split("=");
			if (pair[0] == 'scid')
			{
				this.campaignCode = pair[1];
			}
		}
		
		
		if(this.campaignCode != "")
		{
			// campaign code should only be set once so if the campaign code exists in the cookie, it has
			// already been passed to omniture and should not be set again.
			var tempCodeValue = Get_Cookie( this.CAMPAIGN_CODE_COOKIE_NAME );
			if(tempCodeValue != null)
			{
				this.campaignCode = tempCodeValue;
				this.isCampaignCodeSet = true;
			}
		}
		
	},
	
	
	/**
	*	Called any time a new page loads or the site changes a section - moves from one 'page' to another.
	*	This is typically called by the NavigationManager.  May also be called to capture specific 
	*	user events such as button clicks or gallery item views.
	*
	*/
	callOmniture: function(pageName) {
		
		if(this.deactivate==true) return;
		
		// pageName should be something like "sci: slash: scion racing: drift: rockstar"
		
		// TODO:  Create mapping to specific Omniture names?
		s=s_gi(s_account); 
		s.channel="slash";
		s.pageName = pageName;
		
		// s.campaign should only be set once
		if(this.campaignCode != "") 
		{
			if(this.isCampaignCodeSet == false)
			{
				s.campaign = this.campaignCode;
				this.isCampaignCodeSet = true;
				Set_Cookie( this.CAMPAIGN_CODE_COOKIE_NAME, this.compaignCode, '', '/', '', '' );
			} else {
				s.campaign = "";
			}
		}
		
		//alert('cc: ' + s.campaign + ' page: ' + s.pageName);
		
		s.t();

	}
	
});
