(function(gZ){gZ.fn.theiaStickySidebar=function(fO){var bL={containerSelector:"",additionalMarginTop:0,additionalMarginBottom:0,updateSidebarHeight:true,minWidth:0,disableOnResponsiveLayouts:true,sidebarBehavior:"modern"};fO=gZ.extend(bL,fO);fO.additionalMarginTop=parseInt(fO.additionalMarginTop)||0;fO.additionalMarginBottom=parseInt(fO.additionalMarginBottom)||0;aK(fO,this);function aK(fO,bL){var aK=dN(fO,bL);if(!aK){console.log("TST: Body width smaller than options.minWidth. Init is delayed.");gZ(document).scroll(function(fO,bL){return function(aK){var cg=dN(fO,bL);if(cg){gZ(this).unbind(aK)}}}(fO,bL));gZ(window).resize(function(fO,bL){return function(aK){var cg=dN(fO,bL);if(cg){gZ(this).unbind(aK)}}}(fO,bL))}}function dN(fO,bL){if(fO.initialized===true){return true}if(gZ("body").width()<fO.minWidth){return false}cg(fO,bL);return true}function cg(fO,bL){fO.initialized=true;gZ("head").append(gZ('<style>.theiaStickySidebar:after {content: ""; display: table; clear: both;}</style>'));bL.each(function(){var bL={};bL.sidebar=gZ(this);bL.options=fO||{};bL.container=gZ(bL.options.containerSelector);if(bL.container.length==0){bL.container=bL.sidebar.parent()}bL.sidebar.parents().css("-webkit-transform","none");bL.sidebar.css({position:"relative",overflow:"visible","-webkit-box-sizing":"border-box","-moz-box-sizing":"border-box","box-sizing":"border-box"});bL.stickySidebar=bL.sidebar.find(".theiaStickySidebar");if(bL.stickySidebar.length==0){var aK=/(?:text|application)\/(?:x-)?(?:javascript|ecmascript)/i;bL.sidebar.find("script").filter(function(gZ,fO){return fO.type.length===0||fO.type.match(aK)}).remove();bL.stickySidebar=gZ("<div>").addClass("theiaStickySidebar").append(bL.sidebar.children());bL.sidebar.append(bL.stickySidebar)}bL.marginTop=parseInt(bL.sidebar.css("margin-top"));bL.marginBottom=parseInt(bL.sidebar.css("margin-bottom"));bL.paddingTop=parseInt(bL.sidebar.css("padding-top"));bL.paddingBottom=parseInt(bL.sidebar.css("padding-bottom"));var dN=bL.stickySidebar.offset().top;var cg=bL.stickySidebar.outerHeight();bL.stickySidebar.css("padding-top",0);bL.stickySidebar.css("padding-bottom",0);dN-=bL.stickySidebar.offset().top;cg=bL.stickySidebar.outerHeight()-cg-dN;if(dN==0){bL.stickySidebar.css("padding-top",0);bL.stickySidebarPaddingTop=0}else{bL.stickySidebarPaddingTop=0}if(cg==0){bL.stickySidebar.css("padding-bottom",0);bL.stickySidebarPaddingBottom=0}else{bL.stickySidebarPaddingBottom=0}bL.previousScrollTop=null;bL.fixedScrollTop=0;ae();bL.onScroll=function(bL){if(!bL.stickySidebar.is(":visible")){return}if(gZ("body").width()<bL.options.minWidth){ae();return}if(bL.options.disableOnResponsiveLayouts){var aK=bL.sidebar.outerWidth(bL.sidebar.css("float")=="none");if(aK+50>bL.container.width()){ae();return}}var dN=gZ(document).scrollTop();var cg="static";if(dN>=bL.container.offset().top+(bL.paddingTop+bL.marginTop-bL.options.additionalMarginTop)){var fG=bL.paddingTop+bL.marginTop+fO.additionalMarginTop;var dM=bL.paddingBottom+bL.marginBottom+fO.additionalMarginBottom;var eV=bL.container.offset().top;var dF=bL.container.offset().top+gC(bL.container);var bU=0+fO.additionalMarginTop;var be;var aA=bL.stickySidebar.outerHeight()+fG+dM<gZ(window).height();if(aA){be=bU+bL.stickySidebar.outerHeight()}else{be=gZ(window).height()-bL.marginBottom-bL.paddingBottom-fO.additionalMarginBottom}var eL=eV-dN+bL.paddingTop+bL.marginTop;var eM=dF-dN-bL.paddingBottom-bL.marginBottom;var aI=bL.stickySidebar.offset().top-dN;var gD=bL.previousScrollTop-dN;if(bL.stickySidebar.css("position")=="fixed"){if(bL.options.sidebarBehavior=="modern"){aI+=gD}}if(bL.options.sidebarBehavior=="stick-to-top"){aI=fO.additionalMarginTop}if(bL.options.sidebarBehavior=="stick-to-bottom"){aI=be-bL.stickySidebar.outerHeight()}if(gD>0){aI=Math.min(aI,bU)}else{aI=Math.max(aI,be-bL.stickySidebar.outerHeight())}aI=Math.max(aI,eL);aI=Math.min(aI,eM-bL.stickySidebar.outerHeight());var dX=bL.container.height()==bL.stickySidebar.outerHeight();if(!dX&&aI==bU){cg="fixed"}else if(!dX&&aI==be-bL.stickySidebar.outerHeight()){cg="fixed"}else if(dN+aI-bL.sidebar.offset().top-bL.paddingTop<=fO.additionalMarginTop){cg="static"}else{cg="absolute"}}if(cg=="fixed"){bL.stickySidebar.css({position:"fixed",width:bL.sidebar.width(),top:aI,left:bL.sidebar.offset().left+parseInt(bL.sidebar.css("padding-left"))})}else if(cg=="absolute"){var dH={};if(bL.stickySidebar.css("position")!="absolute"){dH.position="absolute";dH.top=dN+aI-bL.sidebar.offset().top-bL.stickySidebarPaddingTop-bL.stickySidebarPaddingBottom}dH.width=bL.sidebar.width();dH.left="";bL.stickySidebar.css(dH)}else if(cg=="static"){ae()}if(cg!="static"){if(bL.options.updateSidebarHeight==true){bL.sidebar.css({"min-height":bL.stickySidebar.outerHeight()+bL.stickySidebar.offset().top-bL.sidebar.offset().top+bL.paddingBottom})}}bL.previousScrollTop=dN};bL.onScroll(bL);gZ(document).scroll(function(gZ){return function(){gZ.onScroll(gZ)}}(bL));gZ(window).resize(function(gZ){return function(){gZ.stickySidebar.css({position:"static"});gZ.onScroll(gZ)}}(bL));function ae(){bL.fixedScrollTop=0;bL.sidebar.css({"min-height":"0px"});bL.stickySidebar.css({position:"static",width:""})}function gC(fO){var bL=fO.height();fO.children().each(function(){bL=Math.max(bL,gZ(this).height())});return bL}})}}})(jQuery);$(document).ready(function(){$("#wrap #sidebar-right").theiaStickySidebar({additionalMarginTop:80,additionalMarginBottom:10})});