/**************************************************************************************************
	ING Investment Management Custom Analytics Code
	Date Created:		2010-12-01
	Date Updated:		2010-12-01
	
	This script is designed to tag "a" links on a webpage for the Google Analytics Tracking code.
	
	This script is based on the concept found at: http://www.advanced-web-metrics.com/scripts
**************************************************************************************************/
if (typeof jQuery != 'undefined') {
	$(document).ready(function() {
		var extTrack = [document.domain];
		var extDoc = [".doc",".xls",".exe",".zip",".pdf",".js",".gif",".jpg",".ppt","IdcService=GET_FILE", ".xml"];
		//List of file extensions on your site. Add/edit as you require
		
		$("a").each(function() {
			var flag = 0;
			var tmp = this.getAttribute("onclick");
			
			// IE6-IE7 fix (null values error) [from original script]
			if (tmp != null) {
				tmp = String(tmp);
				if (tmp.indexOf('urchinTracker') > -1 || tmp.indexOf('_trackPageview') > -1) return true;
    		}
			
			// Tracking outbound links off site - not the GATC
			for (var j=0; j<extTrack.length; j++) {					
				if (this.href.indexOf(extTrack[j]) == -1 && this.href.indexOf('google-analytics.com') == -1 ) {
					flag++;
				}
			}
			
			if (flag == extTrack.length && this.href.indexOf("mailto:") == -1) {
				this.onclick = function(){ 
				    //may want to consider recording as EVENT as well.
					_gaq.push(['_setCustomVar', 5, 'virtual', 'outbound', 3]);
					_gaq.push(['_trackPageview',this.href]) + ";" +((tmp != null) ? tmp+";" : "");
				};
			}
			
			// Tracking electronic documents - doc, xls, pdf, exe, zip
			for (var j=0; j<extDoc.length; j++) {
				if (this.href.indexOf(extTrack[0]) != -1 && this.href.indexOf(extDoc[j]) != -1) {
					this.onclick = function(){ 
						var splitResult = this.href.split(extTrack[0]);
						_gaq.push(['_setCustomVar', 5, 'virtual', 'download', 3]);
						_gaq.push(['_trackPageview',splitResult[1]])+";" + ((tmp != null) ? tmp+";" : "");
					}
					break;
				}
			}
			
			// Tracking "mailto" commands
			if (this.href.indexOf("mailto:") != -1) {
				this.onclick = function(){ 
					_gaq.push(['_setCustomVar', 5, 'virtual', 'mailto', 3]);
					_gaq.push(['_setVar','outbound']);_gaq.push(['_trackPageview',this.href])+ ";"+((tmp != null) ? tmp+";" : "");
				}
			}
		});
	});
}
