

// Author: Kris Purdy
// Date: 10/04/2007

//======================================================================
function createHotSpots() {
//pre: A HTML page with a <div id="id_of_imgmap" class="hotSpotImg"> 
//       and a corresponding javascript object in the format:
//       [{imgname; hotspots:[{title; pos:{ x; y; w; h}}, ...]}, ...].
//pst: An image map of hotspots.
  for (var i = 0; i < g_ImgMaps.length; i++) {
    if ($("#" + g_ImgMaps[i].imgname).size() != 0) {
      insertHotSpot(g_ImgMaps[i]);
    }
  }
}

//======================================================================
function insertHotSpot(a_ImgMap) {
//pre: An Image object of the format:
//       imgname; hotspots:[{title; pos:{ x; y; w; h}}, ...]. 
//pst: A complete image map on the image with id == imgname.
  var l_Html = "";
  var l_HotSpot = "";
  var l_ImgHS = a_ImgMap.hotspots
  for (var i = 0; i < l_ImgHS.length; i++) {
    l_Html = "<div id='" + l_ImgHS[i].title + "Marker' "
      + "class='hotSpotMarker'> </div>";
    $("#" + l_ImgHS[i].title).parent().append(l_Html);
    l_HotSpot = $("#" + l_ImgHS[i].title + "Marker");
    l_HotSpot.parent().css("left", l_ImgHS[i].pos.x + "px");
    l_HotSpot.parent().css("top", l_ImgHS[i].pos.y + "px");
    l_HotSpot.css("width", l_ImgHS[i].pos.w + "px");
    l_HotSpot.css("height", l_ImgHS[i].pos.h + "px");
  } 
}

//======================================================================
function assignImgHotSpots() {
//pre: A HTML page with <div class="hotSpotImg">.
//pst: Hover events on image hotspots.
  $(".hotSpotImg").hover(
    function () {
      showImageHotSpots(this);
    },
    function () {
      hideImageHotSpots(this);
    } 
  );
  $(".hotSpot").hover(
    function (e) {
      showHotSpotTip(e, this);
    },
    function (e) {
      hideHotSpotTip(e, this);
    }
  );
}

//======================================================================
function showImageHotSpots(a_Img) {
//pre: A DOM element of type: <div class="hotSpotImg">.
//pst: Shows the hotspots for the given img.
  $(a_Img).children(".hotSpot").children(".hotSpotMarker").fadeTo("slow"
    , 0.5);
}

//======================================================================
function hideImageHotSpots(a_Img) {
//pre: A DOM element of type: <div class="hotSpotImg">.
//pst: Hides the hotspots for the given img.
  $(a_Img).children(".hotSpot").children(".hotSpotMarker").fadeTo("slow"
    , 0.0);
}

//======================================================================
function showHotSpotTip(e, a_HotSpot) {
//pre: A DOM element of type: <div class="hotSpot">.
//pst: Shows hot spot tool tip.
  var l_HS = $("#" + $(a_HotSpot).children(".hotSpotTip").get(0).id);
  l_HS.css("left", "0px");
  l_HS.css("top", $(a_HotSpot).height());
  l_HS.fadeIn("slow");
}

//======================================================================
function hideHotSpotTip(e, a_HotSpot) {
//pre: A DOM element of type: <div class="hotSpotImg">.
//pst: Hides hot spot tool tip.
  var l_HS = $("#" + $(a_HotSpot).children(".hotSpotTip").get(0).id);
  l_HS.fadeOut("slow");
}

