//	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: 	30-Sep-2008 
//	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//

var hrefs = document.getElementsByTagName("a");
var link_path = "";
for (var l = 0; l < hrefs.length; l++) {
		try {
			var link_path = hrefs[l].pathname;
			if (location.host == hrefs[l].hostname) {
				if (link_path.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {
					hrefs[l].onclick = function(){ 
						trackfiles(this); 
						return false; 
					};
				}
			} else {
				hrefs[l].onclick = function(){ 
					trackfiles(this); 
					return false; 
				};
			}
		}
		catch(err) { }
}

function trackfiles(array_element) {
	file_path = "";
	if (location.host != this.hostname) {
		file_path = "/exlinks/" + ((array_element) ? array_element.hostname : this.hostname);
	}
	file_path = file_path + "/" + ((array_element) ? array_element.pathname : this.pathname);
	file_path = file_path.replace(/\/\//g,"/");
	pageTracker._trackPageview(file_path);
	window.setTimeout(function() { location.href=array_element.href; }, 200);
}

