/*
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 3.3.0
build: 3167
*/
YUI.add("scrollview-scrollbars",function(a){var l=a.ClassNameManager.getClassName,i,j=a.Transition.useNative,z="scrollbar",C="scrollview",B="verticalNode",m="horizontalNode",u="childCache",w="top",q="left",g="width",v="height",p="scrollWidth",h="scrollHeight",A="_sbh",t="_sbv",n="transitionProperty",f="transform",e="translateX(",d="translateY(",y="scaleX(",x="scaleY(",s="scrollX",r="scrollY",k="px",c=")",o=k+c;function b(){b.superclass.constructor.apply(this,arguments);}b.CLASS_NAMES={showing:l(C,z,"showing"),scrollbar:l(C,z),scrollbarV:l(C,z,"vert"),scrollbarH:l(C,z,"horiz"),scrollbarVB:l(C,z,"vert","basic"),scrollbarHB:l(C,z,"horiz","basic"),child:l(C,"child"),first:l(C,"first"),middle:l(C,"middle"),last:l(C,"last")};i=b.CLASS_NAMES;b.NAME="pluginScrollViewScrollbars";b.NS="scrollbars";b.SCROLLBAR_TEMPLATE=["<div>",'<span class="'+i.child+" "+i.first+'"></span>','<span class="'+i.child+" "+i.middle+'"></span>','<span class="'+i.child+" "+i.last+'"></span>',"</div>"].join("");b.ATTRS={verticalNode:{setter:"_setNode",valueFn:"_defaultNode"},horizontalNode:{setter:"_setNode",valueFn:"_defaultNode"}};a.namespace("Plugin").ScrollViewScrollbars=a.extend(b,a.Plugin.Base,{initializer:function(){this._host=this.get("host");this.afterHostEvent("scrollEnd",this._hostScrollEnd);this.afterHostMethod("_uiScrollTo",this._update);this.afterHostMethod("_uiDimensionsChange",this._hostDimensionsChange);},_hostDimensionsChange:function(){var D=this._host;this._renderBar(this.get(B),D._scrollsVertical);this._renderBar(this.get(m),D._scrollsHorizontal);this._update();a.later(500,this,"flash",true);},_hostScrollEnd:function(D){if(!this._host._flicking){this.flash();}},_renderBar:function(E,G){var F=E.inDoc(),H=this._host._bb,D=E.getData("isHoriz")?i.scrollbarHB:i.scrollbarVB;if(G&&!F){H.append(E);E.toggleClass(D,this._basic);this._setChildCache(E);}else{if(!G&&F){E.remove();this._clearChildCache(E);}}},_setChildCache:function(G){var I=G.get("children"),E=I.item(0),H=I.item(1),F=I.item(2),D=G.getData("isHoriz")?"offsetWidth":"offsetHeight";G.setStyle(n,f);H.setStyle(n,f);F.setStyle(n,f);G.setData(u,{fc:E,lc:F,mc:H,fcSize:E&&E.get(D),lcSize:F&&F.get(D)});},_clearChildCache:function(D){D.clearData(u);},_updateBar:function(D,M,F,W){var K=this._host,G=this._basic,L=K._cb,R=0,N=1,E=D.getData(u),S=E.lc,V=E.mc,aa=E.fcSize,Z=E.lcSize,O,X,U,J,Y,Q,H,T,P,I;if(W){Q=g;H=q;T=A;P=K.get(Q);I=K._scrollWidth||L.get(p);J=e;Y=y;M=(M!==undefined)?M:K.get(s);}else{Q=v;H=w;T=t;P=K.get(Q);I=K._scrollHeight||L.get(h);J=d;Y=x;M=(M!==undefined)?M:K.get(r);}R=Math.floor(P*(P/I));N=Math.floor((M/(I-P))*(P-R));if(R>P){R=1;}if(N>(P-R)){R=R-(N-(P-R));}else{if(N<0){R=N+R;N=0;}}O=(R-(aa+Z));if(O<0){O=0;}if(O===0&&N!==0){N=P-(aa+Z)-1;}if(F!==0){U={duration:F};if(j){U.transform=J+N+o;}else{U[H]=N+k;}D.transition(U);}else{if(j){D.setStyle(f,J+N+o);}else{D.setStyle(H,N+k);}}if(this[T]!==O){this[T]=O;if(O>0){if(F!==0){U={duration:F};if(j){U.transform=Y+O+c;}else{U[Q]=O+k;}V.transition(U);}else{if(j){V.setStyle(f,Y+O+c);}else{V.setStyle(Q,O+k);}}if(!W||!G){X=R-Z;if(F!==0){U={duration:F};if(j){U.transform=J+X+o;}else{U[H]=X;}S.transition(U);}else{if(j){S.setStyle(f,J+X+o);}else{S.setStyle(H,X+k);}}}}}},_update:function(E,J,H,I){var G=this.get(B),D=this.get(m),F=this._host;H=(H||0)/1000;if(!this._showing){this.show();}if(F._scrollsVertical&&G){this._updateBar(G,J,H,false);}if(F._scrollsHorizontal&&D){this._updateBar(D,E,H,true);}},show:function(D){this._show(true,D);},hide:function(D){this._show(false,D);},_show:function(D,G){var F=this.get(B),H=this.get(m),I=(G)?0.6:0,E=(D)?1:0,J;this._showing=D;if(this._flashTimer){this._flashTimer.cancel();}J={duration:I,opacity:E};if(F){F.transition(J);}if(H){H.transition(J);}},flash:function(){var D=false,E=this._host;if(E._scrollsVertical&&(E._scrollHeight>E.get(v))){D=true;}if(E._scrollsHorizontal&&(E._scrollWidth>E.get(g))){D=true;}if(D){this.show(true);this._flashTimer=a.later(800,this,"hide",true);}},_setNode:function(E,D){var F=(D==m);E=a.one(E);if(E){E.addClass(i.scrollbar);E.addClass((F)?i.scrollbarH:i.scrollbarV);E.setData("isHoriz",F);}return E;},_defaultNode:function(){return a.Node.create(b.SCROLLBAR_TEMPLATE);},_basic:a.UA.ie&&a.UA.ie<=8});},"3.3.0",{skinnable:true,requires:["plugin"]});