﻿Tactica.Statistics = new Object();

Tactica.Statistics.GetDomain = function()
{
	var url = location.href;
	var pos = url.indexOf("://");

	if (pos >= 0) pos = url.indexOf("/", pos + 3);
	if (pos >= 0) url = url.substr(0, pos);

	return url;
}

Tactica.Statistics.Initialize = function(id)
{
	var fn = function() { window._tracker = _gat._getTracker(id); window._tracker._trackPageview(); };
	var pt = Tactica.Statistics.GetDomain();

	$(document).ready(function()
	{
		$("head").each(function(i)
		{
			var script = document.createElement("SCRIPT");

			script.onload = function() { fn() };
			script.onreadystatechange = function() { if (script.readyState == "complete" || script.readyState == "loaded") fn() };
			script.src = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.") + "google-analytics.com/ga.js";
			script.type = "text/javascript";

			this.appendChild(script);
		});

		$("a").each(function(i)
		{
			var path = this.href.replace(pt, "").replace(/\?.*$/gi, "");
			var pathInternal = /^.*?:\/\/|^javascript:|\.(asp|aspx|htm|html|shtm|shtml)$/i.test(path);

			if (pathInternal == false)
			{
				this.href_stats = path;

				$(this).click(function(e) { window._tracker._trackPageview(this.href_stats) });
			}
		});
	});
}
