//	Javascript to tag file downloads and external links in Google Analytics
//	To use, a 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.
//

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)
                  {
				addtrackerlistener(hrefs[l]);
			}
		}
		catch(err) { }
}


function addtrackerlistener(obj) {
	if (obj.addEventListener) {
		obj.addEventListener('click', trackfiles, true);
	} else if (obj.attachEvent) {
		obj.attachEvent("on" + 'click', trackfiles);
	}
}

function trackfiles(array_element) {
    if (pageTracker)
    {
	    file_path = "";
	    if (location.host != this.hostname) {
	    // For Image links we need to get the parent's host/path
	        if (array_element.srcElement && array_element.srcElement.tagName && array_element.srcElement.tagName == "IMG")
	        {
	            file_path = "/external/" + array_element.srcElement.parentNode.hostname + "/" + array_element.srcElement.parentNode.pathname ;
	        }
	        else
	        {
		        file_path = "/external/" + ((array_element.srcElement) ? array_element.srcElement.hostname + "/" + array_element.srcElement.pathname  : this.hostname + "/" + this.pathname);
            }
	    }
	    pageTracker._trackPageview(file_path);
    }
}