//	Javascript to tag file downloads and external links in Google Analytics
//	To use, paste the following code directly above your standard Google Analytics tracking code
// (un-escape the slash marks).
// <script src="\/js\/downloads-analytivs.js" type="text\/javascript"><\/script>
// (Don't forget to replace the '/js/taglinks.js' with the correct path to the javascript file)
//	All links to non-html files should now be automatically tracked.
//
//  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//	Created by: 	Colm McBarron, colm.mcbarron@iqcontent.com
//	http://www.iqcontent.com/blog/2006/11/tracking-document-downloads-in-google-analytics
//	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//

var hrefs = document.getElementsByTagName("a");
var link_path = "";
for (var l = 0; l < hrefs.length; l++) {
	// check if it's a non HTML file type
		try {
			var link_path = hrefs[l].pathname;
			if (link_path.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {
				// check if it's an internal link
				if (location.host == hrefs[l].hostname) {
					link_path = hrefs[l].pathname;
			 		if (hrefs[l].addEventListener) {
						hrefs[l].addEventListener('click', trackfiles, true);
					} else if (hrefs[l].attachEvent) {
						hrefs[l].attachEvent("on" + 'click', trackfiles);
					}
				}
			}
		}
		catch(err) { }
}

function trackfiles(array_element) {
	var file_path = (array_element.srcElement) ? "/" + array_element.srcElement.pathname : this.pathname;
	urchinTracker(file_path);
}