var clickedLink = "";
var clickedLinkTimer;
var refreshing = false;

$(document).ready(function()
{
	$.post("/index.php",
	{
		action: 'start',
		unihash: unihash,
		request: request,
		page: page,
		type: type,
		url: document.location.toString(),
		referrer: referrer
	});
	
	$('a').click(function()
	{
		if($(this).attr('href') != "")
		{
			$.post("/index.php",
			{
				action: 'link',
				ip: ip,
				unihash: unihash,
				url: url,
				page: page,
				deferrer: $(this).attr('href'),
				theclass: $(this).attr('class')
			});
			
			window.clearTimeout(clickedLinkTimer);
			clickedLink = $(this).attr('href');
			clickedLinkTimer = window.setTimeout('resetClickedLink()',10);
		}
	});
	
	$(window).bind('beforeunload', function()
	{
		if(!refreshing)
		{
			$.post("/index.php",
			{
				action: 'end',
				ip: ip,
				unihash: unihash,
				deferrer: clickedLink
			});
		}
	});
	
	$(document).keydown(function(event)
	{
		if(event.keyCode == 116)
		{
			refreshing = true;
			$.post("/index.php",
			{
				action: 'end',
				ip: ip,
				unihash: unihash,
				deferrer: request
			});
		}
	});
	
	var latlng = new google.maps.LatLng(51.40393, 7.66819);
	
	if(document.getElementById("googleMap"))
	{
		var map = new google.maps.Map(document.getElementById("googleMap"),
		{
			zoom: 15,
			center: latlng,
			mapTypeId: google.maps.MapTypeId.SATELLITE
		});
		
		setTimeout(function() 
		{
			var marker = new google.maps.Marker(
			{
				position: latlng,
				map: map,
				draggable: false,
				animation: google.maps.Animation.DROP
			});
		}, 1000);
	}
	
	$('#facebook .facebookLabel').hover(function()
	{
		$('#facebook').css('z-index', '5');
		$('#facebook iframe').show();
	}, function()
	{
		//$('#facebook').css('z-index', '1');
	});
	
	$('#facebook').hover(function()
	{
		//$('#facebook').css('z-index', '5');
	}, function()
	{
		$('#facebook').css('z-index', '1');
		$('#facebook iframe').hide();
	});
});
