jQuery.fn.extend({
  pixelIsInside: function(x,y,calIfInside,callData) {
       x = parseInt(x || 0);
       y = parseInt(y || 0);
       if (isNaN(x) || isNaN(y)) return false;

       var isInside = false;
       var i=0;
       this.filter(":visible").each(function() {
           if (isInside) return false;

           var o = $(this).offset();
           isInside = (x >= o.left && x <= o.left+$(this).outerWidth() && y >= o.top && y <= o.top+$(this).outerHeight());

           if (isInside && calIfInside && typeof(calIfInside) == "function") {
               try {calIfInside(this,i,x,y,callData);}catch(e){}
           }
           i++;
           return !isInside;
       });

       return isInside;
   }
});


$(document).ready(function() {
    $("img#img11146, img#img11145,img#img13932,img#img13933,img#img13934,img#img13935").each(function() {
        var findImg = $(this).attr("src").replace(/_overlay/, "").replace(/.*\/([^\/]+)$/, "$1");
        var triggerImage = $("#nexxarReportContent img[src*=" + findImg + "]").get(0);
        var pos = $(triggerImage).position();
        var myID = $(this).parent("div.bild").attr("id");
        if (!myID) {
            myID = findImg + Math.floor(Math.random()*9999);
            $(this).parent("div.bild").attr("id", myID);
        }

        $(this).parent("div.bild")
          .hide()
          .css({position: "absolute", left: pos.left+$(triggerImage).width(), top: pos.top}).
          mouseout(function(ev) {
              if (!$(triggerImage).pixelIsInside(ev.pageX, ev.pageY))
                  $(this).hide();
          });

        $(triggerImage).get(0).overlayImage = $(this).parent("div.bild");
        $(triggerImage).mouseover(function() {
            //alert("mouseover image");
            $($(this).get(0).overlayImage).show();
        }).mouseout(function(ev) {
            if (!$($(this).get(0).overlayImage).pixelIsInside(ev.pageX, ev.pageY))
                $($(this).get(0).overlayImage).hide();
        });
    });
});



