// JavaScript Document
$(function(){
	
/*$('.advocaten li').hover(function(){
		$(this).find('.tooltip').show();							  
	}, function(){
		$(this).find('.tooltip').hide();
	});*/
		//add empty block as container for the tooltips
		$('<div id="tooltip-container" style="position:absolute;"></div>').prependTo('body');
		
		//returns the mouse location//
   		function getMouseLocations(e) {
			var posx = 0;
			var posy = 0;
			if (!e) var e = window.event;
			if (e.pageX || e.pageY) 	{
				posx = e.pageX;
				posy = e.pageY;
			}
			else if (e.clientX || e.clientY) 	{
				posx = e.clientX + document.body.scrollLeft
					+ document.documentElement.scrollLeft;
				posy = e.clientY + document.body.scrollTop
					+ document.documentElement.scrollTop;
			}
			return [posx, posy];
		}
		
		
		
		//on mouse over keep the tooltip-container hidden for 500 ms	
		$('.advocaten li').mouseover(function(e){
			$(this).css("cursor","pointer"); 
			$('#tooltip-container').html("");
			$(this).find('.tooltip').clone().prependTo('#tooltip-container').show();
			$('#tooltip-container').hide();
			t=setTimeout("show()",500);
		});	
		//on mouse out remove the timeout to make sure the tooltip-container doesnt appear while not hovering.		
		$('.advocaten li').mouseout(function(e){
			clearTimeout(t)
			$('#tooltip-container').html("");			
		})
		
		//on mousemove copy the tooltip that belongs to the info button
		//hover the clone of the tooltip at the mouse location
		$('.advocaten li').mousemove(function(e){			
				var mouseX = getMouseLocations(e)[0];
				var mouseY = getMouseLocations(e)[1];
				
				
				$('#tooltip-container').css('z-index',10000);
				$('#tooltip-container').css('left',mouseX + 10);
				$('#tooltip-container').css('top',mouseY+ 10);
				
				var totalWidth = $('#tooltip-container').width() + mouseX+15;
				//alert($('#tooltip-container').width())
				if(totalWidth > $(window).width()){
				//	alert();
					var newX =  $(window).width() -  $('#tooltip-container').width()-10;
					$('#tooltip-container').css('left',newX);
				}
				
		});


	});

function show(){
	$('#tooltip-container').show();
} 	
	
	

