(function(u){function z(b,a,c){var d=0==c,e=b.$n(a);b=b.$n(a+"-embed");e&&(e=e.style,e.display=d?"none":"block",e.opacity=c);b&&(e=b.style,e.display=d?"block":"none")}function v(b,a,c){if(a>c)return b;b<a&&(b=a);b>c&&(b=c);return b}zul.Scrollbar=u.$extends(u.Object,{_pos:null,_barPos:null,_pressTimer:null,_frozenScroll:0,_frozenLimit:!1,$n:function(b){return jq(this.uid+"-"+b,u)[0]},$init:function(b,a,c){if(!b||!a)throw"Both wrapper and scroller dom element are required to generate scrollbar";this.cave=
b;var d=b.style;d.position="relative";d.overflow="hidden";this.scroller=a;this.opts=u.$default(c,{embed:!1,step:20,wheelAmountStep:3,startPositionX:0,startPositionY:0});this.widget=u.Widget.$(b);this.uid=this.widget.uuid;this._pos=[0,0];this._barPos=[0,0];this.currentPos={x:this._pos[0],y:this._pos[1]};jq(b).on("scroll",this.proxy(this._fixScroll)).on("mouseenter",this.proxy(this._mouseEnter)).on("mouseleave",this.proxy(this._mouseLeave))},destroy:function(){jq(this.cave).off("scroll",this.proxy(this._fixScroll)).off("mouseenter",
this.proxy(this._mouseEnter)).off("mouseleave",this.proxy(this._mouseLeave));this._unbindMouseEvent("hor");this._unbindMouseEvent("ver");var b=this.$n("hor"),a=this.$n("ver");b&&jq(b).remove();a&&jq(a).remove();this.opts.embed&&(b=this.$n("hor-embed"),a=this.$n("ver-embed"),b&&jq(b).remove(),a&&jq(a).remove());this._pos=this._barPos=this.currentPos=null},hasVScroll:function(){return this.needV},hasHScroll:function(){return this.needH},syncSize:function(b){this._checkBarRequired();var a=this.widget,
c=a.frozen,d=0,e=a.$n("tpad"),f=a.$n("bpad"),g=this.cave,m=this.scroller,n=this.$n("hor");a=this.$n("ver");var w=this.needH,h=this.needV,p=this.opts,t=m.scrollHeight;e&&f&&(t+=e.offsetHeight+f.offsetHeight);c&&(d=50*(c._scrollScale||0));if(w){c=n.style.display;n.style.display="block";e=this.$n("hor-embed");var x=this.$n("hor-left"),A=this.$n("hor-right");f=this.$n("hor-wrapper");var r=f.style,k=p.startPositionX,q=g.offsetWidth-k;m=m.scrollWidth-k+d;var y=x.offsetWidth,B=A.offsetWidth,l=q-y-B;m<q&&
(m=q+d);k&&(x.style.left=jq.px(k),r.left=jq.px(k+y),e&&(e.style.left=jq.px(k)));h?(r.width=jq.px(l-B),A.style.right=jq.px(B),r=a.style.display,a.style.display="block",m+=jq(a).outerWidth(!0),a.style.display=r):r.width=jq.px(l);r=this.$n("hor-indicator");f=f.offsetWidth;d=Math.round(f*q/m);d=15<d?d:15;r.style.width=d+"px";e&&(e.style.width=d+y+B+"px");this.hLimit=m-q;e=f-d;0>=e?(this.hBarLimit=0,r.style.display="none"):this.hBarLimit=e;this.hRatio=Math.abs(this.hLimit/this.hBarLimit);n.style.display=
c}h&&(c=a.style.display,a.style.display="block",e=this.$n("ver-embed"),h=this.$n("ver-up"),q=this.$n("ver-down"),f=this.$n("ver-wrapper"),r=f.style,m=p.startPositionY,p=g.offsetHeight-m,t-=m,h=h.offsetHeight,d=q.offsetHeight,y=p-h-d,m&&(a.style.top=jq.px(g.offsetTop+m),q.style.bottom=jq.px(m),e&&(e.style.top=a.style.top)),w?(r.height=jq.px0(y-d),q.style.bottom=jq.px(m+d),g=n.style.display,n.style.display="block",t+=jq(n).outerHeight(!0),n.style.display=g):r.height=jq.px(y),r=this.$n("ver-indicator"),
n=f.offsetHeight,g=Math.round(n*p/t),g=15<g?g:15,r.style.height=g+"px",e&&(e.style.height=g+h+d+"px"),this.vLimit=t-p,e=n-g,0>=e?(this.vBarLimit=0,r.style.display="none"):this.vBarLimit=e,this.vRatio=Math.abs(this.vLimit/this.vBarLimit),a.style.display=c);this.scrollTo(this._pos[0],this._pos[1]);b&&(z(this,"hor",1),z(this,"ver",1))},scrollTo:function(b,a){if(this.needH){b=v(b,0,this.hLimit);var c=b/this.hRatio;this._syncPosition("hor",b);this._syncBarPosition("hor",c);this._syncEmbedBarPosition("hor",
b+c)}this.needV&&(a=v(a,0,this.vLimit),c=a/this.vRatio,this._syncPosition("ver",a),this._syncBarPosition("ver",c),this._syncEmbedBarPosition("ver",a+c));this._onScrollEnd()},scrollToElement:function(b){var a=this.cave,c=jq(b).offset().top,d=c+b.offsetHeight,e=jq(b).offset().left,f=e+b.offsetWidth,g=jq(a).offset().top,m=g+a.offsetHeight,n=jq(a).offset().left,w=n+a.offsetWidth,h=!0;a=b.offsetWidth==a.offsetWidth;(f>=n&&f<=w||e>=n&&e<=w||e<=n&&f>=w)&&(c>=g&&c<=m||d>=g&&d<=m||c<=g&&d>=m)||(c<g&&(h=!1),
e<n&&(a=!1),c=h?d-m:g-c,h=this._pos[1]+(h?c:-c),e=a?f-w:n-e,e=this._pos[0]+(a?e:-e),this.needV&&(h=v(h,0,this.vLimit),f=h/this.vRatio,this._syncPosition("ver",h),this._syncBarPosition("ver",f),this._syncEmbedBarPosition("ver",h+f)),this.needH&&(e=v(e,0,this.hLimit),f=e/this.hRatio,this._syncPosition("hor",e),this._syncBarPosition("hor",f),this._syncEmbedBarPosition("hor",e+f)),this._onScrollEnd(),u(b).scrollIntoView())},isScrollIntoView:function(b){var a=this.cave,c=jq(b).offset().top,d=c+b.offsetHeight,
e=jq(b).offset().left;b=e+b.offsetWidth;var f=jq(a).offset().top,g=f+a.offsetHeight,m=jq(a).offset().left;a=m+a.offsetWidth;return this.needV&&d<=g&&c>=f||this.needH&&b<=a&&e>=m?!0:!1},getCurrentPosition:function(){return this.currentPos},setBarPosition:function(b){var a=this.widget.frozen;a&&this.needH&&(b*=this.hBarLimit/a._scrollScale,this._syncBarPosition("hor",b),this._syncEmbedBarPosition("hor",b))},_checkBarRequired:function(){var b=this.cave,a=this.scroller;this.needH=this.widget.frozen?!0:
b.offsetWidth<a.scrollWidth;var c=this.$n("hor");this.needH?this.$n("hor")||(this.redraw(b,"hor"),this._bindMouseEvent("hor")):c&&(this._unbindMouseEvent("hor"),this._syncPosition("hor",0),jq(c).remove(),this.opts.embed&&(c=this.$n("hor-embed"))&&jq(c).remove());this.needV=b.offsetHeight<a.offsetHeight;a=this.$n("ver");this.needV?a||(this.redraw(b,"ver"),this._bindMouseEvent("ver")):a&&(this._unbindMouseEvent("ver"),this._syncPosition("ver",0),jq(a).remove(),this.opts.embed&&(b=this.$n("ver-embed"))&&
jq(b).remove())},_bindMouseEvent:function(b){var a=this.cave,c="hor"==b,d=this.$n(b),e=this.$n(b+"-indicator"),f=this.$n(b+"-rail"),g=this.$n(b+(c?"-left":"-up"));b=this.$n(b+(c?"-right":"-down"));!c||11>u.ie&&u.opera?jq(a).mousewheel(this.proxy(this._mousewheelY)):jq(a).mousewheel(this.proxy(this._mousewheelX));jq(d).click(u.$void);jq(e).on("mousedown",this.proxy(this._dragStart));jq(f).on("mousedown",this.proxy(this._mouseDown)).on("mouseup",this.proxy(this._mouseUp));jq(g).on("mousedown",this.proxy(this._mouseDown)).on("mouseup",
this.proxy(this._mouseUp));jq(b).on("mousedown",this.proxy(this._mouseDown)).on("mouseup",this.proxy(this._mouseUp))},_unbindMouseEvent:function(b){var a=this.cave,c="hor"==b,d=this.$n(b),e=this.$n(b+"-indicator"),f=this.$n(b+"-rail"),g=this.$n(b+(c?"-left":"-up"));b=this.$n(b+(c?"-right":"-down"));!c||11>u.ie&&u.opera?jq(a).unmousewheel(this.proxy(this._mousewheelY)):jq(a).unmousewheel(this.proxy(this._mousewheelX));jq(d).off("click",u.$void);jq(e).off("mousedown",this.proxy(this._dragStart));jq(f).off("mousedown",
this.proxy(this._mouseDown)).off("mouseup",this.proxy(this._mouseUp));jq(g).off("mousedown",this.proxy(this._mouseDown)).off("mouseup",this.proxy(this._mouseUp));jq(b).off("mousedown",this.proxy(this._mouseDown)).off("mouseup",this.proxy(this._mouseUp))},_fixScroll:function(b){b=this.cave;this.dragging||this.scrollTo(b.scrollLeft,b.scrollTop)},_mouseEnter:function(b){z(this,"hor",1);z(this,"ver",1)},_mouseLeave:function(b){this.dragging||(z(this,"hor",0),z(this,"ver",0))},_dragStart:function(b){this._pressTimer&&
(clearInterval(this._pressTimer),this._pressTimer=null);b.preventDefault();var a=this.$n("hor-indicator")==b.currentTarget?"hor":"ver",c="hor"==a;b={orient:a,point:c?b.pageX:b.pageY,pos:c?this._barPos[0]:this._barPos[1]};jq(document).on("mousemove",b,this.proxy(this._dragMove)).on("mouseup",this.proxy(this._dragEnd))},_dragEnd:function(b){var a=b.pageX;b=b.pageY;var c=this.cave,d=jq(c).offset().left,e=jq(c).offset().top;jq(document).off("mousemove",this.proxy(this._dragMove)).off("mouseup",this.proxy(this._dragEnd));
this.dragging=!1;if(a<d||a>d+c.offsetWidth||b<e||b>e+c.offsetHeight)z(this,"hor",0),z(this,"ver",0)},_dragMove:function(b){var a=b.data,c=a.orient,d=a.pos,e="hor"==c,f=(e?b.pageX:b.pageY)-a.point;b=e?this.hBarLimit:this.vBarLimit;a=e?this.hRatio:this.vRatio;var g=this.widget.frozen;this.dragging=!0;f=v(d+f,0,b);this._syncBarPosition(c,f);g&&e?(g._doScroll(f/(b/g._scrollScale)),this._syncEmbedBarPosition("hor",f)):(d=f*a,this._syncPosition(c,d),this._syncEmbedBarPosition(c,d+f),this._onScrollEnd())},
_mousewheelX:function(b,a,c,d){a=this.opts;a=a.step*a.wheelAmountStep;d=this._pos[0];c&&(b.stop(),d=v(d+(0<c?-a:a)+a,0,this.hLimit),b=this.widget.frozen,c=d/this.hRatio,b?(a=this.hBarLimit/b._scrollScale,c/=a,b._doScroll(c),this._syncEmbedBarPosition("hor",c)):(this._syncPosition("hor",d),this._syncEmbedBarPosition("hor",d+c)),this._syncBarPosition("hor",c),this._onScrollEnd())},_mousewheelY:function(b,a,c,d){a=this.opts;c=a.step*a.wheelAmountStep;a=this._pos[1];d&&(d=0<d,d&&0==a||!d&&a==this.vLimit||
(b.stop(),a=v(a+(d?-c:c),0,this.vLimit),b=a/this.vRatio,this._syncPosition("ver",a),this._syncBarPosition("ver",b),this._syncEmbedBarPosition("ver",a+b),this._onScrollEnd()))},_mouseUp:function(b){clearInterval(this._pressTimer);this._pressTimer=null},_mouseDown:function(b){this._pressTimer&&(clearInterval(this._pressTimer),this._pressTimer=null);var a=b.currentTarget,c=this.$n("hor-rail"),d=this.$n("ver-rail"),e=this.$n("ver-up"),f=this.$n("ver-down"),g=this.$n("hor-left"),m=this.$n("hor-right"),
n=this.widget.frozen,w=this.hBarLimit,h=n?w/n._scrollScale:this.opts.step;if(a==c||a==d){var p=a==c,t=p?"hor":"ver";c=jq(a).offset();c=p?c.left:c.top;d=this.$n(t+"-indicator");var x=(p?b.pageX:b.pageY)-c-(p?d.offsetWidth:d.offsetHeight)/2,A=p?this.hLimit:this.vLimit,r=p?this.hRatio:this.vRatio,k=p?this._pos[0]:this._pos[1],q=p?this._barPos[0]:this._barPos[1],y=x*r,B=10*h;l=this;n?(x=v(x,0,w),l._syncBarPosition("hor",x),l._syncEmbedBarPosition("hor",x),n._doScroll(x/h)):l._pressTimer=setInterval(function(){var C=
x>q;var D=C?k:y;D=0>D?0:D;var E=C?y:k;E=E>A?A:E;k+=C?B:-B;k=v(k,D,E);C=k/r;if(k==y||k<=D||k>=E)clearInterval(l._pressTimer),l._pressTimer=null;l._syncPosition(t,k);l._syncBarPosition(t,C);l._syncEmbedBarPosition(t,k+C);l._onScrollEnd()},50)}if(a==g||a==m||a==e||a==f){var l=this;t=(p=a==g||a==m)?"hor":"ver";A=p?l.hLimit:l.vLimit;r=p?l.hRatio:l.vRatio;k=p?l._pos[0]:l._pos[1];q=l._barPos[0];l._pressTimer=setInterval(function(){n&&p?(q+=a==g?-h:h,q=v(q,0,w),l._syncBarPosition(t,q),l._syncEmbedBarPosition(t,
q),n._doScroll(q/h)):(k=p?k+(a==g?-h:h):k+(a==e?-h:h),k=v(k,0,A),q=k/r,l._syncPosition(t,k),l._syncBarPosition(t,q),l._syncEmbedBarPosition(t,k+q),l._onScrollEnd())},50)}},_syncPosition:function(b,a){if(this._pos){var c="hor"==b,d=this.cave;b=this.$n(b);var e=this.opts.embed;b&&(a=Math.round(a),this._pos[c?0:1]=a,b.style[c?"left":"top"]=a+"px",c&&this.needV&&(this.$n("ver").style.right=-a+"px",e&&(this.$n("ver-embed").style.right=-a+"px")),!c&&this.needH&&(this.$n("hor").style.bottom=-a+"px",e&&(this.$n("hor-embed").style.bottom=
-a+"px")),d[c?"scrollLeft":"scrollTop"]=a,a=this.opts.onSyncPosition)&&(this.currentPos={x:this._pos[0],y:this._pos[1]},a.call(this))}},_syncBarPosition:function(b,a){var c="hor"==b;b=this.$n(b+"-indicator");this._barPos[c?0:1]=a;b.style[c?"left":"top"]=a+"px"},_syncEmbedBarPosition:function(b,a){if(this.opts.embed){var c="hor"==b;b=this.$n(b+"-embed");var d=this.opts;b.style[c?"left":"top"]=a+(c?d.startPositionX:d.startPositionY)+"px"}},_onScrollEnd:function(){var b=this.opts.onScrollEnd;b&&(this.currentPos=
{x:this._pos[0],y:this._pos[1]},b.call(this))},redraw:function(b,a){var c="hor"==a;a=this.uid+"-"+a;var d=c?"horizontal":"vertical",e=c?"left":"up";c=c?"right":"down";var f="";this.opts.embed&&(f+='<div id="'+a+'-embed" class="z-scrollbar-'+d+'-embed"></div>');f+='<div id="'+a+'" class="z-scrollbar z-scrollbar-'+d+'"><div id="'+a+"-"+e+'" class="z-scrollbar-'+e+'"><i class="z-icon-caret-'+e+'"></i></div><div id="'+a+'-wrapper" class="z-scrollbar-wrapper"><div id="'+a+'-indicator" class="z-scrollbar-indicator"><i class="z-scrollbar-icon z-icon-reorder"></i></div><div id="'+
a+'-rail" class="z-scrollbar-rail"></div></div><div id="'+a+"-"+c+'" class="z-scrollbar-'+c+'"><i class="z-icon-caret-'+c+'"></i></div></div>';jq(b).append(f)}})})(zk);
