/* Copyright (c) Motoki, 2010 */
/*   motokisensei@gmail.com   */
/*  Developed for FarGate.RU  */

// A More Accessible Map. Copyright (c) Seth Duffey
// http://alistapart.com/articles/cssmaps

Supernatural.Map = {

	offsetX: -16,
	offsetY: 16,
	element: false,

	showTooltip: function()
	{
		var objid = this.parentNode.nextSibling;
		Supernatural.Map.element = objid;
		var mapWidth  = objid.parentNode.offsetWidth;
		var mapHeight = objid.parentNode.offsetHeight;
		var toopTipWidth = objid.offsetWidth;
		var toopTipHeight = objid.offsetHeight;
		var newX = this.offsetLeft + Supernatural.Map.offsetX;
		var newY = this.offsetTop + Supernatural.Map.offsetY;
		objid.style.left = ((newX + toopTipWidth) > mapWidth) ?
			newX - toopTipWidth - 24 + 'px' : newX + 'px';
		objid.style.top = ((newY + toopTipHeight) > mapHeight) ?
			newY - toopTipHeight - 14 + 'px' : newY + 'px';
	},
	
	hideTooltip: function()
	{
		Supernatural.Map.element.style.left = '-9999px';
	}

}
 
$(document).ready(function() {
	$('dl.map dt a').each(function() {
		$(this).mouseover(Supernatural.Map.showTooltip);
		$(this).mouseout(Supernatural.Map.hideTooltip);
		$(this).focus(Supernatural.Map.showTooltip);
		$(this).blur(Supernatural.Map.hideTooltip);
	});
});
