$(function(){
	$(".imagemap dl.map").addClass("on");

	var $mapdl = $('.imagemap dl.map'),
		maptop = $mapdl.offset().top,
		mapleft = $mapdl.offset().left,
		mapwidth = $mapdl.width(),
		mapheight = $mapdl.height();

	$(".imagemap dt").mouseover(function() {
		var $dd = $(this).next(),
			$a = $(this).find('a'),
			ddwidth = $dd.width();
			ddheight = $dd.height(),
			//figure out where tooltip should be places based on point location
			newX = $a.offset().left - mapleft,
			newY = $a.offset().top - maptop;
		//check if tooltip fits map width 
		if (newX + ddwidth > mapwidth) {
			$dd.css({left: 'auto', right: mapwidth - newX});
		} else {
			$dd.css("left", newX);
		};
		//check if tooltip fits map height 
		if (newY + ddheight > mapheight) {
			$dd.css("bottom", mapheight - newY);
		} else {
			$dd.css("top", newY);
		};
		// set the location link to selected
		$("div.locationlinks a#locationlink" + $a.attr("id")).addClass("hover");
	}).mouseout(function() {
		$(".imagemap dd").css("left", -9999);
		$(".imagemap dt a").removeClass("hover");
	});
});

function showImageMapLocation(locationID) {
    $(".imagemap dt a#" + locationID).parent().trigger("mouseover");
    $(".imagemap dt a#" + locationID).addClass("hover");
}