// JavaScript Document

$(document).ready(function() {
  // Magic
  $(window).scroll(function() {
    var Y = $(this).scrollTop();
    $('#feed .chated-poeople').each(function() {
      var $this = $(this),
        posY = $this.offset().top,
        posX = $this.offset().left,
        width = $this.width(),
        height = $this.height(),
        headerHeight = $this.find('.headerpost').height(),
        stop = (posY + height) - headerHeight;
      // Fixed on position top / or else
      if (Y > posY) {
        $this.find('.headerpost').css({
          position: 'fixed',
          top: 52,
          left: posX,
          width: width
        });
      } else {
        $this.find('.headerpost').css({
          position: 'absolute',
          top: 52,
          left: 0,
          width: width
        });
      }
      // Absolute to bottom of post
      if (Y >= stop) {
        $this.find('.headerpost').css({
          position: 'absolute',
          top: 'auto',
          left: 0,
          bottom: 0,
          width: width
        });
      }
    });
  });
});