/****************************************************
     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.
	
	 -Updated to async GA
	 -Remove tracking of download links and mailto links
	 -Remove comments
	 -Code refactoring
     
     **Modified by Jordan Louis to reflect deprecation of _gat -> replaced with _gaq.
	 
****************************************************/


function addLinkerEvents() {
	var as = document.getElementsByTagName("a");
	var extTrack = ["publicinsite.com"];
	// List of local sites that should not be treated as an outbound link. 

	for(var i=0; i<as.length; i++) 
	{
		var flag = 0;
		var tmp = as[i].getAttribute("onclick");
		
		if(as[i].href.indexOf('javascript:') == -1 && as[i].href.indexOf('google-analytics.com') == -1 && as[i].href.indexOf("mailto:") == -1)
		// Ensure it is not a GA call, an email or javascript link
		{
			// Tracking outbound links off site - not the GATC
			for (var j=0; j<extTrack.length; j++) 
			{					
				if (as[i].href.indexOf(extTrack[j]) == -1) 
				{
					flag++;
				}
			}
			
			if (flag == extTrack.length) //Outgoing link?
			{
				as[i].onclick = function()
				{ 
					var splitResult = document.href.split("//");
					_gaq.push(['_trackPageview', '/outgoing/' +splitResult[1]]); //+ ";" +((tmp != null) ? tmp+";" : "");
                    //alert(document.href +"  /outgoing/" +splitResult[1]);
				};
					
			}
			else if (as[i].href.indexOf(addLinkerEvents_currentWebSite) == -1) //It's not an outgoing but it's not the current one
			{
				as[i].onclick = function()
				{ 
					  if (!_gaq) return true;
					  window.open(_gaq._getTrackerByName()._getLinkerUrl(document.href));
					  return false;

					//alert(document.href +"  _link " );
				};
					
			}
		}
	}
}

