(function(m){function t(b,a,c){var e=0==c,d=b.$n(a);b=b.$n(a+"-embed");d&&(d=d.style,d.display=e?"none":"block",d.opacity=c,9>m.ie&&(d.filter="alpha(opacity="+100*c+")"));b&&(d=b.style,d.display=e?"block":"none")}function w(b,a,c){if(a>c)return b;b<a&&(b=a);b>c&&(b=c);return b}zul.Scrollbar=m.$extends(m.Object,{_pos:null,_barPos:null,_pressTimer:null,_frozenScroll:0,_frozenLimit:!1,$n:function(b){return jq(this.uid+"-"+b,m)[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 e=b.style;e.position="relative";e.overflow="hidden";this.scroller=a;this.opts=m.$default(c,{embed:!1,step:20,wheelAmountStep:3,startPositionX:0,startPositionY:0});this.widget=m.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).bind("scroll",this.proxy(this._fixScroll)).bind("mouseenter",this.proxy(this._mouseEnter)).bind("mouseleave",this.proxy(this._mouseLeave))},destroy:function(){jq(this.cave).unbind("scroll",
this.proxy(this._fixScroll)).unbind("mouseenter",this.proxy(this._mouseEnter)).unbind("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;var c=a.frozen;var e=0;var d=a.$n("tpad");var f=a.$n("bpad");var g=this.cave,h=this.scroller,r=this.$n("hor");a=this.$n("ver");var y=this.needH,n=this.needV,u=this.opts,v=h.scrollHeight;d&&f&&(v+=d.offsetHeight+f.offsetHeight);c&&(e=50*(c._scrollScale||0));if(y){c=r.style.display;r.style.display="block";d=this.$n("hor-embed");var m=this.$n("hor-left"),w=this.$n("hor-right");f=this.$n("hor-wrapper");var p=f.style;var k=u.startPositionX,q=g.offsetWidth-k;h=h.scrollWidth-k+e;var x=
m.offsetWidth,z=w.offsetWidth,l=q-x-z;h<q&&(h=q+e);k&&(m.style.left=jq.px(k),p.left=jq.px(k+x),d&&(d.style.left=jq.px(k)));n?(p.width=jq.px(l-z),w.style.right=jq.px(z),p=a.style.display,a.style.display="block",h+=a.offsetWidth,a.style.display=p):p.width=jq.px(l);p=this.$n("hor-indicator");f=f.offsetWidth;e=Math.round(f*q/h);e=15<e?e:15;p.style.width=e+"px";d&&(d.style.width=e+x+z+"px");this.hLimit=h-q;d=f-e;0>=d?(this.hBarLimit=0,p.style.display="none"):this.hBarLimit=d;this.hRatio=Math.abs(this.hLimit/
this.hBarLimit);this.needH=p.offsetHeight;r.style.display=c}n&&(c=a.style.display,a.style.display="block",d=this.$n("ver-embed"),n=this.$n("ver-up"),q=this.$n("ver-down"),f=this.$n("ver-wrapper"),p=f.style,h=u.startPositionY,u=g.offsetHeight-h,v-=h,n=n.offsetHeight,e=q.offsetHeight,x=u-n-e,h&&(a.style.top=jq.px(g.offsetTop+h),q.style.bottom=jq.px(h),d&&(d.style.top=a.style.top)),y?(p.height=jq.px0(x-e),q.style.bottom=jq.px(h+e),g=r.style.display,r.style.display="block",v+=r.offsetHeight,r.style.display=
g):p.height=jq.px(x),p=this.$n("ver-indicator"),r=f.offsetHeight,g=Math.round(r*u/v),g=15<g?g:15,p.style.height=g+"px",d&&(d.style.height=g+n+e+"px"),this.vLimit=v-u,d=r-g,0>=d?(this.vBarLimit=0,p.style.display="none"):this.vBarLimit=d,this.vRatio=Math.abs(this.vLimit/this.vBarLimit),this.needV=p.offsetWidth,a.style.display=c);this.scrollTo(this._pos[0],this._pos[1]);b&&(t(this,"hor",1),t(this,"ver",1))},scrollTo:function(b,a){if(this.needH){b=w(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=w(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,e=c+b.offsetHeight,d=jq(b).offset().left,f=d+b.offsetWidth,g=jq(a).offset().top,h=g+a.offsetHeight,r=jq(a).offset().left,y=r+a.offsetWidth,n=!0;a=b.offsetWidth==a.offsetWidth;(f>=r&&f<=y||d>=r&&d<=
y||d<=r&&f>=y)&&(c>=g&&c<=h||e>=g&&e<=h||c<=g&&e>=h)||(c<g&&(n=!1),d<r&&(a=!1),c=n?e-h:g-c,n=this._pos[1]+(n?c:-c),d=a?f-y:r-d,d=this._pos[0]+(a?d:-d),this.needV&&(n=w(n,0,this.vLimit),f=n/this.vRatio,this._syncPosition("ver",n),this._syncBarPosition("ver",f),this._syncEmbedBarPosition("ver",n+f)),this.needH&&(d=w(d,0,this.hLimit),f=d/this.hRatio,this._syncPosition("hor",d),this._syncBarPosition("hor",f),this._syncEmbedBarPosition("hor",d+f)),this._onScrollEnd(),m(b).scrollIntoView())},isScrollIntoView:function(b){var a=
this.cave,c=jq(b).offset().top,e=c+b.offsetHeight,d=jq(b).offset().left;b=d+b.offsetWidth;var f=jq(a).offset().top,g=f+a.offsetHeight,h=jq(a).offset().left;a=h+a.offsetWidth;return this.needV&&e<=g&&c>=f||this.needH&&b<=a&&d>=h?!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,e=this.$n(b),d=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>m.ie&&m.opera?jq(a).mousewheel(this.proxy(this._mousewheelY)):jq(a).mousewheel(this.proxy(this._mousewheelX));jq(e).click(m.$void);jq(d).bind("mousedown",this.proxy(this._dragStart));jq(f).bind("mousedown",this.proxy(this._mouseDown)).bind("mouseup",this.proxy(this._mouseUp));
jq(g).bind("mousedown",this.proxy(this._mouseDown)).bind("mouseup",this.proxy(this._mouseUp));jq(b).bind("mousedown",this.proxy(this._mouseDown)).bind("mouseup",this.proxy(this._mouseUp))},_unbindMouseEvent:function(b){var a=this.cave,c="hor"==b,e=this.$n(b),d=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>m.ie&&m.opera?jq(a).unmousewheel(this.proxy(this._mousewheelY)):jq(a).unmousewheel(this.proxy(this._mousewheelX));jq(e).unbind("click",
m.$void);jq(d).unbind("mousedown",this.proxy(this._dragStart));jq(f).unbind("mousedown",this.proxy(this._mouseDown)).unbind("mouseup",this.proxy(this._mouseUp));jq(g).unbind("mousedown",this.proxy(this._mouseDown)).unbind("mouseup",this.proxy(this._mouseUp));jq(b).unbind("mousedown",this.proxy(this._mouseDown)).unbind("mouseup",this.proxy(this._mouseUp))},_fixScroll:function(b){b=this.cave;this.dragging||this.scrollTo(b.scrollLeft,b.scrollTop)},_mouseEnter:function(b){t(this,"hor",1);t(this,"ver",
1)},_mouseLeave:function(b){this.dragging||(t(this,"hor",0),t(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).bind("mousemove",b,this.proxy(this._dragMove)).bind("mouseup",this.proxy(this._dragEnd))},_dragEnd:function(b){var a=b.pageX;b=b.pageY;var c=this.cave,
e=jq(c).offset().left,d=jq(c).offset().top;jq(document).unbind("mousemove",this.proxy(this._dragMove)).unbind("mouseup",this.proxy(this._dragEnd));this.dragging=!1;if(a<e||a>e+c.offsetWidth||b<d||b>d+c.offsetHeight)t(this,"hor",0),t(this,"ver",0)},_dragMove:function(b){var a=b.data;var c=a.orient,e=a.point;a=a.pos;var d="hor"==c,f=(d?b.pageX:b.pageY)-e;b=d?this.hBarLimit:this.vBarLimit;e=d?this.hRatio:this.vRatio;var g=this.widget.frozen;this.dragging=!0;f=w(a+f,0,b);this._syncBarPosition(c,f);g&&
d?(g._doScroll(f/(b/g._scrollScale)),this._syncEmbedBarPosition("hor",f)):(a=f*e,this._syncPosition(c,a),this._syncEmbedBarPosition(c,a+f),this._onScrollEnd())},_mousewheelX:function(b,a,c,e){a=this.opts;a=a.step*a.wheelAmountStep;e=this._pos[0];c&&(b.stop(),e=w(e+(0<c?-a:a)+a,0,this.hLimit),b=this.widget.frozen,c=e/this.hRatio,b?(a=this.hBarLimit/b._scrollScale,c/=a,b._doScroll(c),this._syncEmbedBarPosition("hor",c)):(this._syncPosition("hor",e),this._syncEmbedBarPosition("hor",e+c)),this._syncBarPosition("hor",
c),this._onScrollEnd())},_mousewheelY:function(b,a,c,e){a=this.opts;c=a.step*a.wheelAmountStep;a=this._pos[1];e&&(e=0<e,e&&0==a||!e&&a==this.vLimit||(b.stop(),a=w(a+(e?-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){var a;this._pressTimer&&(clearInterval(this._pressTimer),this._pressTimer=null);
var c=b.currentTarget,e=this.$n("hor-rail"),d=this.$n("ver-rail"),f=this.$n("ver-up"),g=this.$n("ver-down"),h=this.$n("hor-left"),r=this.$n("hor-right"),m=this.widget.frozen,n=this.hBarLimit,u=m?n/m._scrollScale:this.opts.step;if(c==e||c==d){var v=(a=c==e)?"hor":"ver";e=jq(c).offset();e=a?e.left:e.top;d=this.$n(v+"-indicator");var t=(a?b.pageX:b.pageY)-e-(a?d.offsetWidth:d.offsetHeight)/2;var A=a?this.hLimit:this.vLimit;var p=a?this.hRatio:this.vRatio;var k=a?this._pos[0]:this._pos[1];var q=a?this._barPos[0]:
this._barPos[1];var x=t*p,z=10*u;var l=this;m?(t=w(t,0,n),l._syncBarPosition("hor",t),l._syncEmbedBarPosition("hor",t),m._doScroll(t/u)):l._pressTimer=setInterval(function(){var a=t>q;var b=a?k:x;b=0>b?0:b;var c=a?x:k;c=c>A?A:c;k+=a?z:-z;k=w(k,b,c);a=k/p;if(k==x||k<=b||k>=c)clearInterval(l._pressTimer),l._pressTimer=null;l._syncPosition(v,k);l._syncBarPosition(v,a);l._syncEmbedBarPosition(v,k+a);l._onScrollEnd()},50)}if(c==h||c==r||c==f||c==g)l=this,v=(a=c==h||c==r)?"hor":"ver",A=a?l.hLimit:l.vLimit,
p=a?l.hRatio:l.vRatio,k=a?l._pos[0]:l._pos[1],q=l._barPos[0],l._pressTimer=setInterval(function(){m&&a?(q+=c==h?-u:u,q=w(q,0,n),l._syncBarPosition(v,q),l._syncEmbedBarPosition(v,q),m._doScroll(q/u)):(k=a?k+(c==h?-u:u):k+(c==f?-u:u),k=w(k,0,A),q=k/p,l._syncPosition(v,k),l._syncBarPosition(v,q),l._syncEmbedBarPosition(v,k+q),l._onScrollEnd())},50)},_syncPosition:function(b,a){if(this._pos){var c="hor"==b,e=this.cave;b=this.$n(b);var d=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",d&&(this.$n("ver-embed").style.right=-a+"px")),!c&&this.needH&&(this.$n("hor").style.bottom=-a+"px",d&&(this.$n("hor-embed").style.bottom=-a+"px")),e[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 e=this.opts;b.style[c?"left":"top"]=a+(c?e.startPositionX:e.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 e=c?"horizontal":"vertical",d=c?"left":"up";c=c?"right":"down";var f="";this.opts.embed&&(f+='<div id="'+a+'-embed" class="z-scrollbar-'+e+'-embed"></div>');f+='<div id="'+a+'" class="z-scrollbar z-scrollbar-'+
e+'"><div id="'+a+"-"+d+'" class="z-scrollbar-'+d+'"><i class="z-icon-caret-'+d+'"></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);
