$(document).ready(function() {
  $('a[href="#poptavka"]').fancybox({'overlayShow': true, 'frameHeight': 500});
  $('.easydooris-prehled .item').click(function() {
    window.location = $(this).find('a').attr('href');
  });
  $('.easydooris-prehled .item').css('cursor', 'pointer');

  $('.clickable').click(function() {
    window.location = $(this).find('a:first').attr('href');
  });
  
  $('.clickable').hover(function() {
    $(this).addClass('clickable-hover');
  }, function() {
    $(this).removeClass('clickable-hover');
  });
  
  $('.clickable').css('cursor', 'pointer');

  //this is the floating content
  var $floatingbox = $('.poptavka-butt');
  if ($floatingbox.length && ! $floatingbox.hasClass('no-scroll')) {
    var offset = $('.poptavka-butt').offset();
    var bodyY = parseInt(offset.top) - 30;
    var originalX = $floatingbox.css('margin-left');
    var bodyX = parseInt(offset.left);
  
    $(window).scroll(function () { 
      var scrollY = $(window).scrollTop();
      var isfixed = $floatingbox.css('position') == 'fixed';
   
      if($floatingbox.length > 0){
        if ( scrollY > bodyY && !isfixed ) {
          $floatingbox.stop().css({
            position: 'fixed',
            left: bodyX,
            top: 20,
            marginLeft: 0
          });
  
        } else if ( scrollY < bodyY && isfixed ) {
          $floatingbox.css({
            position: 'relative',
            left: 0,
            top: 0,
            marginLeft: originalX
          });
        }
      }
    });
  }
});

