// gautils.js ext

ncverTracker.prototype = new gaUtils();
ncverTracker.prototype.constructor = ncverTracker;

/**
* NCVER Google Analytics Utilities Extension.<p>
* Extends the core GAUtils tracking code functionality contained in gautils.js to include additional functionality specific to the NCVER website
* @example
* &lt;script type="text/javascript" src="/path/to/gautils.js"&gt;&lt;/script&gt;
* &lt;script type="text/javascript"&gt;
* var gaU = new ncverTracker('mydomain.com');
* gaU.Initialise();
* &lt;/script&gt;
* @constructor
* @param {String} domain Optional. Bbase domain name. If left blank the current host name is used
* @public
* @author Panalysis Pty Ltd
* @version 1.0.0
* @return void
*/
function ncverTracker(d)
{
	this._baseDomain ="";
	if(d != "")
		this._baseDomain = d;

	this._customVarSlots = new Object();

	this._customVarSlots["userseg"] = {
		slot: 1,
		scope: 1,
		pageview: true,
		url: "/tracking/usersegment"
	};
	
	this._customVarSlots["filecat"] = {
		slot: 2,
		scope: 3,
		pageview: true
	};
	this._customVarSlots["filetype"] = {
		slot: 3,
		scope: 3,
		pageview: true
	};
	
	this.Settings = new Object();
	this.Settings = {
		linktracking: {
			trackexternal: true,
			trackemail: true,
			externalbase: "/external/",
			emailbase: "/email/",
			externalpageview: true,
			emailpageview: true
		},
		trackbanners: false,
		trackfirstcampaign: false,
		trackrightclicks: false,
		debug: false,
		autotrackmembers: true,
		autoinitlinks: false,
		trackadwordsquery: false
	};
}

/**
* Records a download of the specified file into the Top Content report in Google Analytics. Also records the file category and file type into custom variables
* @public
* @param {string} FilePath. The path to the file to be recorded into Google Analytics
* @param {string} FileCategory. The category to be recorded into Google Analytics
* @author Panalysis Pty Ltd
* @version 1.0
* @return void
*/
ncverTracker.prototype.TrackDownload = function (fpath, category)
{
	var fExt = this._getFileExtension(fpath);
	
	if(fExt != "" && typeof(this._customVarSlots["filetype"]) != "undefined")
	{
		try
		{
			this.PageTracker._setCustomVar(
				this._customVarSlots["filetype"].slot,
				"file-type",fExt,
				this._customVarSlots["filetype"].scope
			);
		} catch (err) {}
	}
	
	if(typeof(this._customVarSlots["filecat"]) != "undefined")
	{
		try
		{
			this.PageTracker._setCustomVar(
				this._customVarSlots["filecat"].slot,
				"file-category",category,
				this._customVarSlots["filecat"].scope
			);
		} catch (err) {}
	}
	
	
	try
	{
		this.PageTracker._trackPageview(fpath);
	} catch (err) {}
}

ncverTracker.prototype._getFileExtension = function(fPath)
{
	var fExt = "";
	var fParts;
	
	var fpParts = fPath.split("/"); // separate out the path
	if(fpParts.length>0)
	{
		fParts = fpParts[fpParts.length-1].split(".");
	}
	
	if(fParts.length>1) // must have at least 1 dot in the file name
	{
		fExt = fParts[fParts.length-1].toLowerCase();
	}
	
	return fExt;
}