//	Javascript to tag file downloads and external links in Google Analytics
//	To use, place reference to this file should be placed at the bottom of all pages, 
//	just above the Google Analytics tracking code.
//	All outbound links and links to non-html files should now be automatically tracked.
//
//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//	Created by: 	Colm McBarron, colm.mcbarron@iqcontent.com
//	Last updated: 	12-Feb-2006
//	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//  Found here: http://www.iqcontent.com/blog/2006/11/tracking-document-downloads-in-google-analytics

var hrefs = document.getElementsByTagName('a');
var _lp = '';
for (var l = 0; l < hrefs.length; l++) {
		try {
			_lp = hrefs[l].pathname;
			if (location.host == hrefs[l].hostname) {
				if (_lp.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {
					addTrackerListener(hrefs[l]);
				}
			} else {
				addTrackerListener(hrefs[l]);
			}
		}
		catch(e) { }
}
function addTrackerListener(obj) {
	if (obj.addEventListener) {
		obj.addEventListener('click', trackFiles, true);
	} else if (obj.attachEvent) {
		obj.attachEvent('onclick', trackFiles);
	}
}
function trackFiles(el) {
	var fp = '';
	if (location.host != this.hostname)
		fp = '/exlinks/' + ((el.srcElement) ? '/' + el.srcElement.hostname : this.hostname);

	fp = fp + ((el.srcElement) ? '/' + el.srcElement.pathname : this.pathname);
	urchinTracker(fp);
}
