﻿//This JavaScript fixes the way SharePoint handles the floating ribbon and scrollbar
// Without this, hiding the ribbon for anonymous users will prevent the ability to scroll
// For reference:
//   http://www.greggalipeau.com/2011/01/28/a-better-enhanced-sharepoint-2010-floating-ribbon/

//set top padding of the workspace to the height of the ribbon
function setTopPadding() {
   var wrkElem = document.getElementById('s4-workspace');
   var ribHeight = document.getElementById('s4-ribbonrow').offsetHeight;
   if (window.location.search.match("[?&]IsDlg=1")) {
      //margin works better for dialogs b/c of scrollbars
      wrkElem.style.marginTop = ribHeight + 'px';
      wrkElem.style.paddingTop = '0px';
   }
   else {
     //padding works better for the main window
     wrkElem.style.paddingTop = ribHeight + 'px';
   }
}

// 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");
