/*
 * Tiny Scrollbar 1.65
 * http://www.baijs.nl/tinyscrollbar/
 *
 * Copyright 2010, Maarten Baijs
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/gpl-2.0.php
 *
 * Date: 10 / 05 / 2011
 * Depends on library: jQuery
 * 
 * Modified for vBulletin
 * 		- added namespace to event handlers to prevent affecting other attached similar events when unbinding
 * 		- added 'update' callback to the options to allow custom function to call whenever tinyscrollbar_update() is called
 */
(function(A){A.tiny=A.tiny||{};A.tiny.scrollbar={options:{axis:"y",wheel:40,scroll:true,size:"auto",sizethumb:"auto",update:null}};A.fn.tinyscrollbar=function(C){var C=A.extend({},A.tiny.scrollbar.options,C);this.each(function(){A(this).data("tsb",new B(A(this),C))});return this};A.fn.tinyscrollbar_update=function(C){return A(this).data("tsb").update(C)};function B(Q,F){var J=this;var T=Q;var I={obj:A(".viewport",Q)};var G={obj:A(".overview",Q)};var D={obj:A(".scrollbar",Q)};var L={obj:A(".track",D.obj)};var P={obj:A(".thumb",D.obj)};var K=F.axis=="x",N=K?"left":"top",V=K?"Width":"Height";var R,Y={start:0,now:0},O={};var M="tinyscrollbar";function C(){J.update();S();return J}this.update=function(Z){I[F.axis]=I.obj[0]["offset"+V];G[F.axis]=G.obj[0]["scroll"+V];G.ratio=I[F.axis]/G[F.axis];D.obj.toggleClass("disable",G.ratio>=1);L[F.axis]=F.size=="auto"?I[F.axis]:F.size;P[F.axis]=Math.min(L[F.axis],Math.max(0,(F.sizethumb=="auto"?(L[F.axis]*G.ratio):F.sizethumb)));D.ratio=F.sizethumb=="auto"?(G[F.axis]/L[F.axis]):(G[F.axis]-I[F.axis])/(L[F.axis]-P[F.axis]);R=(Z=="relative"&&G.ratio<=1)?Math.min((G[F.axis]-I[F.axis]),Math.max(0,R)):0;R=(Z=="bottom"&&G.ratio<=1)?(G[F.axis]-I[F.axis]):isNaN(parseInt(Z))?R:parseInt(Z);W();if(typeof F.update=="function"){F.update.apply(T)}};function W(){if(R<0){R=0}P.obj.css(N,R/D.ratio);G.obj.css(N,-R);O.start=P.obj.offset()[N];var Z=V.toLowerCase();D.obj.css(Z,L[F.axis]);L.obj.css(Z,L[F.axis]);P.obj.css(Z,P[F.axis])}function S(){P.obj.bind("mousedown."+M,H);P.obj[0].ontouchstart=function(Z){Z.preventDefault();P.obj.unbind("mousedown."+M);H(Z.touches[0]);return false};L.obj.bind("mouseup."+M,U);if(F.scroll&&this.addEventListener){T[0].addEventListener("DOMMouseScroll",X,false);T[0].addEventListener("mousewheel",X,false)}else{if(F.scroll){T[0].onmousewheel=X}}}function H(a){O.start=K?a.pageX:a.pageY;var Z=parseInt(P.obj.css(N));Y.start=Z=="auto"?0:Z;A(document).bind("mousemove."+M,U);document.ontouchmove=function(b){A(document).unbind("mousemove."+M);U(b.touches[0])};A(document).bind("mouseup."+M,E);P.obj.bind("mouseup."+M,E);P.obj[0].ontouchend=document.ontouchend=function(b){A(document).unbind("mouseup."+M);P.obj.unbind("mouseup."+M);E(b.touches[0])};return false}function X(a){if(!(G.ratio>=1)){a=A.event.fix(a||window.event);var Z=a.wheelDelta?a.wheelDelta/120:-a.detail/3;R-=Z*F.wheel;R=Math.min((G[F.axis]-I[F.axis]),Math.max(0,R));P.obj.css(N,R/D.ratio);G.obj.css(N,-R);a.preventDefault()}}function E(Z){A(document).unbind("mousemove."+M,U);A(document).unbind("mouseup."+M,E);P.obj.unbind("mouseup."+M,E);document.ontouchmove=P.obj[0].ontouchend=document.ontouchend=null;return false}function U(Z){if(!(G.ratio>=1)){Y.now=Math.min((L[F.axis]-P[F.axis]),Math.max(0,(Y.start+((K?Z.pageX:Z.pageY)-O.start))));R=Y.now*D.ratio;G.obj.css(N,-R);P.obj.css(N,Y.now)}return false}return C()}})(jQuery);