// JavaScript Document
// Only links written to the page (already in the DOM) will be tagged
// This version is for ga.js (July 15th 2008)

doc, eps, jpg, png, svg, xls, ppt, pdf, xls, zip, txt, vsd, vxd, js, css, rar, exe, wma, mov, avi, wmv, mp3


function addLinkerEvents() {
	var as = document.getElementsByTagName("a");
	var extTrack = ["youtube.com","adobe.com"];
	// List of local sites that should not be treated as an outbound link. Include at least your own domain here
	
	var extDoc = [".doc",".xls",".exe",".zip",".pdf",".js",".eps",".jpg",".png",".ppt",".txt",".css",".rar",".wma",".mov",".avi",".wmv",".mp3"];
	//List of file extensions on your site. Add/edit as you require
	
	/*If you edit no further below this line, Top Content will report as follows:
		/ext/url-of-external-site
		/downloads/filename
		/mailto/email-address-clicked
	*/
	
	for(var i=0; i<as.length; i++) {
		var flag = 0;
		var tmp = as[i].getAttribute("onclick");
		if (tmp != null && (tmp.indexOf('urchinTracker') > -1 || tmp.indexOf('_trackPageview') > -1) ) continue;

		// Tracking outbound links off site - no GATC
		for (var j=0; j<extTrack.length; j++) {					
			if (as[i].href.indexOf(extTrack[j]) == -1 && as[i].href.indexOf('google-analytics.com') == -1 ) {
				flag++;
			}
		}
		if (flag == extTrack.length){
			var splitResult = as[i].href.split("//");
			as[i].setAttribute("onclick",((tmp != null) ? tmp+";" : "") + "pageTracker._trackPageview('/ext/" +splitResult[1]+ "');");
		}			


		// Tracking electronic documents - doc, xls, pdf, exe, zip
		for (var j=0; j<extDoc.length; j++) {
			if (as[i].href.indexOf(extTrack[0]) != -1 && as[i].href.indexOf(extDoc[j]) != -1) {
				var splitResult = as[i].href.split(extTrack[0]);
				as[i].setAttribute("onclick",((tmp != null) ? tmp+";" : "") + "pageTracker._trackPageview('/downloads" +splitResult[1]+ "');");
				//alert(splitResult[1])
				break;
			}
		}


		// Change CLIENT@EXAMPLE.com to reflect the email address on page.  This may be repeated for other email links on site.
		if (as[i].href.indexOf("mailto:") != -1  && as[i].href.indexOf("info@colorworks.ca") == -1 ) {
			var splitResult = as[i].href.split(":");
			as[i].setAttribute("onclick",((tmp != null) ? tmp+";" : "") + "pageTracker._trackPageview('/mailto/" +splitResult[1]+ "');");
			//alert(splitResult[1])
			break;
		}
	}
}

