﻿// This is written in jQuery.
// This piece of code will toggle the ribbon from a fixed position to a relative position based on the viewable area in the browser


// This is written in jQuery.
// This piece of code will toggle the ribbon from a fixed position to a relative position based on the viewable area in the browser

// When the Window Scrolls
$(window).scroll(function () {
	// The Current Window in an object
	var jWindow = $(window);
	
	// If the Ribbon is turned on...
	
	//If the top of the page is over 145 pixels scrolled then...
	if(jWindow.scrollTop() > 145)
	{
		// Set the height of the ribbon box and toggle it to fixed.
		$("#scrollingDiv").css("height", $("#s4-ribbonrow").height() + "px");
		$("#s4-ribbonrow").addClass("fixed-ribbon");
	}
	//If the top of the page is less than 145 pixels scrolled then...
	else if(jWindow.scrollTop() < 146)
	{
		// Remove the set height and toggle it back to relative
		$("#s4-ribbonrow").removeClass("fixed-ribbon");
		$("#scrollingDiv").removeAttr("style");
	}
});

$(document).ready(function() {
	/*Fix the Edit Web Part Properties panel*/
	$(".ms-ToolPaneBody").css({  height: ($(window).height() - 245) + "px"});
	var $webPartToolPane = $(".ms-ToolPaneOuter");
	$(window).scroll(function(){
		$webPartToolPane.stop().animate({"marginTop": ($(window).scrollTop() + 80) + "px"}, "fast"); });
});
 
/*Fix the ribbon dropdowns*/
function setTopPos() {
	$('.ms-cui-menu').each(function(){
		var origTop = $(this).data('origTop') || $(this).position().top;
		$(this).data('origTop',origTop );
		newTop = $(window).scrollTop() + origTop;
		$(this).css({  top : newTop  });
	});
	$('.ms-siteactionsmenu').each(function(){
		var origTop = $(this).data('origTop') || $(this).position().top;
		$(this).data('origTop',origTop );
		newTop = $(window).scrollTop() + origTop;
		$(this).css({  top : newTop  });
	});

}
setInterval(setTopPos, 300);


