
// function to reset the top margin to whatever the current height of the ribbon is

function setTopPadding()
 {
 var myElem = document.getElementById('s4-workspace'), newHeight = document.getElementById('s4-ribbonrow').offsetHeight; myElem.style.paddingTop = newHeight + 'px'; }

   function setTopPos() {
  $('.ms-cui-menu, .ms-cui-tooltip').each(function(){
  var newTop = $(this).data('origTop') || $(this).position().top;
  $(this).data('origTop',newTop);
  newTop += $('#s4-ribbonrow').position().top;
  $(this).css({
  top : newTop 
 });
  });
  } 
  // bind top padding reset to ribbon resize event so that the page always lays out correctly. 
ExecuteOrDelayUntilScriptLoaded(function () { SP.UI.Workspace.add_resized(setTopPadding); }, "init.js"); 
  $(document).ready(function(){ 
 setInterval(setTopPos, 300); 
 });

