$(function () {
  $('.facebook_zakladka').each(function () {
    var distance = 250;
    var time = 350;
    var hideDelay = 700;
    var hideDelayTimer = null;
    var beingShown = false;
    var shown = false;
    var trigger = $('.fb_wyzwalacz', this);
    var popup = $('.fb_pasek', this).css('opacity', 0);

    $([trigger.get(0), popup.get(0)]).mouseover(function () {
     
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

     
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

      
        popup.css({
          top: -10,
          left: 0,
          display: 'block' 
        })

      
        .animate({
          left: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
         
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          left: '+=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
         
          shown = false;
          
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
});

