// Requires that Prototype.js and globals.js are loaded

var PracticalAnalytics = new Object();
PracticalAnalytics.save = function() {
	var now = new Date();
	
	if(analytics_url) {
		var path = analytics_url + "?do";
	}
	else {
		var path = "http://businesspov.com/analytics?do";
	}
	
	for(var module in this) {
		if(this[module].onsave) {
			path += this[module].onsave();
		}
	}
	
	// Slap the current time on there to prevent caching on subsequent page views in a few browsers
	path += '&'+now.getTime();
	
	//alert(path);
	
	if (document.write) {
		img_code = '<img src="'+path+'" alt="" style="position: absolute; left: -9999px;" onload="this.parentNode.removeChild(this);" />';
		//alert(img_code);
		document.write(img_code);
	}
	else
	{
		// Record this visit; uses XMLHttpRequest to play nice with pages served as application/xhtml+xml
		// Causes a security issue when served from a sub or other domain
		var data = false;
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		try { data = new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e) { try { data = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { data = false; } }
		@end @*/
		if (!data && typeof XMLHttpRequest!='undefined') { data = new XMLHttpRequest(); }
		if (data) { data.open("GET", path, true); data.send(null); }
	};
};

PracticalAnalytics.Referrer  = 
{
onsave: function() {
	if (typeof DocTitle=='undefined') {
		DocTitle = document.title;
	}
	
	var referer	= (window.decodeURI) ? window.decodeURI(document.referrer) : document.referrer;
	
	var resource = (window.decodeURI) ? window.decodeURI(document.URL) : document.URL;
	
	return '&visit[referer]=' + escape(referer) + '&visit[resource_url]=' + escape(resource) + '&visit[resource_title]=' + escape(DocTitle);
}};

PracticalAnalytics.WindowWidth = 
{
	onsave	: function() 
	{
		var width = -1;
		if (window.innerWidth)
		{
			width = window.innerWidth;
		}
		else if (document.getElementsByTagName)
		{
			var html = document.getElementsByTagName('html');
			if (html[0].offsetWidth)
			{
				width = html[0].offsetWidth;
			}
		}
		return '&visit[window_width]=' + width;
	}
};

PracticalAnalytics.UserAgent = 
{
	flashVersion		: 0,
	resolution			: '0x0',
	detectFlashVersion	: function () 
	{
		var m =16;
		var ua = navigator.userAgent.toLowerCase();
		if (navigator.plugins && navigator.plugins.length) 
		{
			var p = navigator.plugins['Shockwave Flash'];
			if (typeof p == 'object') 
			{
				for (var i=m;i>=3;i--) 
				{
					if (p.description && p.description.indexOf(' ' + i + '.') != -1) { this.flashVersion = i; break; }
				}
			}
		}
		else if (ua.indexOf("msie") != -1 && ua.indexOf("win")!=-1 && parseInt(navigator.appVersion) >= 4 && ua.indexOf("16bit")==-1) 
		{
			var vb = '<scr' + 'ipt language="VBScript"\> \nOn Error Resume Next \nDim obFlash \nFor i = ' + m + ' To 3 Step -1 \n   Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash." & i) \n   If IsObject(obFlash) Then \n      Mint.SI.UserAgent007.flashVersion = i \n      Exit For \n   End If \nNext \n<'+'/scr' + 'ipt\> \n';
			document.write(vb);
		}
		else if (ua.indexOf("webtv/2.5") != -1) this.flashVersion = 3;
		else if (ua.indexOf("webtv") != -1) this.flashVersion = 2;
		return this.flashVersion;
	},
	onsave				: function() 
	{
		this.resolution = screen.width+'x'+screen.height;
		return '&visit[resolution]=' + this.resolution + '&visit[flash_version]=' + this.flashVersion;
	}
};

PracticalAnalytics.UserAgent.detectFlashVersion();
PracticalAnalytics.save();