
jQuery(document).ready(function($){

var oMap = jQuery('#map');
var oMapToolTip = oMap.find('.map-details');

var mapAnchorWatch = null;
var mapToolTipWatch = null;

var mapToolTipWatchTimeout = null;

var toolTipOn = null;

var toolTipRemovalTimeout = 2000;


mapAnchorWatch = oMap
	.find('.map-link')
	.WatchBounds({
		inBounds: function($e,a){//Passes in event object and target
			if(toolTipOn)return;//If toolt is on return
			if(mapToolTipWatchTimeout)//If timeout has been set clear it
			{
				clearTimeout(mapToolTipWatchTimeout);
				mapToolTipWatchTimeout = null;	
			}
			if(mapToolTipWatch)//If tooltip watch is on without it being hoevered disable it
			{
				mapToolTipWatch.release();
				mapToolTipWatch = null;	
			}
			var sRel = a.attr('rel');//Get relation attribute
			oMapToolTip.find('.pod').css('display','none');//Hide tool tip content of all links
			oMapToolTip.find('#' + sRel).css('display','block');//Display content of current link
			oMapToolTip//Display tool tip
				.css({
					left: Math.round(a.position().left + a.width()),
					top: Math.round(a.position().top + (a.height() / 2)),
					display: 'block'	
				});
			mapToolTipWatch = oMapToolTip//Enable listener for tool tip
				.WatchBounds({
					inBounds: function(){
						toolTipOn = true;//Tool tip is on
						clearTimeout(mapToolTipWatchTimeout);//clear timeout for mouseout of anchor tag
						mapToolTipWatchTimeout = null;	
					},
					outBounds: function(){
						toolTipOn = null;//Tool tip is off	
						oMapToolTip.css({display: 'none'});//Hide tool tip	
						mapToolTipWatch.release();//Detach mouse listening
						mapToolTipWatch = null;	
					}		
				});	
				
		},
		outBounds: function(){
			if(toolTipOn)return;//If tooltip is on ignore this mouse out	
			mapToolTipWatchTimeout = setTimeout(function(){
				oMapToolTip.css({display: 'none'});//Hide tool tip	
				mapToolTipWatch.release();//Release tool tip watch
				mapToolTipWatch = null;
			},toolTipRemovalTimeout);		
		}
	});
		
});
