//	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
//	Modified by: 	Florian Wegscheider
//	Last updated: 	02-Feb-2010
//	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
function trackfiles(array_element) {
	file_path = "";
	var myhost = this.hostname;
	if(array_element.srcElement) {
		myhost = array_element.srcElement.hostname;
	}
	
	file_path = ((array_element.srcElement) ? array_element.srcElement.hostname : this.hostname);
	link_title = ((array_element.srcElement) ? array_element.srcElement.innerHTML : this.innerHTML);
	
	
	if (location.host != myhost) {
		category = "Externer Link";
	} else {
		category = "Download";
	}
	
	file_path = file_path + ((array_element.srcElement) ? "/"+array_element.srcElement.pathname : this.pathname);
	
	if (pageTracker != undefined) {
		//Neu
		pageTracker._trackEvent(category, "Click", link_title + "(" + file_path + ")"); 
		//alert('test');
			
		//Vorher
		//	pageTracker._trackPageview(file_path);
	} else {
		urchinTracker(file_path);
	}
	
}

function addtrackerlistener(obj) {

	file_path = "";
	var myhost = this.hostname;
	var regStr = /^(.*[.])austria[.]info/;
	// externer link
	if (
		location.host != obj.hostname &&
		regStr.test(obj.hostname) == false &&
		obj.hostname != 'austria.info' &&
		obj.hostname.substring(0,11) != "javascript:" &&
		obj.hostname.substring(0,7) != "mailto:" &&
		obj.hostname != "" &&
		$(obj).find('img').length == 0
	) {
		//Klasse hinzufügen
		$(obj).addClass("externLink");
	}
	
	
	if (obj.addEventListener) {
		obj.addEventListener('click', trackfiles, false);
	} else if (obj.attachEvent) {
		obj.attachEvent("on" + 'click', trackfiles);
	}
}




var hrefs = document.getElementsByTagName("a");
var link_path = "";
// alle links durchparsen

for (var tli = 0; tli < hrefs.length; tli++) {
		try {
			var link_path = hrefs[tli].pathname;
			// interner link
			if (location.host == hrefs[tli].hostname) {
				// download
				if (link_path.match(/\.(doc|pdf|xls|ppt|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)$/)) {
					addtrackerlistener(hrefs[tli]);
				}
			// externer link
			} else {
				addtrackerlistener(hrefs[tli]);
			}
		}
		catch(err) { }
}