
function trackfiles(array_element) {
    file_path = "";
    if (location.host != array_element.hostname) {
        file_path = "/outbound/" + ((array_element.srcElement) ? "/" + array_element.srcElement.hostname : array_element.hostname);
    }
    file_path = file_path + ((array_element.srcElement) ? "/" + array_element.srcElement.pathname : array_element.pathname);
    pageTracker._trackPageview(file_path);
    window.setTimeout(function() { location.href=array_element.href; }, 300); // This is the best way that I've found to delay navigation for 300 milliseconds, which seems sufficient.
}

//Automatic File and Outbound Link Tracking from ROI
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); // "this" refers to the link element itself. You can also use "this.href" to just pass the href value.
						return false; // Necessary to override default link behavior.
					};
				}
			} else {
				hrefs[l].onclick = function(){
					trackfiles(this);
					return false;
				};
			}
		}
		catch(err) { }
}
