//	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: 	12-Feb-2006
//  Modified: T-media, 14-Dec-2007
//	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//

function gaUtilAddTrackers() {
	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)$/)) {
					gaUtilAddTrackerListener(hrefs[l]);
				}
			} else {
				gaUtilAddTrackerListener(hrefs[l]);
			}
		}
		catch(err) { }
	}
    
    // special tracking?
    if ( typeof(tmd_specialTracker) != 'undefined' ) pageTracker._trackPageview(tmd_specialTracker);
}


function gaUtilAddTrackerListener(obj) {
	if (obj.addEventListener) {
		obj.addEventListener('click', gaUtilTrackFiles, true);
	} else if (obj.attachEvent) {
		obj.attachEvent("on" + 'click', gaUtilTrackFiles);
	}
}

function gaUtilTrackFiles(array_element) {
	var file_path = "";
	var this_host = array_element.srcElement ? array_element.srcElement.hostname : this.hostname

	if ( location.host != this_host ) {
		file_path = "/zunanji/" + ((array_element.srcElement) ? array_element.srcElement.hostname : this.hostname);
	}
	file_path = file_path + ((array_element.srcElement) ? "/" + array_element.srcElement.pathname : this.pathname);
	// old GA: urchinTracker(file_path);
	pageTracker._trackPageview(file_path);
}


// Activate
gaUtilAddTrackers();
