// JavaScript Document

var mousePos = "";
var mouseClick = "";
var curPage = window.location.href;
var wHeight = "";
var wWidth = "";

jQuery(document).ready(function(){
			
	wHeight = $(window).height();
   	wWidth = $(window).width();			
			
   	$().mousemove(function(e){
	  mousePos +=  (e.pageX - (wWidth/2)) +','+ (e.pageY - (wHeight/2)) + ';';
      //$('#status').html(mousePos);
   	}); 
   
   	$('*').click(function(e){
	  mouseClick += (e.pageX - (wWidth/2)) +','+ (e.pageY - (wHeight/2)) + ';';
      //$('#status').html(mouseClick);
    });
   
    $(document).keydown(
   function(e){
     var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
     
	 if( key == 77 ){
		 $.ajax({
			  url: "http://www.carpentermedia.nl/mtracker/loadMouseField.php",
			  data: "uri=" + curPage,
			  cache: false,
			  success: function(html){
				$('#blaat').html(html);
			  }
		  });
	 }
					  
	});
   
   setTimeout("savePos()", 1000);
});

function savePos(){
	
	$.ajax({
	   type: "GET",
	   url: "http://www.carpentermedia.nl/mtracker/save.php",
	   data: "w=" + wWidth + "&h=" + wHeight + "&uri=" + curPage + "&pos=" + mousePos + "&click=" + mouseClick,
	   success: function(msg){
		mousePos = "";
		mouseClick = "";
		setTimeout("savePos()", 1000);
	   }
	});
}