﻿var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

if (!window.App) var App = {};
App.initGoogleAnalytics = function(gaCode, filetypes)
{
	App.googleAnalyticsCode = gaCode;
	App.googleAnalyticsFiletypes = filetypes;
	jQuery(document).ready(function()
	{
		try
		{
			var pageTracker = _gat._getTracker(App.googleAnalyticsCode);
			pageTracker._trackPageview();
			if ((window.location.href.indexOf("/myasg") > 0) || (window.location.href.indexOf("/MemberHome.aspx") > 0)) {
				pageTracker._setVar("ASG Member");
			}
		}
		catch (err) { }

		var filetypes = (App.googleAnalyticsFiletypes ? App.googleAnalyticsFiletypes : new RegExp("\.(pdf|doc*|xls*|ppt*|zip)$", "i"));

		jQuery("a").each(function()
		{
			var href = jQuery(this).attr("href");
			if (href)
			{
				if ((href.match(new RegExp("^https?\:", "i"))) && (!href.match(document.domain)))
				{
					// External link
					jQuery(this).click(function()
					{
						var extLink = href.replace(new RegExp("^https?\:\/\/", "i"), "");
						pageTracker._trackEvent("External", "Click", extLink);
					});
				}
				else if (href.match(new RegExp("^mailto\:", "i")))
				{
					// Mailto link
					jQuery(this).click(function()
					{
						var mailLink = href.replace(new RegExp("^mailto\:", "i"), "");
						pageTracker._trackEvent("Email", "Click", mailLink);
					});
				}
				else if (href.match(filetypes))
				{
					// File link
					jQuery(this).click(function()
					{
						var extension = (new RegExp("[.]").exec(href)) ? new RegExp("[^.]+$").exec(href) : undefined;
						var filePath = href.replace(new RegExp("^https?\:\/\/(www.)" + document.domain + "\/", "i"), "");
						pageTracker._trackEvent("Download", "Click - " + extension, filePath);
					});
				}
			}
		});
	});
}
