var imagemapUseMouseAsPopupLocation = false;
  $(function() {
    // Create javascript imagemap popups
    $("div.imagemapplaceholder").imagemap();
  });

(function($){

 /*
  Create imagemap popups for an imagemap
  */
  $.fn.imagemap = function (options) {
    // var config = $.extend({}, options || {});
    var config = options;

    var imagemaps = $(this);
    if (imagemaps.size() > 1) {
      $(this).each($(this).imagemap(config));
    }
    else if (imagemaps.size() == 1) {
      var curSpotOpen = "";
      var current = $(this);
      var img = current.find("img.imagemap");
      var map = current.find("map");
      var type = map.attr("alt");
      if (type != null && type != '' && type.contains(":")) {
        type = type.split(":")[1];      
      }
      else {
        type = 'mouseover';
      }
      // First hide all popups
      current.find(".imagemapplaceholder");
      
      var hide = function(id) {
        $(id).hide();
        curSpotOpen = "";
        return false;
      };
      
      var show = function(area,id,event) {
        if(curSpotOpen!="") {
          hide(curSpotOpen);
        }
        
        var spot = $(id);
        
        if(area!=null) {
          var x = 0;
          var y = 0;
          
          if (imagemapUseMouseAsPopupLocation) {
            x = event.clientX + config.offset.x + $(window).scrollLeft();
            y = event.clientY + config.offset.y + $(window).scrollTop();
          }
          else {
            // Imagemap is absolute gepositioneerd tov parent div
            x = 0;
            y = 0;

            var coords=area.attr("coords").split(",");
            var minX=10000;
            var minY=10000;
            var maxX=0;
            var maxY=0;
            var corInd;
            var shape=area.attr("shape").toLowerCase();
            
            if (shape.indexOf("poly") == 0 || shape.indexOf("rect") == 0 ) {
              for (corInd=0;corInd<coords.length;corInd+=2) {
                var curX=parseInt(coords[corInd],10);
                if (curX<minX) minX=curX;
                if (curX>maxX) maxX=curX;
              }
              for (corInd=1;corInd<coords.length;corInd+=2) {
                var curY=parseInt(coords[corInd],10);
                if (curY<minY) minY=curY;
                if (curY>maxY) maxY=curY;
              }
              x+=(minX+maxX)/2;
              y+=(minY+maxY)/2;
            }
            else if (shape=="circle") {
              x+=parseInt(coords[0],10);
              y+=parseInt(coords[1],10);
            }
          } 
            
          spot.css("left", x + "px");
          spot.css("top", y + "px");

          spot.show();
          curSpotOpen = id;
          
          return false;
        }
        
        return true;
      };

      current.find("map area").bind(type, function(event) {
        var area = $(this);
        var id = area.attr("href");
        return show(area, id, event);
      });
      current.find(".hotspot_popup").each(function() {
        var hotspot = $(this);
        var hotspotId = hotspot.attr("id");
        hotspot.find(".sluitkruis").click(function(event) {
          return hide("#"+hotspotId);
        });
      });
    }
  };
})(jQuery); 
