

	if(!window.GameCatalog)
		GameCatalog = {};

	if(!GameCatalog.WebAnalysis)
		GameCatalog.WebAnalysis = {};

	if(!GameCatalog.WebAnalysis.SiteTracking)
		GameCatalog.WebAnalysis.SiteTracking = {};

	GameCatalog.WebAnalysis.SiteTracking.Replacer = function(str)
	{
	//		ReplaceStr.symbols = {'%%user-status%%': GetUserStatus()};

		this.rep = function(a) { return GameCatalog.WebAnalysis.SiteTracking.Replacer.symbols[a]()||a; }
		if (str === undefined || str === null)
			return '';

		return (str+'').replace(/(%%[^%]*%%)/g, this.rep);
	}

	GameCatalog.WebAnalysis.SiteTracking.hashCurrentSParams = {};

	GameCatalog.WebAnalysis.SiteTracking.submitEvent = function(pageName, data)
	{
		var pageData = GameCatalog.WebAnalysis.SiteTracking[pageName];
		
		if(pageData == null && data != null)
			pageData = data;
		else if(pageData == null && data == null)
			return;
		
		GameCatalog.WebAnalysis.SiteTracking.ClearParams();
		for(p in pageData)
		{
			if(typeof(pageData[p]) == 'function')
			{
				try{
					s[p] = pageData[p]();
				}
				catch(ex)
				{
					s[p] = "";
				}
			}
			else
				s[p] = pageData[p];

			GameCatalog.WebAnalysis.SiteTracking.hashCurrentSParams[p] = "";
		}
		
		s.t();
	}

	GameCatalog.WebAnalysis.SiteTracking.ClearParams = function()
	{
		for(p in GameCatalog.WebAnalysis.SiteTracking.hashCurrentSParams)
		{
			delete s[p];
		}
		
		GameCatalog.WebAnalysis.SiteTracking.hashCurrentSParams = {};
	}
	
	function GetScriptSrcQueryString()
	{
		var src = "";
		var pageName = GetPageName();
		src = "pagefilename=" + pageName;
		src += "&" + document.location.search.substr(1);

		return src;
	}
	
	function GetPageName()
	{
		var name = document.location.pathname.split("/")[document.location.pathname.split("/").length -1].split(".")[0];
		if(name)
			name = name.toLowerCase();
			
		return name || "homepage";
	}
	
	/*////////////		OMNITURE CUSTOMIZATION FOR OBERON		//////////////////////////////*/
	
	/* Download clicks tracking */
	function getCookie(name) { 
		var index = document.cookie.indexOf(name + "=");
		if (index == -1) return null;
		index = document.cookie.indexOf("=", index) + 1;
		var endstr = document.cookie.indexOf(";", index);
		if (endstr == -1) endstr = document.cookie.length;
		return unescape(document.cookie.substring(index, endstr));
	}
	
	//name - the name of cookie
	//value - the value of the cookie
	//expiration - the expiration period of the cookie (in days)
	function setCookie(name, value, expiration) { // use: setCookie("name", value);
		GameCatalog.WebAnalysis.SiteTracking.setCookie(name, value, expiration)
	}

	
	GameCatalog.WebAnalysis.SiteTracking.setCookie = function(name, value, expiration)
	{
		try {
			var strDate = new String();
			strDate = value.toString();
			//replace all chars with URL encoding
			while (strDate.indexOf(" ") != -1) {
				strDate = strDate.replace(" ","%20");
			}
			while (strDate.indexOf(":") != -1) {
				strDate = strDate.replace(":","%3A");
			}
			strDate = strDate.replace("+","%2B");
			strDate = strDate.replace("-","%2D");
			var today = new Date();
			var expiry = new Date(today.getTime() + expiration * 24 * 60 * 60 * 1000); 
			if (strDate != null && strDate != "") {
				document.cookie=name + "=" + strDate + "; expires=" + expiry.toGMTString();
			}
		}
		catch(er){}
	}


	// don't call this function directly, only from {omnitureLogDownload}, {omnitureLogDownload}, 
	function omnitureLogDownloadCover(gameCode, gameName)
	{
		GameCatalog.WebAnalysis.SiteTracking.omnitureLogDownloadCover(gameCode, gameName);
	}
	
	GameCatalog.WebAnalysis.SiteTracking.omnitureLogDownloadCover = function(gameCode, gameName)
	{
		var expirationPeriod = 180 //the number of days before expiration
		var today = new Date();
		
		try{
		GameCatalog.WebAnalysis.SiteTracking.setCookie(gameCode,today,expirationPeriod);
		s.linkType="d";
		s.events="event1";
		s.eVar11= GameCatalog.WebAnalysis.SiteTracking.DownloadOmnitureFormattedDate(); //Mon, 12 Feb 2007 15:13:42 UTC
		//s.lnk=s.co(this);
		s.tl(this,"d", gameName);
		}
		catch(er){}
	}
	
	// return date string in format: 2/12/2007 8:14:31 AM
	function DownloadOmnitureFormattedDate()
	{
		return GameCatalog.WebAnalysis.SiteTracking.DownloadOmnitureFormattedDate();
	}
	
	GameCatalog.WebAnalysis.SiteTracking.DownloadOmnitureFormattedDate = function()
	{
				var date = new Date();
		hours = date.getUTCHours();
		minutes = date.getUTCMinutes();
		seconds = date.getUTCSeconds();

		var suffix = "AM";
		if (hours >= 12) {
			suffix = "PM";
			hours = hours - 12;
		}
		if (hours == 0) {
			hours = 12;
		}

		if (minutes < 10)
			minutes = "0" + minutes
		if (seconds < 10)
			seconds = "0" + seconds
		
			
		return (date.getUTCMonth()+1) + "/" + date.getUTCDate() + "/" + date.getUTCFullYear() + " " + hours + ":" + minutes + ":" + seconds + " " + suffix;
	}
	
	//stores the download time per sku fixme and refid?
	//the page that is calling this function is required to include the omniture js files   
	function logDownload(gameCode, omnitureChannel) {
		GameCatalog.WebAnalysis.SiteTracking.logDownload(gameCode, omnitureChannel);
	}
	
	GameCatalog.WebAnalysis.SiteTracking.logDownload = function(gameCode, omnitureChannel)
	{
		s.linkName=gameCode;
		s.products=";"+gameCode;

		GameCatalog.WebAnalysis.SiteTracking.omnitureLogDownloadCover(gameCode, gameCode);
	}
	
	function omnitureLogDownload(gameCode, omnitureChannel, gameReportName) {
		return GameCatalog.WebAnalysis.SiteTracking.omnitureLogDownload(gameCode, omnitureChannel, gameReportName);
	}

	GameCatalog.WebAnalysis.SiteTracking.omnitureLogDownload = function(gameCode, omnitureChannel, gameReportName)
	{
		try {
			s.linkName=gameReportName;
			s.products=";"+gameReportName;
			GameCatalog.WebAnalysis.SiteTracking.omnitureLogDownloadCover(gameCode, gameReportName);
		}
		catch(er){}
		
		return true;
	}

	function omnitureLogDownload_Real(gameCode, omnitureChannel,gameName,catName,dlDateTime) {
		return GameCatalog.WebAnalysis.SiteTracking.omnitureLogDownload_Real(gameCode, omnitureChannel,gameName,catName,dlDateTime);
	}

	GameCatalog.WebAnalysis.SiteTracking.omnitureLogDownload_Real = function(gameCode, omnitureChannel,gameName,catName,dlDateTime)
	{
		try{		
		s.linkName=gameName;
		s.products=catName + ";" + gameName;
		GameCatalog.WebAnalysis.SiteTracking.omnitureLogDownloadCover(gameCode, gameName);
		}
		catch(e){}
		
		return true;
	}

	function getTimeBucket(oDate)
	{
		try {
			var today = new Date();
			var downloadDate = new Date(oDate);
			var timeGap		
			
			//the gap between downloadDate and today in hours
			timeGap = ((today.getTime() - downloadDate.getTime())/ (60*60*1000))	
			//fit the time gap into a descret bucket
			var timeBucket 
			if (downloadDate.getTime() == 0 || isNaN(timeGap)) {
				timeBucket = "Unknown";
			} else if (timeGap >=0 && timeGap <1) {
				timeBucket = "0-1 Hours";
			} else if (timeGap >=1 && timeGap <2) {
				timeBucket = "1-2 Hours";
			} else if (timeGap >=2 && timeGap <4) {
				timeBucket = "2-4 Hours";
			} else if (timeGap >=4 && timeGap <6) {
				timeBucket = "4-6 Hours";
			} else if (timeGap >=6 && timeGap <12) {
				timeBucket = "6-12 Hours";
			} else if (timeGap >=12 && timeGap <24) {
				timeBucket = "1 Day";
			} else if (timeGap >=1*24 && timeGap <2*24) {
				timeBucket = "2 Days";
			} else if (timeGap >=2*24 && timeGap <3*24) {
				timeBucket = "3 Days";
			} else if (timeGap >=3*24 && timeGap <4*24) {
				timeBucket = "4 Days";
			} else if (timeGap >=4*24 && timeGap <5*24) {
				timeBucket = "5 Days";
			} else if (timeGap >=5*24 && timeGap <6*24) {
				timeBucket = "6 Days";
			} else if (timeGap >=6*24 && timeGap <7*24) {
				timeBucket = "7 Days";
			} else if (timeGap >=1*24*7 && timeGap <2*24*7) {
				timeBucket = "1-2 Weeks";
			} else if (timeGap >=2*24*7 && timeGap <4*24*7) {
				timeBucket = "2-4 Weeks";
			} else if (timeGap >=1*24*7*4 && timeGap <2*24*7*4) {
				timeBucket = "1-2 Months";
			} else {
				timeBucket = " > 2 Months";
			}

			return timeBucket;
		}
		catch(er){
			return "Unknown";
		}
	}