$(function(){
	var offsetX  = -22; // tooltip X offset
	var offsetY = 12;  // tooltip Y offset
	$(".imagemap dl.map").addClass("on");
	var mapwidth = $(".imagemap img.map").width();
	var mapheight = $(".imagemap img.map").height();
	
	// set the location of the dl to the image map
	$(".imagemap dl.map").css("width", mapwidth);
	$(".imagemap dl.map").css("height", mapheight);
	var imagemaptop = $(".imagemap img.map").offset().top;
	//$(".imagemap dl.map").css("top", imagemaptop);
	var imagemapleft = $(".imagemap img.map").offset().left;
	//if ($.browser.msie && $.browser.version < 8)
	//	$(".imagemap dl.map").css("left", imagemapleft);

	$(".imagemap dt").mouseover(function() {
		var dd = $(this).next();
		//get width and height of the dd
		var ddwidth = dd.width();
		var ddheight = dd.height();
		//figure out where tooltip should be places based on point location
		var newX = $("a", this).offset().left - imagemapleft + offsetX;
		var newY = $("a", this).offset().top - imagemaptop + offsetY;
		//check if tooltip fits map width 
		if ((newX + ddwidth) > mapwidth) {
			dd.css("left", newX - ddwidth - 24);
		} else {
			dd.css("left", newX);
		};
		//check if tooltip fits map height 
		if ((newY + ddheight) > mapheight) {
			dd.css("top", newY - ddheight - 14);
		} else {
			dd.css("top", newY);
		};
		// set the location link to selected
		$("div.locationlinks a#locationlink" + $("a", this).attr("id")).addClass("hover");
	});
	$(".imagemap dt, div.locationlinks a").mouseout(function() {
		$(".imagemap dd").css("left", -9999);
		// remove the hover class from locationlinks and dt
		$(".imagemap dt a, div.locationlinks a").removeClass("hover");
	});
	
	// remove link for Harlan
	$('.imagemap dt a').click(function() {
		return false;
	});
});

function showImageMapLocation(locationID) {
    $(".imagemap dt a#" + locationID).parent().trigger("mouseover");
    $(".imagemap dt a#" + locationID).addClass("hover");
}
