try
{

	var memory = '';
	var timerOn = false;
	var mouseMovement = false;

	var lastMousePosition = null;
	var storePoll = 250;
	var storeTimeout = 5000;
	var memoryEmpty = true;

	var isIE = document.all?true:false;
	if (!isIE) document.captureEvents(Event.MOUSEMOVE | Event.CLICK | Event.UNLOAD);
	document.onmousemove = captureMouseMovement;
	document.onclick = captureMouseClick;
	window.onbeforeunload = unloadPage;

	var storeTimeoutRef = setTimeout(sendTimeout, storeTimeout);

	function captureMouseMovement(e)
	{
		try
		{
			// Save the current position
			lastMousePosition = getMousePosition(e);
				
			// Set that we saw the mouse move
			mouseMovement = true;
			
			// If we dont already have a timer running
			if (!timerOn)
			{
			
				// Record this mouse movement
				storeMousePosition(lastMousePosition, false);
				
				// Set a timer to record the next one
				setTimeout(tickStoreMousePosition, storePoll);
				
				// We set a timer
				timerOn = true;
			}
		}
		catch(exp)
		{
		
		}
	}

	function tickStoreMousePosition()
	{		
		try
		{
			// If there was mouse movement since the last time we recorded
			if (mouseMovement)
			{
			
				// Display and store the mouse position
				storeMousePosition(lastMousePosition, false);
			
				// Then set another timer
				setTimeout(tickStoreMousePosition, storePoll);
				
				// And reset the mouse movement flag
				mouseMovement = false;
				
			}
			else
			{
			
				// We didnt set a timer
				timerOn = false;
				
			}
		}
		catch(exp)
		{
		
		}
	}

	function getMousePosition(e)
	{		
		try
		{
			var mouseX = 0;
			var mouseY = 0;
			if (isIE) { // grab the x-y pos.s if browser is IE
				mouseX = event.clientX + document.body.scrollLeft
				mouseY = event.clientY + document.body.scrollTop
			} else {  // grab the x-y pos.s if browser is NS
				mouseX = e.pageX
				mouseY = e.pageY
			}
			
			var d = new Date();
			
			return { "mouseX" : mouseX, "mouseY" : mouseY, "timestamp" : d.getTime() };
		}
		catch(exp)
		{
		
		}
	}

	function storeMousePosition(mousePosition, wasClick)
	{
		try
		{
			var text;
			if (wasClick)
			{
				text = ';.'+mousePosition.mouseX+','+mousePosition.mouseY+','+mousePosition.timestamp;
			}
			else
			{
				text = ';'+mousePosition.mouseX+','+mousePosition.mouseY+','+mousePosition.timestamp;
			}
			
			memory += text;
			memoryEmpty = false;
		}
		catch(exp)
		{
		
		}
	}

	function captureMouseClick(e)
	{
		try
		{
			storeMousePosition(lastMousePosition, true);
		}
		catch(exp)
		{
		
		}
	}

	function unloadPage(e)
	{
		try
		{
			sendBatch();
		}
		catch(exp)
		{
		
		}
	}

	function sendTimeout(e)
	{
		try
		{
			sendBatch();
		}
		catch(exp)
		{
		
		}
	}

	function getAndEmptyMemory()
	{
		try
		{
			var memoryBefore = memory;
			memory = '';
			memoryEmpty = true;
			return memoryBefore;
		}
		catch(exp)
		{
		
		}
	}

	function sendBatch()
	{
		try
		{
			clearTimeout(storeTimeoutRef);	
			
			if (!memoryEmpty)
			{		
				
				var batch = getAndEmptyMemory();					
			
				var xmlhttp = initXMLHttpClient();
							
				var url = "scripts/mousetrackerstorer.php";
				var screenWidth = 'na';
				var screenHeight = 'na';
				try
				{
					if (screen.width)
					{
						screenWidth = screen.width;
					}
					if (screen.height)
					{
						screenHeight = screen.height;
					}
				}
				catch (ex)
				{
				
				}
				var params = "sw="+screenWidth+"&sh="+screenHeight+"&mtdata="+batch;
				xmlhttp.open("POST", url, false);

				//Send the proper header information along with the request
				xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				xmlhttp.setRequestHeader("Content-length", params.length);
				xmlhttp.setRequestHeader("Connection", "close");

				xmlhttp.onreadystatechange = function() 
				{
					if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						//alert(xmlhttp.responseText);
					}
				}
				xmlhttp.send(params);
			}
			
			storeTimeoutRef = setTimeout(sendTimeout, storeTimeout);
		}
		catch(exp)
		{
		
		}
	}	

	function initXMLHttpClient() 
	{
		try
		{
			var xmlhttp;
			try 
			{
				// Mozilla / Safari / IE7
				xmlhttp = new XMLHttpRequest();
			} 
			catch (e) 
			{
				// IE
				var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0',	'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP',	'Microsoft.XMLHTTP');
				var success = false;
				for (var i=0;i < XMLHTTP_IDS.length && !success; i++) 
				{
					try 
					{
						xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
						success = true;
					} 
					catch (e) 
					{
					}
				}
				if (!success) 
				{
					throw new Error('Unable to create XMLHttpRequest.');
				}
			}
			return xmlhttp;
		}
		catch(exp)
		{
		
		}
	}
}
catch(exp)
{

}
