$(function() {
	if (document.getElementsByTagName) {
		// Initialize external link handlers
		var hrefs = document.getElementsByTagName("a");
		for (var l = 0; l < hrefs.length; l++) {
			// try {} catch{} block added by erikvold VKI
			try{
				//protocol, host, hostname, port, pathname, search, hash
				if (hrefs[l].protocol == "mailto:") {
						startListening(hrefs[l],"click",trackMailto);
				} else if (hrefs[l].hostname == location.host) {
						var path = hrefs[l].pathname + hrefs[l].search;
						var isDoc = path.match(/\.(?:doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)($|\&|\?)/);
						if (isDoc) {
							startListening(hrefs[l],"click",trackExternalLinks);
						}
				// Fix to ignore JavaScript in hrefs
				} else if (!hrefs[l].href.match(/^javascript:/)) {
						startListening(hrefs[l],"click",trackExternalLinks);
				}
			}
			catch(e){
				continue;
			}
		}
	}
});

function startListening (obj,evnt,func) {
	if (obj.addEventListener) {
			 obj.addEventListener(evnt,func,false);
	} else if (obj.attachEvent) {
			 obj.attachEvent("on" + evnt,func);
	}
}

function trackExternalLinks (evnt) {
	var e = (evnt.srcElement) ? evnt.srcElement : this;
	while (e.tagName != "A") {
			 e = e.parentNode;
	}
	var lnk = (e.pathname.charAt(0) == "/") ? e.pathname : "/" + e.pathname;
	if (e.search && e.pathname.indexOf(e.search) == -1) lnk += e.search;
	
	var ext = lnk.substring(lnk.lastIndexOf('.') + 1);
	var file = lnk.substring(lnk.lastIndexOf('/')+1);
	
	if (e.hostname == location.host) {
	_gaq.push(['_trackPageview', location.pathname + '/downloads' + e.pathname]);_gaq.push(['_trackEvent',ext,file]);
	} 
	else if (e.hostname != location.host) {
if (e.hostname == "www.hln.be" || e.hostname == "www.7s7.be" || e.hostname == "www.demorgen.be" || e.hostname == "www.autozone.be" || e.hostname == "www.regiojobs.be" || e.hostname == "www.nina.be" || e.hostname == "www.goedgevoel.be" || e.hostname == "www.zone03.be" || e.hostname == "www.zone09.be" || e.hostname == "www.zone02.be" || e.hostname == "11dor.7sur7.be" || e.hostname == "gouden11.hln.be" || e.hostname == "ozo.regiojobs.be" || e.hostname == "www.ad.nl" || e.hostname == "www.volkskrant.nl" || e.hostname == "www.trouw.nl" || e.hostname == "www.parool.nl" || e.hostname == "www.vkbanen.nl" ||  e.hostname == "zorg.vkbanen.nl" || e.hostname == "onderwijs.vkbanen.nl" || e.hostname == "www.werkendichtbij.nl"){
	_gaq.push(['_trackPageview', '/outbound-dpg/' + e.hostname]);_gaq.push(['_trackEvent','outbound links','de persgroep websites',e.hostname]);
	}
		else  if (e.hostname != "www.hln.be" || e.hostname != "www.7s7.be" || e.hostname != "www.demorgen.be" || e.hostname != "www.autozone.be" || e.hostname != "www.regiojobs.be" || e.hostname != "www.nina.be" || e.hostname != "www.goedgevoel.be" || e.hostname != "www.zone03.be" || e.hostname != "www.zone09.be" || e.hostname != "www.zone02.be" || e.hostname != "11dor.7sur7.be" || e.hostname != "gouden11.hln.be" || e.hostname != "ozo.regiojobs.be" || e.hostname != "www.ad.nl" || e.hostname != "www.volkskrant.nl" || e.hostname != "www.trouw.nl" || e.hostname != "www.parool.nl" || e.hostname != "www.vkbanen.nl" || e.hostname != "zorg.vkbanen.nl" || e.hostname != "onderwijs.vkbanen.nl" || e.hostname != "www.werkendichtbij.nl"){
	_gaq.push(['_trackPageview', '/outbound/' + e.hostname]);_gaq.push(['_trackEvent','outbound links','other websites',e.hostname]);
	}
	}
}
