//	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: 	20-Jan-2009 by Julie L : new code version
//	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//

var link_path = "";
for (var l = 0; l < $('a').length; l++) {
	try {
		var link_path = $('a')[l].pathname;
		if (location.host == $('a')[l].hostname) {
			if (link_path.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {
				addtrackerlistener($('a')[l]);
			}
		} else {
			addtrackerlistener($('a')[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) {
	file_path = "";	
	var hostname = array_element.srcElement ? array_element.srcElement.hostname : this.hostname;
	if (location.host != hostname) {
		file_path = "/lien_externe/" + ((array_element.srcElement) ? "/" + array_element.srcElement.hostname : this.hostname);
	}
	file_path = file_path + ((array_element.srcElement) ? "/" + array_element.srcElement.pathname : this.pathname);
	// new code version
	pageTracker._trackPageview(file_path);	
}
