!function(e){e.fn.theiaStickySidebar=function(t){var n={containerSelector:"",additionalMarginTop:0,additionalMarginBottom:0,updateSidebarHeight:!0,minWidth:0,sidebarBehavior:"modern"};t=e.extend(n,t),t.additionalMarginTop=parseInt(t.additionalMarginTop)||0,t.additionalMarginBottom=parseInt(t.additionalMarginBottom)||0,e("head").append(e('<style>.theiaStickySidebar:after {content: ""; display: table; clear: both;}</style>')),this.each(function(){function s(){n.fixedScrollTop=0,n.sidebar.css({"min-height":"1px"}),n.stickySidebar.css({position:"static",width:""})}function a(t){var n=t.height();return t.children().each(function(){n=Math.max(n,e(this).height())}),n}n={},n.sidebar=e(this),n.options=t||{},n.container=e(n.options.containerSelector),0==n.container.size()&&(n.container=n.sidebar.parent()),n.sidebar.parents().css("-webkit-transform","none"),n.sidebar.css({position:"relative",overflow:"visible","-webkit-box-sizing":"border-box","-moz-box-sizing":"border-box","box-sizing":"border-box"}),n.stickySidebar=n.sidebar.find(".theiaStickySidebar"),0==n.stickySidebar.length&&(n.sidebar.find("script").remove(),n.stickySidebar=e("<div>").addClass("theiaStickySidebar").append(n.sidebar.children()),n.sidebar.append(n.stickySidebar)),n.marginTop=parseInt(n.sidebar.css("margin-top")),n.marginBottom=parseInt(n.sidebar.css("margin-bottom")),n.paddingTop=parseInt(n.sidebar.css("padding-top")),n.paddingBottom=parseInt(n.sidebar.css("padding-bottom"));var n,o=n.stickySidebar.offset().top,i=n.stickySidebar.outerHeight();n.stickySidebar.css("padding-top",1),n.stickySidebar.css("padding-bottom",1),o-=n.stickySidebar.offset().top,i=n.stickySidebar.outerHeight()-i-o,0==o?(n.stickySidebar.css("padding-top",0),n.stickySidebarPaddingTop=0):n.stickySidebarPaddingTop=1,0==i?(n.stickySidebar.css("padding-bottom",0),n.stickySidebarPaddingBottom=0):n.stickySidebarPaddingBottom=1,n.previousScrollTop=null,n.fixedScrollTop=0,s(),n.onScroll=function(n){if(n.stickySidebar.is(":visible")){if(e("body").width()<n.options.minWidth)return void s();if(n.sidebar.outerWidth(!0)+50>n.container.width())return void s();if(i=e(document).scrollTop(),r="static",i>=n.container.offset().top+(n.paddingTop+n.marginTop-n.options.additionalMarginTop)){var i,r,c,d,j=n.paddingTop+n.marginTop+t.additionalMarginTop,b=n.paddingBottom+n.marginBottom+t.additionalMarginBottom,v=n.container.offset().top,m=n.container.offset().top+a(n.container),u=0+t.additionalMarginTop,g=n.stickySidebar.outerHeight()+j+b<e(window).height(),l=g?u+n.stickySidebar.outerHeight():e(window).height()-n.marginBottom-n.paddingBottom-t.additionalMarginBottom,f=v-i+n.paddingTop+n.marginTop,p=m-i-n.paddingBottom-n.marginBottom,o=n.stickySidebar.offset().top-i,h=n.previousScrollTop-i;"fixed"==n.stickySidebar.css("position")&&"modern"==n.options.sidebarBehavior&&(o+=h),"legacy"==n.options.sidebarBehavior&&(o=l-n.stickySidebar.outerHeight(),o=Math.max(o,l-n.stickySidebar.outerHeight())),o=h>0?Math.min(o,u):Math.max(o,l-n.stickySidebar.outerHeight()),o=Math.max(o,f),o=Math.min(o,p-n.stickySidebar.outerHeight()),d=n.container.height()==n.stickySidebar.outerHeight(),r=(d||o!=u)&&(d||o!=l-n.stickySidebar.outerHeight())?i+o-n.sidebar.offset().top-n.paddingTop<=t.additionalMarginTop?"static":"absolute":"fixed"}"fixed"==r?n.stickySidebar.css({position:"fixed",width:n.sidebar.width(),top:o,left:n.sidebar.offset().left+parseInt(n.sidebar.css("padding-left"))}):"absolute"==r?(c={},"absolute"!=n.stickySidebar.css("position")&&(c.position="absolute",c.top=i+o-n.sidebar.offset().top-n.stickySidebarPaddingTop-n.stickySidebarPaddingBottom),c.width=n.sidebar.width(),c.left="",n.stickySidebar.css(c)):"static"==r&&s(),"static"!=r&&1==n.options.updateSidebarHeight&&n.sidebar.css({"min-height":n.stickySidebar.outerHeight()+n.stickySidebar.offset().top-n.sidebar.offset().top+n.paddingBottom}),n.previousScrollTop=i}},n.onScroll(n),e(document).scroll(function(e){return function(){e.onScroll(e)}}(n)),e(window).resize(function(e){return function(){e.stickySidebar.css({position:"static"}),e.onScroll(e)}}(n))})}}(jQuery)