$(function() {
     $.fn.maphilight.defaults = {
       fill: true,
       fillColor: 'E3E9F0',
       fillOpacity: 0.8,
       stroke: true,
       strokeColor: 'E3E9F0',
       strokeOpacity: 1,
       strokeWidth: 1,
       fade: true,
       alwaysOn: false
     }
     $('.map').maphilight();
     
      $('.trigger').each(function(){
         var trigger = $(this);
         var id = $(trigger).attr('rel');
         var popup = $('#tooltip_'+id);
         var beingShown = false;
         var shown = false;
         var hideDelayTimer = null;
         var hideDelay = 100;
           
         $([trigger.get(0), popup.get(0)]).mouseover(function() {
           // stops the hide event if we move from the trigger to the popup element
           if (hideDelayTimer) clearTimeout(hideDelayTimer);
           
           if (beingShown || shown) {
                   return;
                 } else {
                   beingShown = true;
                   popup.fadeIn(100, function() {
                     beingShown = false;
                     shown = true;
                   });
                 }            
         }).mouseout(function() {
					if (popup.attr('rel') != 'show') {
           if (hideDelayTimer) clearTimeout(hideDelayTimer);
           // store the timer so that it can be cleared in the mouseover if required
               hideDelayTimer = setTimeout(function () {
                 hideDelayTimer = null;
                 popup.fadeOut(200,  function () {
                   // once the animate is complete, set the tracker variables
                   shown = false;
                   // hide the popup entirely after the effect (opacity alone doesn't do the job)
                   //popup.css('display', 'none');
                 });
               }, hideDelay);
							} else { return false; }
           });
         })
   });
