jQuery(window).scroll(function(e){
  var $socialbar      = jQuery('.hd-row4');
  var $search         = jQuery('.searchbox');
  var $container      = jQuery('.socialcontainer');
  var isPositionFixed = ($socialbar.css('position') == 'fixed' || $search.css('position') == 'fixed');

  if (jQuery(this).scrollTop() > 305 && jQuery('#wpadminbar').length > 0){
    $socialbar.css({'position': 'fixed', 'top': '97px'});
    $search.css({'position': 'fixed', 'top': '97px', 'margin-top': '5px', 'background-color': '#1a1a1a', 'box-shadow': 'inset 0px 0px 2px #000000, inset 0px 0px 2px #000000, 0px 0px 3px #ffffff50'});
  }

  if (jQuery(this).scrollTop() > 305 && !isPositionFixed){
    $socialbar.css({'position': 'fixed', 'top': '65px'});
    $search.css({'position': 'fixed', 'top': '65px', 'margin-top': '5px', 'background-color': '#1a1a1a', 'box-shadow': 'inset 0px 0px 2px #000000, inset 0px 0px 2px #000000, 0px 0px 3px #ffffff50'});
    $container.css({'justify-content': 'flex-start'});
  }

  if (jQuery(this).scrollTop() < 305 && isPositionFixed){
    $socialbar.css({'position': 'relative', 'top': '0px'});
    $search.css({'position': 'relative', 'top': '0px', 'margin-top': '20px', 'background-color': '#1a1a1a00', 'box-shadow': 'inset 0px 0px 0px #000000'});
    $container.css({'justify-content': 'center'});
  }
});