!function(t,e,i,l){"use strict";function s(t){var i=t.charAt(0).toUpperCase()+t.slice(1),s=e.createElement("test"),r=[t,"Webkit"+i];for(var n in r)if(s.style[r[n]]!==l)return r[n];return""}function r(t,e,i){var l=t.className.split(/\s+/),s=l.indexOf(e);i?~s||l.push(e):~s&&l.splice(s,1),t.className=l.join(" ")}function n(t,e,i){for(var s in e)!e.hasOwnProperty(s)||t[s]!==l&&i||(t[s]=e[s]);return t}function o(t,e,i){var l,s;if(t.length)for(l=0,s=t.length;l<s;l++)t[l][e].apply(t[l],i);else for(l in t)t[l][e].apply(t[l],i)}var c=function t(e,i){return new t.Instance(e,i||{})},a=c.globalSettings={scrollMinUpdateInterval:25,checkFrequency:1e3,pauseCheck:!1};c.defaults={preventParentScroll:!1,forceScrollbars:!1,scrollStopDelay:300,maxTrackSize:95,minTrackSize:5,draggableTracks:!0,autoUpdate:!0,classPrefix:"optiscroll-",wrapContent:!0,rtl:!1},(c.Instance=function(e,i){this.element=e,this.settings=n(n({},c.defaults),i||{}),"boolean"!=typeof i.rtl&&(this.settings.rtl="rtl"===t.getComputedStyle(e).direction),this.cache={},this.init()}).prototype={init:function(){var t=this.element,e=this.settings,i=!1,l=this.scrollEl=e.wrapContent?f.createWrapper(t):t.firstElementChild;r(l,e.classPrefix+"content",!0),r(t,"is-enabled"+(e.rtl?" is-rtl":""),!0),this.scrollbars={v:d("v",this),h:d("h",this)},(v.scrollbarSpec.width||e.forceScrollbars)&&(i=f.hideNativeScrollbars(l,e.rtl)),i&&o(this.scrollbars,"create"),v.isTouch&&e.preventParentScroll&&r(t,e.classPrefix+"prevent",!0),this.update(),this.bind(),e.autoUpdate&&v.instances.push(this),e.autoUpdate&&!v.checkTimer&&f.checkLoop()},bind:function(){var t,e,i,l,s=this.listeners={},r=this.scrollEl;for(var n in s.scroll=(t=p.scroll.bind(this),e=a.scrollMinUpdateInterval,function(){var s=this,r=Date.now(),n=arguments;i&&r<i+e?(clearTimeout(l),l=setTimeout(function(){i=r,t.apply(s,n)},e)):(i=r,t.apply(s,n))}),v.isTouch&&(s.touchstart=p.touchstart.bind(this),s.touchend=p.touchend.bind(this)),s.mousewheel=s.wheel=p.wheel.bind(this),s)r.addEventListener(n,s[n],v.passiveEvent)},update:function(){var t=this.scrollEl,i=this.cache,s=i.clientH,r=t.scrollHeight,n=t.clientHeight,c=t.scrollWidth,a=t.clientWidth;if(r!==i.scrollH||n!==i.clientH||c!==i.scrollW||a!==i.clientW){if(i.scrollH=r,i.clientH=n,i.scrollW=c,i.clientW=a,s!==l){if(0===r&&0===n&&!e.body.contains(this.element))return this.destroy(),!1;this.fireCustomEvent("sizechange")}o(this.scrollbars,"update")}},scrollTo:function(t,e,i){var l,s,r,n,o=this.cache;v.pauseCheck=!0,this.update(),l=this.scrollEl.scrollLeft,s=this.scrollEl.scrollTop,r=+t,"left"===t&&(r=0),"right"===t&&(r=o.scrollW-o.clientW),!1===t&&(r=l),n=+e,"top"===e&&(n=0),"bottom"===e&&(n=o.scrollH-o.clientH),!1===e&&(n=s),this.animateScroll(l,r,s,n,+i)},scrollIntoView:function(t,e,i){var l,s,r,n,o,c,a,h,u,p,d,f,m=this.scrollEl;v.pauseCheck=!0,this.update(),"string"==typeof t?t=m.querySelector(t):t.length&&t.jquery&&(t=t[0]),"number"==typeof i&&(i={top:i,right:i,bottom:i,left:i}),i=i||{},l=t.getBoundingClientRect(),s=m.getBoundingClientRect(),u=d=m.scrollLeft,p=f=m.scrollTop,a=u+l.left-s.left,h=p+l.top-s.top,r=a-(i.left||0),n=h-(i.top||0),r<u&&(d=r),u<(o=a+l.width-this.cache.clientW+(i.right||0))&&(d=o),n<p&&(f=n),p<(c=h+l.height-this.cache.clientH+(i.bottom||0))&&(f=c),this.animateScroll(u,d,p,f,+e)},animateScroll:function(e,l,s,r,n){var o=this,c=this.scrollEl,a=Date.now();if(l!==e||r!==s){if(0===n)return c.scrollLeft=l,void(c.scrollTop=r);isNaN(n)&&(n=15*i.pow(i.max(i.abs(l-e),i.abs(r-s)),.54)),function h(){var u=i.min(1,(Date.now()-a)/n),p=f.easingFunction(u);r!==s&&(c.scrollTop=~~(p*(r-s))+s),l!==e&&(c.scrollLeft=~~(p*(l-e))+e),o.scrollAnimation=u<1?t.requestAnimationFrame(h):null}()}},destroy:function(){var e,i=this,l=this.element,s=this.scrollEl,n=this.listeners;if(this.scrollEl){for(var c in n)s.removeEventListener(c,n[c]);if(o(this.scrollbars,"remove"),this.settings.wrapContent){for(;e=s.childNodes[0];)l.insertBefore(e,s);l.removeChild(s),this.scrollEl=null}r(l,this.settings.classPrefix+"prevent",!1),r(l,"is-enabled",!1),t.requestAnimationFrame(function(){var t=v.instances.indexOf(i);-1<t&&v.instances.splice(t,1)})}},fireCustomEvent:function(t){var i,l,s=this.cache,r=s.scrollH,o=s.scrollW;i={scrollbarV:n({},s.v),scrollbarH:n({},s.h),scrollTop:s.v.position*r,scrollLeft:s.h.position*o,scrollBottom:(1-s.v.position-s.v.size)*r,scrollRight:(1-s.h.position-s.h.size)*o,scrollWidth:o,scrollHeight:r,clientWidth:s.clientW,clientHeight:s.clientH},"function"==typeof CustomEvent?l=new CustomEvent(t,{detail:i}):(l=e.createEvent("CustomEvent")).initCustomEvent(t,!1,!1,i),this.element.dispatchEvent(l)}};var h,u,p={scroll:function(t){v.pauseCheck||this.fireCustomEvent("scrollstart"),v.pauseCheck=!0,this.scrollbars.v.update(),this.scrollbars.h.update(),this.fireCustomEvent("scroll"),clearTimeout(this.cache.timerStop),this.cache.timerStop=setTimeout(p.scrollStop.bind(this),this.settings.scrollStopDelay)},touchstart:function(t){v.pauseCheck=!1,this.scrollbars.v.update(),this.scrollbars.h.update(),p.wheel.call(this,t)},touchend:function(t){clearTimeout(this.cache.timerStop)},scrollStop:function(){this.fireCustomEvent("scrollstop"),v.pauseCheck=!1},wheel:function(e){var i=this.cache,l=i.v,s=i.h,r=this.settings.preventParentScroll&&v.isTouch;t.cancelAnimationFrame(this.scrollAnimation),r&&l.enabled&&l.percent%100==0&&(this.scrollEl.scrollTop=l.percent?i.scrollH-i.clientH-1:1),r&&s.enabled&&s.percent%100==0&&(this.scrollEl.scrollLeft=s.percent?i.scrollW-i.clientW-1:1)}},d=function(l,s){var o="v"===l,c=s.element,a=s.scrollEl,h=s.settings,u=s.cache,p=u[l]={},d=o?"H":"W",f="client"+d,m="scroll"+d,g=o?"scrollTop":"scrollLeft",b=o?["top","bottom"]:["left","right"],E=/^(mouse|touch|pointer)/,y=v.scrollbarSpec.rtl,C=!1,w=null,T=null,S={dragData:null,dragStart:function(t){t.preventDefault();var e=t.touches?t.touches[0]:t;S.dragData={x:e.pageX,y:e.pageY,scroll:a[g]},S.bind(!0,t.type.match(E)[1])},dragMove:function(t){var e,i=t.touches?t.touches[0]:t,l=h.rtl&&1===y&&!o?-1:1;t.preventDefault(),e=(o?i.pageY-S.dragData.y:i.pageX-S.dragData.x)/u[f],a[g]=S.dragData.scroll+e*u[m]*l},dragEnd:function(t){S.dragData=null,S.bind(!1,t.type.match(E)[1])},bind:function(t,i){var l=(t?"add":"remove")+"EventListener",s=i+"move",r=i+("touch"===i?"end":"up");e[l](s,S.dragMove),e[l](r,S.dragEnd),e[l](i+"cancel",S.dragEnd)}};return{toggle:function(t){C=t,T&&r(c,"has-"+l+"track",C),p.enabled=C},create:function(){w=e.createElement("div"),T=e.createElement("b"),w.className=h.classPrefix+l,T.className=h.classPrefix+l+"track",w.appendChild(T),c.appendChild(w),h.draggableTracks&&(t.PointerEvent?["pointerdown"]:["touchstart","mousedown"]).forEach(function(t){T.addEventListener(t,S.dragStart)})},update:function(){var t,e,l,s,r;(C||u[f]!==u[m])&&(t=(l=this.calc()).size,e=p.size,s=1/t*l.position*100,r=i.abs(l.position-(p.position||0))*u[f],1===t&&C&&this.toggle(!1),t<1&&!C&&this.toggle(!0),T&&C&&this.style(s,r,t,e),p=n(p,l),C&&this.fireEdgeEv())},style:function(t,e,i,l){i!==l&&(T.style[o?"height":"width"]=100*i+"%",h.rtl&&!o&&(T.style.marginRight=100*(1-i)+"%")),T.style[v.cssTransform]="translate("+(o?"0%,"+t+"%":t+"%,0%")+")"},calc:function(){var t,e=a[g],l=u[f],s=u[m],r=l/s,n=s-l;return 1<=r||!s?{position:0,size:1,percent:0}:(!o&&h.rtl&&y&&(e=n-e*y),t=100*e/n,e<=1&&(t=0),n-1<=e&&(t=100),r=i.max(r,h.minTrackSize/100),{position:t/100*(1-(r=i.min(r,h.maxTrackSize/100))),size:r,percent:t})},fireEdgeEv:function(){var t=p.percent;p.was!==t&&t%100==0&&(s.fireCustomEvent("scrollreachedge"),s.fireCustomEvent("scrollreach"+b[t/100])),p.was=t},remove:function(){this.toggle(!1),w&&(w.parentNode.removeChild(w),w=null)}}},f={hideNativeScrollbars:function(t,e){var i=v.scrollbarSpec.width,l=t.style;if(0===i){var s=Date.now();return t.setAttribute("data-scroll",s),f.addCssRule('[data-scroll="'+s+'"]::-webkit-scrollbar',"display:none;width:0;height:0;")}return l[e?"left":"right"]=-i+"px",l.bottom=-i+"px",!0},addCssRule:function(t,i){var l=e.getElementById("scroll-sheet");l||((l=e.createElement("style")).id="scroll-sheet",l.appendChild(e.createTextNode("")),e.head.appendChild(l));try{return l.sheet.insertRule(t+" {"+i+"}",0),!0}catch(t){return}},createWrapper:function(t,i){for(var l,s=e.createElement("div");l=t.childNodes[0];)s.appendChild(l);return t.appendChild(s)},checkLoop:function(){v.instances.length?(v.pauseCheck||o(v.instances,"update"),a.checkFrequency&&(v.checkTimer=setTimeout(function(){f.checkLoop()},a.checkFrequency))):v.checkTimer=null},easingFunction:function(t){return--t*t*t+1}},v=c.G={isTouch:"ontouchstart"in t,cssTransition:s("transition"),cssTransform:s("transform"),scrollbarSpec:function(){var t,i,s,l=e.documentElement,r=1;return(t=e.createElement("div")).style.cssText="overflow:scroll;width:50px;height:50px;position:absolute;left:-100px;direction:rtl",(i=e.createElement("div")).style.cssText="width:100px;height:100px",t.appendChild(i),l.appendChild(t),s=t.offsetWidth-t.clientWidth,0<t.scrollLeft?r=0:(t.scrollLeft=1,0===t.scrollLeft&&(r=-1)),l.removeChild(t),{width:s,rtl:r}}(),passiveEvent:(h=!1,u=Object.defineProperty({},"passive",{get:function(){h=!0}}),t.addEventListener("test",null,u),!!h&&{capture:!1,passive:!0}),instances:[],checkTimer:null,pauseCheck:!1};"function"==typeof defineOptiScroll&&defineOptiScroll.amd&&defineOptiScroll(function(){return c}),"undefined"!=typeof module&&module.exports&&(module.exports=c),t.Optiscroll=c}(window,document,Math),function(t){var e="optiscroll";t.fn[e]=function(i){var l,s;return"string"==typeof i&&(s=Array.prototype.slice.call(arguments),l=s.shift()),this.each(function(){var r=t(this),n=r.data(e);n?n&&"string"==typeof l&&(n[l].apply(n,s),"destroy"===l&&r.removeData(e)):(n=new window.Optiscroll(this,i||{}),r.data(e,n))})}}(jQuery||Zepto);