hbx.lt = 'auto';

// Assign Page Title and URL to Custom Metric 1 (dimensions 1 and 2)
var cTitle = document.title;
cTitle = cTitle.replace(/'/g, "");
cTitle = cTitle.replace(/"/g, "");
cTitle = cTitle.replace(/,/g, "");
cTitle = cTitle.replace(/\|/g, "");
var cUrl = window.location;
hbx.hc1 = cTitle  + '|' + cUrl;

/* process hbx.mlc and hbx.pn to eliminate redundant categorization */
var protocol = cUrl.toString().substring(0,4); //get url protocol

//temp vars to route pages
var hbx_temp_zone; var hbx_temp_pn;

if ( protocol == "http" ) { //url can be further processed
   var urlPath = cUrl.toString().replace(/http:\/\/\S+\.cbc\.ca\//, "/");
   //process EPT
   if ( !hbx_temp_pn ) {
      //orginally had 'do nothing' now had old version
			if (urlPath.match(/\/story\/\d{4}\/\d{2}\/\d{2}\/(\S+)\.html/)){
			 	urlPath = urlPath.substring(0, urlPath.lastIndexOf('/'));
			 	var index = urlPath.search(/\d{4}\/\d{2}\/\d{2}/);
			 	var yyyymmdd = urlPath.substring(index).replace(/\//g, '-');
			 	urlPath = urlPath.replace(/\d{4}\/\d{2}\/\d{2}/, yyyymmdd);	
			 	hbx.mlc = urlPath;
				// Add DEFAULT_CAT_PREFIX to mlc if provided
				if (typeof(DEFAULT_CAT_PREFIX) != "undefined") hbx.mlc = DEFAULT_CAT_PREFIX + hbx.mlc;
			}
   } else {
      var new_pn = hbx_temp_pn.replace(/\//g, '-');
      //remove date, file extension and querystring
      urlPath = urlPath.replace(/\d{4}\/\d{2}\/\d{2}\/(\S+)\.html(.*)/, '');
      hbx.mlc = urlPath;
      hbx.pn = new_pn + ".html";
	// Add DEFAULT_CAT_PREFIX to mlc if provided
	if (typeof(DEFAULT_CAT_PREFIX) != "undefined") hbx.mlc = DEFAULT_CAT_PREFIX + hbx.mlc;
   }
   //process programguide
   if ( urlPath.match(/\/programguide\/(\S+)\/\d{4}\/\d{2}\/\d{2}\/(\S+)/) ) {
      urlPath = urlPath.replace(/\/(\S+)\/\d{4}\/\d{2}\/\d{2}/, '/programguide');
      hbx.mlc = urlPath;
   }
   //process 400 pages (500 pages not tracked at all)
   if ( hbx_temp_zone == "error" ) { hbx.mlc = "/error"; }
} else { //url is an obvious error, push to error mlc
   hbx.mlc = "/malformedUrl";
}

// "Proxy" functions for reporting page views and media activity to HBX from Flash or Ajax applications.

function cbcStatsReportPageView(o) {
	if (o.page != undefined && o.category != undefined) _hbPageView(o.page, o.category); // report page view to hbx
}

function cbcStatsReportMedia(o) {
	if (o.clientname != undefined) _hbSet("m.cl",o.clientname);
	if (o.clientversion != undefined) _hbSet("m.cv",o.clientversion);
	if (o.filename != undefined) _hbSet("m.f",o.filename);
	if (o.state != undefined) _hbSet("m.s",o.state); //play,pause,stop,playp
	if (o.position != undefined) _hbSet("m.cp",o.position); // current position, usually 0 when movie starts playing
	if (o.duration != undefined) _hbSet("m.ep",o.duration); // aka "end position"
	if (o) _hbSend(); // send variables to hbx
}

function cbcStatsReportLink(o) {
	_hbLink(o.name, o.pos);
}

