/****************************************************
     Author: Brian J Clifton
     Url: http://www.advanced-web-metrics.com/scripts
     This script is free to use as long as this info is left in
     
     Combined script for tracking external links, file downloads and mailto links
     
     All scripts presented have been tested and validated by the author and are believed to be correct
     as of the date of publication or posting. The Google Analytics software on which they depend is 
     subject to change, however; and therefore no warranty is expressed or implied that they will
     work as described in the future. Always check the most current Google Analytics documentation.

     Thanks to Nick Mikailovski (Google) for intitial discussions & Holger Tempel from webalytics.de
     for pointing out the original flaw of doing this in IE.

****************************************************/
// Only links written to the page (already in the DOM) will be tagged
// This version is for ga.js (last updated Jan 15th 2009)

// E-Nor added the prefix “tracker_” before all variables names (last updated on November 12th 2009)

function addLinkerEvents() {
	var tracker_as = document.getElementsByTagName("a");
	var tracker_extTrack = ["calacademy.org"];	// List of local sites that should not be treated as an outbound link. Include at least your own domain here
	var tracker_extDoc = [".doc",".xls",".exe",".zip",".pdf",".js"];  //List of file extensions on your site. Add/edit as you require
	
	for(var i=0; i<tracker_as.length; i++) {
		var tracker_flag = 0;
		var tracker_tmp = tracker_as[i].getAttribute("onclick");

		if (tracker_tmp != null) {
		  tracker_tmp = String(tracker_tmp);
		  if (tracker_tmp.indexOf('urchinTracker') > -1 || tracker_tmp.indexOf('_trackPageview') > -1) continue;
    		}

// Tracking File Downloads
		for (var j=0; j<tracker_extDoc.length; j++) 
		{
			if (tracker_as[i].href.indexOf(tracker_extTrack[0]) != -1 && tracker_as[i].href.indexOf(tracker_extDoc[j]) != -1) 
			{
				tracker_as[i].onclick = function(){ var tracker_splitResult = this.href.split(tracker_extTrack[0]);pageTracker._trackPageview('/virtual-page/downloads' +tracker_splitResult[1])+ ";"
+((tracker_tmp != null) ? tracker_tmp+";" : "");
}
				break;
			}
		}

		
	}
}
