Plugin Directory

Changeset 3126870


Ignore:
Timestamp:
07/28/2024 06:15:58 PM (20 months ago)
Author:
webshouter
Message:

Bug Fixes

Location:
ws-custom-scrollbar/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ws-custom-scrollbar/trunk/js/jquery.nicescroll.js

    r1271098 r3126870  
    11/* jquery.nicescroll
    2 -- version 3.4.0
    3 -- copyright 2011-12-13 InuYaksa*2013
     2-- version 3.7.6
     3-- copyright 2017-07-19 InuYaksa*2017
    44-- licensed under the MIT
    55--
    6 -- http://areaaperta.com/nicescroll
     6-- https://nicescroll.areaaperta.com/
    77-- https://github.com/inuyaksa/jquery.nicescroll
    88--
    99*/
    1010
    11 (function(jQuery){
     11/* jshint expr: true */
     12
     13(function (factory) {
     14  if (typeof define === 'function' && define.amd) {
     15    // AMD. Register as anonymous module.
     16    define(['jquery'], factory);
     17  } else if (typeof exports === 'object') {
     18    // Node/CommonJS.
     19    module.exports = factory(require('jquery'));
     20  } else {
     21    // Browser globals.
     22    factory(jQuery);
     23  }
     24}(function (jQuery) {
     25
     26  "use strict";
    1227
    1328  // globals
    14   var domfocus = false;
    15   var mousefocus = false;
    16   var zoomactive = false;
    17   var tabindexcounter = 5000;
    18   var ascrailcounter = 2000;
    19   var globalmaxzindex = 0;
    20  
    21   var $ = jQuery;  // sandbox
    22  
     29  var domfocus = false,
     30    mousefocus = false,
     31    tabindexcounter = 0,
     32    ascrailcounter = 2000,
     33    globalmaxzindex = 0;
     34
     35  var $ = jQuery,       // sandbox
     36    _doc = document,
     37    _win = window,
     38    $window = $(_win);
     39
     40  var delegatevents = [];
     41
    2342  // http://stackoverflow.com/questions/2161159/get-script-path
    2443  function getScriptPath() {
    25     var scripts=document.getElementsByTagName('script');
    26     var path=scripts[scripts.length-1].src.split('?')[0];
    27     return (path.split('/').length>0) ? path.split('/').slice(0,-1).join('/')+'/' : '';
     44    var scripts = _doc.currentScript || (function () { var s = _doc.getElementsByTagName('script'); return (s.length) ? s[s.length - 1] : false; })();
     45    var path = scripts ? scripts.src.split('?')[0] : '';
     46    return (path.split('/').length > 0) ? path.split('/').slice(0, -1).join('/') + '/' : '';
    2847  }
    29   var scriptpath = getScriptPath();
    30 
    31 // derived by Paul Irish https://gist.github.com/paulirish/1579671 - thanks for your code!
    32 
    33   if (!Array.prototype.forEach) {  // JS 1.6 polyfill
    34     Array.prototype.forEach = function(fn, scope) {
    35       for(var i = 0, len = this.length; i < len; ++i) {
    36         fn.call(scope, this[i], i, this);
    37       }
    38     }
     48
     49  // based on code by Paul Irish https://www.paulirish.com/2011/requestanimationframe-for-smart-animating/ 
     50  var setAnimationFrame = _win.requestAnimationFrame || _win.webkitRequestAnimationFrame || _win.mozRequestAnimationFrame || false;
     51  var clearAnimationFrame = _win.cancelAnimationFrame || _win.webkitCancelAnimationFrame || _win.mozCancelAnimationFrame || false;
     52
     53  if (!setAnimationFrame) {
     54    var anilasttime = 0;
     55    setAnimationFrame = function (callback, element) {
     56      var currTime = new Date().getTime();
     57      var timeToCall = Math.max(0, 16 - (currTime - anilasttime));
     58      var id = _win.setTimeout(function () { callback(currTime + timeToCall); },
     59        timeToCall);
     60      anilasttime = currTime + timeToCall;
     61      return id;
     62    };
     63    clearAnimationFrame = function (id) {
     64      _win.clearTimeout(id);
     65    };
     66  } else {
     67    if (!_win.cancelAnimationFrame) clearAnimationFrame = function (id) { };
    3968  }
    40  
    41   var vendors = ['ms','moz','webkit','o'];
    42  
    43   var setAnimationFrame = window.requestAnimationFrame||false;
    44   var clearAnimationFrame = window.cancelAnimationFrame||false;
    45 
    46   vendors.forEach(function(v){
    47     if (!setAnimationFrame) setAnimationFrame = window[v+'RequestAnimationFrame'];
    48     if (!clearAnimationFrame) clearAnimationFrame = window[v+'CancelAnimationFrame']||window[v+'CancelRequestAnimationFrame'];   
    49   });
    50  
    51   var clsMutationObserver = window.MutationObserver || window.WebKitMutationObserver || false;
    52  
     69
     70  var ClsMutationObserver = _win.MutationObserver || _win.WebKitMutationObserver || false;
     71
     72  var now = Date.now || function () { return new Date().getTime(); };
     73
    5374  var _globaloptions = {
    54       zindex:"auto",
    55       cursoropacitymin:0,
    56       cursoropacitymax:1,
    57       cursorcolor:"#424242",
    58       cursorwidth:"5px",
    59       cursorborder:"1px solid #fff",
    60       cursorborderradius:"5px",
    61       scrollspeed:60,
    62       mousescrollstep:8*3,
    63       touchbehavior:false,
    64       hwacceleration:true,
    65       usetransition:true,
    66       boxzoom:false,
    67       dblclickzoom:true,
    68       gesturezoom:true,
    69       grabcursorenabled:true,
    70       autohidemode:true,
    71       background:"",
    72       iframeautoresize:true,
    73       cursorminheight:32,
    74       preservenativescrolling:true,
    75       railoffset:false,
    76       bouncescroll:true,
    77       spacebarenabled:true,
    78       railpadding:{top:0,right:0,left:0,bottom:0},
    79       disableoutline:true,
    80       horizrailenabled:true,
    81       railalign:"right",
    82       railvalign:"bottom",
    83       enabletranslate3d:true,
    84       enablemousewheel:true,
    85       enablekeyboard:true,
    86       smoothscroll:true,
    87       sensitiverail:true,
    88       enablemouselockapi:true,
    89 //      cursormaxheight:false,
    90       cursorfixedheight:false,     
    91       directionlockdeadzone:6,
    92       hidecursordelay:400,
    93       nativeparentscrolling:true,
    94       enablescrollonselection:true,
    95       overflowx:true,
    96       overflowy:true,
    97       cursordragspeed:0.3,
    98       rtlmode:false,
    99       cursordragontouch:false
    100   }
    101  
     75    zindex: "auto",
     76    cursoropacitymin: 0,
     77    cursoropacitymax: 1,
     78    cursorcolor: "#424242",
     79    cursorwidth: "6px",
     80    cursorborder: "1px solid #fff",
     81    cursorborderradius: "5px",
     82    scrollspeed: 40,
     83    mousescrollstep: 9 * 3,
     84    touchbehavior: false,   // deprecated
     85    emulatetouch: false,    // replacing touchbehavior
     86    hwacceleration: true,
     87    usetransition: true,
     88    boxzoom: false,
     89    dblclickzoom: true,
     90    gesturezoom: true,
     91    grabcursorenabled: true,
     92    autohidemode: true,
     93    background: "",
     94    iframeautoresize: true,
     95    cursorminheight: 32,
     96    preservenativescrolling: true,
     97    railoffset: false,
     98    railhoffset: false,
     99    bouncescroll: true,
     100    spacebarenabled: true,
     101    railpadding: {
     102      top: 0,
     103      right: 0,
     104      left: 0,
     105      bottom: 0
     106    },
     107    disableoutline: true,
     108    horizrailenabled: true,
     109    railalign: "right",
     110    railvalign: "bottom",
     111    enabletranslate3d: true,
     112    enablemousewheel: true,
     113    enablekeyboard: true,
     114    smoothscroll: true,
     115    sensitiverail: true,
     116    enablemouselockapi: true,
     117    //      cursormaxheight:false,
     118    cursorfixedheight: false,
     119    directionlockdeadzone: 6,
     120    hidecursordelay: 400,
     121    nativeparentscrolling: true,
     122    enablescrollonselection: true,
     123    overflowx: true,
     124    overflowy: true,
     125    cursordragspeed: 0.3,
     126    rtlmode: "auto",
     127    cursordragontouch: false,
     128    oneaxismousemode: "auto",
     129    scriptpath: getScriptPath(),
     130    preventmultitouchscrolling: true,
     131    disablemutationobserver: false,
     132    enableobserver: true,
     133    scrollbarid: false
     134  };
     135
    102136  var browserdetected = false;
    103  
    104   var getBrowserDetection = function() {
    105  
     137
     138  var getBrowserDetection = function () {
     139
    106140    if (browserdetected) return browserdetected;
    107  
    108     var domtest = document.createElement('DIV');
    109 
    110     var d = {};
    111    
    112         d.haspointerlock = "pointerLockElement" in document || "mozPointerLockElement" in document || "webkitPointerLockElement" in document;
    113        
    114     d.isopera = ("opera" in window);
    115     d.isopera12 = (d.isopera&&("getUserMedia" in navigator));
    116    
    117     d.isie = (("all" in document) && ("attachEvent" in domtest) && !d.isopera);
    118     d.isieold = (d.isie && !("msInterpolationMode" in domtest.style));  // IE6 and older
    119     d.isie7 = d.isie&&!d.isieold&&(!("documentMode" in document)||(document.documentMode==7));
    120     d.isie8 = d.isie&&("documentMode" in document)&&(document.documentMode==8);
    121     d.isie9 = d.isie&&("performance" in window)&&(document.documentMode>=9);
    122     d.isie10 = d.isie&&("performance" in window)&&(document.documentMode>=10);
    123    
    124     d.isie9mobile = /iemobile.9/i.test(navigator.userAgent);  //wp 7.1 mango
    125     if (d.isie9mobile) d.isie9 = false;
    126     d.isie7mobile = (!d.isie9mobile&&d.isie7) && /iemobile/i.test(navigator.userAgent);  //wp 7.0
    127    
    128     d.ismozilla = ("MozAppearance" in domtest.style);
    129        
    130     d.iswebkit = ("WebkitAppearance" in domtest.style);
    131    
    132     d.ischrome = ("chrome" in window);
    133         d.ischrome22 = (d.ischrome&&d.haspointerlock);
    134     d.ischrome26 = (d.ischrome&&("transition" in domtest.style));  // issue with transform detection (maintain prefix)
    135    
    136     d.cantouch = ("ontouchstart" in document.documentElement)||("ontouchstart" in window);  // detection for Chrome Touch Emulation
    137     d.hasmstouch = (window.navigator.msPointerEnabled||false);  // IE10+ pointer events
    138        
    139     d.ismac = /^mac$/i.test(navigator.platform);
    140    
    141     d.isios = (d.cantouch && /iphone|ipad|ipod/i.test(navigator.platform));
    142     d.isios4 = ((d.isios)&&!("seal" in Object));
    143    
    144     d.isandroid = (/android/i.test(navigator.userAgent));
    145    
     141
     142    var _el = _doc.createElement('DIV'),
     143      _style = _el.style,
     144      _agent = navigator.userAgent,
     145      _platform = navigator.platform,
     146      d = {};
     147
     148    d.haspointerlock = "pointerLockElement" in _doc || "webkitPointerLockElement" in _doc || "mozPointerLockElement" in _doc;
     149
     150    d.isopera = ("opera" in _win); // 12-
     151    d.isopera12 = (d.isopera && ("getUserMedia" in navigator));
     152    d.isoperamini = (Object.prototype.toString.call(_win.operamini) === "[object OperaMini]");
     153
     154    d.isie = (("all" in _doc) && ("attachEvent" in _el) && !d.isopera); //IE10-
     155    d.isieold = (d.isie && !("msInterpolationMode" in _style)); // IE6 and older
     156    d.isie7 = d.isie && !d.isieold && (!("documentMode" in _doc) || (_doc.documentMode === 7));
     157    d.isie8 = d.isie && ("documentMode" in _doc) && (_doc.documentMode === 8);
     158    d.isie9 = d.isie && ("performance" in _win) && (_doc.documentMode === 9);
     159    d.isie10 = d.isie && ("performance" in _win) && (_doc.documentMode === 10);
     160    d.isie11 = ("msRequestFullscreen" in _el) && (_doc.documentMode >= 11); // IE11+
     161
     162    d.ismsedge = ("msCredentials" in _win);  // MS Edge 14+
     163
     164    d.ismozilla = ("MozAppearance" in _style);
     165
     166    d.iswebkit = !d.ismsedge && ("WebkitAppearance" in _style);
     167
     168    d.ischrome = d.iswebkit && ("chrome" in _win);
     169    d.ischrome38 = (d.ischrome && ("touchAction" in _style)); // behavior changed in touch emulation   
     170    d.ischrome22 = (!d.ischrome38) && (d.ischrome && d.haspointerlock);
     171    d.ischrome26 = (!d.ischrome38) && (d.ischrome && ("transition" in _style)); // issue with transform detection (maintain prefix)
     172
     173    d.cantouch = ("ontouchstart" in _doc.documentElement) || ("ontouchstart" in _win); // with detection for Chrome Touch Emulation   
     174    d.hasw3ctouch = (_win.PointerEvent || false) && ((navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)); //IE11 pointer events, following W3C Pointer Events spec
     175    d.hasmstouch = (!d.hasw3ctouch) && (_win.MSPointerEvent || false); // IE10 pointer events
     176
     177    d.ismac = /^mac$/i.test(_platform);
     178
     179    d.isios = d.cantouch && /iphone|ipad|ipod/i.test(_platform);
     180    d.isios4 = d.isios && !("seal" in Object);
     181    d.isios7 = d.isios && ("webkitHidden" in _doc);  //iOS 7+
     182    d.isios8 = d.isios && ("hidden" in _doc);  //iOS 8+
     183    d.isios10 = d.isios && _win.Proxy;  //iOS 10+
     184
     185    d.isandroid = (/android/i.test(_agent));
     186
     187    d.haseventlistener = ("addEventListener" in _el);
     188
    146189    d.trstyle = false;
    147190    d.hastransform = false;
     
    150193    d.hastransition = false;
    151194    d.transitionend = false;
    152    
    153     var check = ['transform','msTransform','webkitTransform','MozTransform','OTransform'];
    154     for(var a=0;a<check.length;a++){
    155       if (typeof domtest.style[check[a]] != "undefined") {
    156         d.trstyle = check[a];
    157         break;
    158       }
     195
     196    d.trstyle = "transform";
     197    d.hastransform = ("transform" in _style) || (function () {
     198      var check = ['msTransform', 'webkitTransform', 'MozTransform', 'OTransform'];
     199      for (var a = 0, c = check.length; a < c; a++) {
     200        if (_style[check[a]] !== undefined) {
     201          d.trstyle = check[a];
     202          break;
     203        }
     204      }
     205      d.hastransform = (!!d.trstyle);
     206    })();
     207
     208    if (d.hastransform) {
     209      _style[d.trstyle] = "translate3d(1px,2px,3px)";
     210      d.hastranslate3d = /translate3d/.test(_style[d.trstyle]);
    159211    }
    160     d.hastransform = (d.trstyle != false);
    161     if (d.hastransform) {
    162       domtest.style[d.trstyle] = "translate3d(1px,2px,3px)";
    163       d.hastranslate3d = /translate3d/.test(domtest.style[d.trstyle]);
    164     }
    165    
    166     d.transitionstyle = false;
     212
     213    d.transitionstyle = "transition";
    167214    d.prefixstyle = '';
    168     d.transitionend = false;
    169     var check = ['transition','webkitTransition','MozTransition','OTransition','OTransition','msTransition','KhtmlTransition'];
    170     var prefix = ['','-webkit-','-moz-','-o-','-o','-ms-','-khtml-'];
    171     var evs = ['transitionend','webkitTransitionEnd','transitionend','otransitionend','oTransitionEnd','msTransitionEnd','KhtmlTransitionEnd'];
    172     for(var a=0;a<check.length;a++) {
    173       if (check[a] in domtest.style) {
    174         d.transitionstyle = check[a];
    175         d.prefixstyle = prefix[a];
    176         d.transitionend = evs[a];
    177         break;
    178       }
    179     }
    180     if (d.ischrome26) {  // use always prefix
    181       d.prefixstyle = prefix[1];
    182     }
    183    
    184     d.hastransition = (d.transitionstyle);
    185    
    186     function detectCursorGrab() {     
    187       var lst = ['-moz-grab','-webkit-grab','grab'];
    188       if ((d.ischrome&&!d.ischrome22)||d.isie) lst=[];  // force setting for IE returns false positive and chrome cursor bug
    189       for(var a=0;a<lst.length;a++) {
     215    d.transitionend = "transitionend";
     216
     217    d.hastransition = ("transition" in _style) || (function () {
     218
     219      d.transitionend = false;
     220      var check = ['webkitTransition', 'msTransition', 'MozTransition', 'OTransition', 'OTransition', 'KhtmlTransition'];
     221      var prefix = ['-webkit-', '-ms-', '-moz-', '-o-', '-o', '-khtml-'];
     222      var evs = ['webkitTransitionEnd', 'msTransitionEnd', 'transitionend', 'otransitionend', 'oTransitionEnd', 'KhtmlTransitionEnd'];
     223      for (var a = 0, c = check.length; a < c; a++) {
     224        if (check[a] in _style) {
     225          d.transitionstyle = check[a];
     226          d.prefixstyle = prefix[a];
     227          d.transitionend = evs[a];
     228          break;
     229        }
     230      }
     231      if (d.ischrome26) d.prefixstyle = prefix[1];  // always use prefix
     232
     233      d.hastransition = (d.transitionstyle);
     234
     235    })();
     236
     237    function detectCursorGrab() {
     238      var lst = ['grab', '-webkit-grab', '-moz-grab'];
     239      if ((d.ischrome && !d.ischrome38) || d.isie) lst = []; // force setting for IE returns false positive and chrome cursor bug
     240      for (var a = 0, l = lst.length; a < l; a++) {
    190241        var p = lst[a];
    191         domtest.style['cursor']=p;
    192         if (domtest.style['cursor']==p) return p;
    193       }
    194       return 'url(http://www.google.com/intl/en_ALL/mapfiles/openhand.cur),n-resize';  // thank you google for custom cursor!
     242        _style.cursor = p;
     243        if (_style.cursor == p) return p;
     244      }
     245      return 'url(https://cdnjs.cloudflare.com/ajax/libs/slider-pro/1.3.0/css/images/openhand.cur),n-resize'; // thanks to https://cdnjs.com/ for the openhand cursor!
    195246    }
    196247    d.cursorgrabvalue = detectCursorGrab();
    197248
    198     d.hasmousecapture = ("setCapture" in domtest);
    199    
    200     d.hasMutationObserver = (clsMutationObserver !== false);
    201    
    202     domtest = null; //memory released
     249    d.hasmousecapture = ("setCapture" in _el);
     250
     251    d.hasMutationObserver = (ClsMutationObserver !== false);
     252
     253    _el = null; //memory released
    203254
    204255    browserdetected = d;
    205    
    206     return d; 
    207   }
    208  
    209   var NiceScrollClass = function(myopt,me) {
     256
     257    return d;
     258  };
     259
     260  var NiceScrollClass = function (myopt, me) {
    210261
    211262    var self = this;
    212263
    213     this.version = '3.4.0';
     264    this.version = '3.7.6';
    214265    this.name = 'nicescroll';
    215    
     266
    216267    this.me = me;
    217    
    218     this.opt = {
    219       doc:$("body"),
    220       win:false
    221     };
    222    
    223     $.extend(this.opt,_globaloptions);
    224    
    225 // Options for internal use
    226     this.opt.snapbackspeed = 80;
    227    
    228     if (myopt||false) {
    229       for(var a in self.opt) {
    230         if (typeof myopt[a] != "undefined") self.opt[a] = myopt[a];
     268
     269    var $body = $("body");
     270
     271    var opt = this.opt = {
     272      doc: $body,
     273      win: false
     274    };
     275
     276    $.extend(opt, _globaloptions);  // clone opts
     277
     278    // Options for internal use
     279    opt.snapbackspeed = 80;
     280
     281    if (myopt || false) {
     282      for (var a in opt) {
     283        if (myopt[a] !== undefined) opt[a] = myopt[a];
    231284      }
    232285    }
    233    
    234     this.doc = self.opt.doc;
    235     this.iddoc = (this.doc&&this.doc[0])?this.doc[0].id||'':'';   
    236     this.ispage = /BODY|HTML/.test((self.opt.win)?self.opt.win[0].nodeName:this.doc[0].nodeName);
    237     this.haswrapper = (self.opt.win!==false);
    238     this.win = self.opt.win||(this.ispage?$(window):this.doc);
    239     this.docscroll = (this.ispage&&!this.haswrapper)?$(window):this.win;
    240     this.body = $("body");
     286
     287    if (opt.disablemutationobserver) ClsMutationObserver = false;
     288
     289    this.doc = opt.doc;
     290    this.iddoc = (this.doc && this.doc[0]) ? this.doc[0].id || '' : '';
     291    this.ispage = /^BODY|HTML/.test((opt.win) ? opt.win[0].nodeName : this.doc[0].nodeName);
     292    this.haswrapper = (opt.win !== false);
     293    this.win = opt.win || (this.ispage ? $window : this.doc);
     294    this.docscroll = (this.ispage && !this.haswrapper) ? $window : this.win;
     295    this.body = $body;
    241296    this.viewport = false;
    242    
     297
    243298    this.isfixed = false;
    244    
     299
    245300    this.iframe = false;
    246301    this.isiframe = ((this.doc[0].nodeName == 'IFRAME') && (this.win[0].nodeName == 'IFRAME'));
    247    
     302
    248303    this.istextarea = (this.win[0].nodeName == 'TEXTAREA');
    249    
     304
    250305    this.forcescreen = false; //force to use screen position on events
    251306
    252     this.canshowonmouseevent = (self.opt.autohidemode!="scroll");
    253    
    254 // Events jump table   
     307    this.canshowonmouseevent = (opt.autohidemode != "scroll");
     308
     309    // Events jump table   
    255310    this.onmousedown = false;
    256311    this.onmouseup = false;
     
    260315    this.ongesturezoom = false;
    261316    this.onclick = false;
    262    
    263 // Nicescroll custom events
     317
     318    // Nicescroll custom events
    264319    this.onscrollstart = false;
    265320    this.onscrollend = false;
    266     this.onscrollcancel = false;   
    267    
     321    this.onscrollcancel = false;
     322
    268323    this.onzoomin = false;
    269324    this.onzoomout = false;
    270    
    271 // Let's start! 
     325
     326    // Let's start! 
    272327    this.view = false;
    273328    this.page = false;
    274    
    275     this.scroll = {x:0,y:0};
    276     this.scrollratio = {x:0,y:0};   
     329
     330    this.scroll = {
     331      x: 0,
     332      y: 0
     333    };
     334    this.scrollratio = {
     335      x: 0,
     336      y: 0
     337    };
    277338    this.cursorheight = 20;
    278339    this.scrollvaluemax = 0;
    279    
    280     this.checkrtlmode = false;
    281    
     340
     341    // http://dev.w3.org/csswg/css-writing-modes-3/#logical-to-physical
     342    // http://dev.w3.org/csswg/css-writing-modes-3/#svg-writing-mode
     343    if (opt.rtlmode == "auto") {
     344      var target = this.win[0] == _win ? this.body : this.win;
     345      var writingMode = target.css("writing-mode") || target.css("-webkit-writing-mode") || target.css("-ms-writing-mode") || target.css("-moz-writing-mode");
     346
     347      if (writingMode == "horizontal-tb" || writingMode == "lr-tb" || writingMode === "") {
     348        this.isrtlmode = (target.css("direction") == "rtl");
     349        this.isvertical = false;
     350      } else {
     351        this.isrtlmode = (writingMode == "vertical-rl" || writingMode == "tb" || writingMode == "tb-rl" || writingMode == "rl-tb");
     352        this.isvertical = (writingMode == "vertical-rl" || writingMode == "tb" || writingMode == "tb-rl");
     353      }
     354    } else {
     355      this.isrtlmode = (opt.rtlmode === true);
     356      this.isvertical = false;
     357    }
     358    //    this.checkrtlmode = false;
     359
    282360    this.scrollrunning = false;
    283    
     361
    284362    this.scrollmom = false;
    285    
    286     this.observer = false;
     363
     364    this.observer = false;  // observer div changes
    287365    this.observerremover = false;  // observer on parent for remove detection
    288    
    289     do {
    290       this.id = "ascrail"+(ascrailcounter++);
    291     } while (document.getElementById(this.id));
    292    
     366    this.observerbody = false;  // observer on body for position change
     367
     368    if (opt.scrollbarid !== false) {
     369      this.id = opt.scrollbarid;
     370    } else {
     371      do {
     372        this.id = "ascrail" + (ascrailcounter++);
     373      } while (_doc.getElementById(this.id));
     374    }
     375
    293376    this.rail = false;
    294377    this.cursor = false;
    295     this.cursorfreezed = false; 
     378    this.cursorfreezed = false;
    296379    this.selectiondrag = false;
    297    
     380
    298381    this.zoom = false;
    299382    this.zoomactive = false;
    300    
     383
    301384    this.hasfocus = false;
    302385    this.hasmousefocus = false;
    303    
    304     this.visibility = true;
    305     this.locked = false;
     386
     387    //this.visibility = true;
     388    this.railslocked = false;  // locked by resize
     389    this.locked = false;  // prevent lost of locked status sets by user
    306390    this.hidden = false; // rails always hidden
    307391    this.cursoractive = true; // user can interact with cursors
    308    
    309     this.overflowx = self.opt.overflowx;
    310     this.overflowy = self.opt.overflowy;
    311    
     392
     393    this.wheelprevented = false; //prevent mousewheel event
     394
     395    this.overflowx = opt.overflowx;
     396    this.overflowy = opt.overflowy;
     397
    312398    this.nativescrollingarea = false;
    313399    this.checkarea = 0;
    314    
    315     this.events = [];  // event list for unbind
    316    
    317     this.saved = {};
    318    
     400
     401    this.events = []; // event list for unbind
     402
     403    this.saved = {};  // style saved
     404
    319405    this.delaylist = {};
    320406    this.synclist = {};
    321    
     407
    322408    this.lastdeltax = 0;
    323409    this.lastdeltay = 0;
    324    
    325     this.detected = getBrowserDetection();
    326    
    327     var cap = $.extend({},this.detected);
    328  
    329     this.canhwscroll = (cap.hastransform&&self.opt.hwacceleration);
    330     this.ishwscroll = (this.canhwscroll&&self.haswrapper);
    331    
    332     this.istouchcapable = false;  // desktop devices with touch screen support
    333    
    334 //## Check Chrome desktop with touch support
    335     if (cap.cantouch&&cap.ischrome&&!cap.isios&&!cap.isandroid) {
     410
     411    this.detected = getBrowserDetection();
     412
     413    var cap = $.extend({}, this.detected);
     414
     415    this.canhwscroll = (cap.hastransform && opt.hwacceleration);
     416    this.ishwscroll = (this.canhwscroll && self.haswrapper);
     417
     418    if (!this.isrtlmode) {
     419      this.hasreversehr = false;
     420    } else if (this.isvertical) { // RTL mode with reverse horizontal axis
     421      this.hasreversehr = !(cap.iswebkit || cap.isie || cap.isie11);
     422    } else {
     423      this.hasreversehr = !(cap.iswebkit || (cap.isie && !cap.isie10 && !cap.isie11));
     424    }
     425
     426    this.istouchcapable = false; // desktop devices with touch screen support
     427
     428    //## Check WebKit-based desktop with touch support
     429    //## + Firefox 18 nightly build (desktop) false positive (or desktop with touch support)
     430
     431    if (!cap.cantouch && (cap.hasw3ctouch || cap.hasmstouch)) {  // desktop device with multiple input
    336432      this.istouchcapable = true;
    337       cap.cantouch = false;  // parse normal desktop events
    338     }   
    339 
    340 //## Firefox 18 nightly build (desktop) false positive (or desktop with touch support)
    341     if (cap.cantouch&&cap.ismozilla&&!cap.isios) {
     433    } else if (cap.cantouch && !cap.isios && !cap.isandroid && (cap.iswebkit || cap.ismozilla)) {
    342434      this.istouchcapable = true;
    343       cap.cantouch = false;  // parse normal desktop events
    344     }   
    345    
    346 //## disable MouseLock API on user request
    347 
    348     if (!self.opt.enablemouselockapi) {
     435    }
     436
     437    //## disable MouseLock API on user request
     438    if (!opt.enablemouselockapi) {
    349439      cap.hasmousecapture = false;
    350440      cap.haspointerlock = false;
    351441    }
    352    
    353     this.delayed = function(name,fn,tm,lazy) {
    354       var dd = self.delaylist[name];
    355       var nw = (new Date()).getTime();
    356       if (!lazy&&dd&&dd.tt) return false;
    357       if (dd&&dd.tt) clearTimeout(dd.tt);
    358       if (dd&&dd.last+tm>nw&&!dd.tt) {     
     442
     443    this.debounced = function (name, fn, tm) {
     444      if (!self) return;
     445      var dd = self.delaylist[name] || false;
     446      if (!dd) {
    359447        self.delaylist[name] = {
    360           last:nw+tm,
    361           tt:setTimeout(function(){self.delaylist[name].tt=0;fn.call();},tm)
    362         }
    363       }
    364       else if (!dd||!dd.tt) {
    365         self.delaylist[name] = {
    366           last:nw,
    367           tt:0
    368         }
    369         setTimeout(function(){fn.call();},0);
    370       }
    371     };
    372    
    373     this.debounced = function(name,fn,tm) {
    374       var dd = self.delaylist[name];
    375       var nw = (new Date()).getTime();     
    376       self.delaylist[name] = fn;
    377       if (!dd) {       
    378         setTimeout(function(){var fn=self.delaylist[name];self.delaylist[name]=false;fn.call();},tm);
    379       }
    380     }
    381    
    382     this.synched = function(name,fn) {
    383    
    384       function requestSync() {
    385         if (self.onsync) return;
    386         setAnimationFrame(function(){
    387           self.onsync = false;
    388           for(name in self.synclist){
    389             var fn = self.synclist[name];
    390             if (fn) fn.call(self);
    391             self.synclist[name] = false;
    392           }
     448          h: setAnimationFrame(function () {
     449            self.delaylist[name].fn.call(self);
     450            self.delaylist[name] = false;
     451          }, tm)
     452        };
     453        fn.call(self);
     454      }
     455      self.delaylist[name].fn = fn;
     456    };
     457
     458
     459    this.synched = function (name, fn) {
     460      if (self.synclist[name]) self.synclist[name] = fn;
     461      else {
     462        self.synclist[name] = fn;
     463        setAnimationFrame(function () {
     464          if (!self) return;
     465          self.synclist[name] && self.synclist[name].call(self);
     466          self.synclist[name] = null;
    393467        });
    394         self.onsync = true;
    395       };   
    396    
    397       self.synclist[name] = fn;
    398       requestSync();
    399       return name;
    400     };
    401    
    402     this.unsynched = function(name) {
     468      }
     469    };
     470
     471    this.unsynched = function (name) {
    403472      if (self.synclist[name]) self.synclist[name] = false;
    404     }
    405    
    406     this.css = function(el,pars) {  // save & set
    407       for(var n in pars) {
    408         self.saved.css.push([el,n,el.css(n)]);
    409         el.css(n,pars[n]);
    410       }
    411     };
    412    
    413     this.scrollTop = function(val) {
    414       return (typeof val == "undefined") ? self.getScrollTop() : self.setScrollTop(val);
    415     };
    416 
    417     this.scrollLeft = function(val) {
    418       return (typeof val == "undefined") ? self.getScrollLeft() : self.setScrollLeft(val);
    419     };
    420    
    421 // derived by by Dan Pupius www.pupius.net
    422     BezierClass = function(st,ed,spd,p1,p2,p3,p4) {
     473    };
     474
     475    this.css = function (el, pars) { // save & set
     476      for (var n in pars) {
     477        self.saved.css.push([el, n, el.css(n)]);
     478        el.css(n, pars[n]);
     479      }
     480    };
     481
     482    this.scrollTop = function (val) {
     483      return (val === undefined) ? self.getScrollTop() : self.setScrollTop(val);
     484    };
     485
     486    this.scrollLeft = function (val) {
     487      return (val === undefined) ? self.getScrollLeft() : self.setScrollLeft(val);
     488    };
     489
     490    // derived by by Dan Pupius www.pupius.net
     491    var BezierClass = function (st, ed, spd, p1, p2, p3, p4) {
     492
    423493      this.st = st;
    424494      this.ed = ed;
    425495      this.spd = spd;
    426      
    427       this.p1 = p1||0;
    428       this.p2 = p2||1;
    429       this.p3 = p3||0;
    430       this.p4 = p4||1;
    431      
    432       this.ts = (new Date()).getTime();
    433       this.df = this.ed-this.st;
     496
     497      this.p1 = p1 || 0;
     498      this.p2 = p2 || 1;
     499      this.p3 = p3 || 0;
     500      this.p4 = p4 || 1;
     501
     502      this.ts = now();
     503      this.df = ed - st;
    434504    };
    435505    BezierClass.prototype = {
    436       B2:function(t){ return 3*t*t*(1-t) },
    437       B3:function(t){ return 3*t*(1-t)*(1-t) },
    438       B4:function(t){ return (1-t)*(1-t)*(1-t) },
    439       getNow:function(){
    440         var nw = (new Date()).getTime();
    441         var pc = 1-((nw-this.ts)/this.spd);
     506      B2: function (t) {
     507        return 3 * (1 - t) * (1 - t) * t;
     508      },
     509      B3: function (t) {
     510        return 3 * (1 - t) * t * t;
     511      },
     512      B4: function (t) {
     513        return t * t * t;
     514      },
     515      getPos: function () {
     516        return (now() - this.ts) / this.spd;
     517      },
     518      getNow: function () {
     519        var pc = (now() - this.ts) / this.spd;
    442520        var bz = this.B2(pc) + this.B3(pc) + this.B4(pc);
    443         return (pc<0) ? this.ed : this.st+Math.round(this.df*bz);
     521        return (pc >= 1) ? this.ed : this.st + (this.df * bz) | 0;
    444522      },
    445       update:function(ed,spd){
     523      update: function (ed, spd) {
    446524        this.st = this.getNow();
    447525        this.ed = ed;
    448526        this.spd = spd;
    449         this.ts = (new Date()).getTime();
    450         this.df = this.ed-this.st;
     527        this.ts = now();
     528        this.df = this.ed - this.st;
    451529        return this;
    452530      }
    453531    };
    454    
    455     if (this.ishwscroll) { 
    456     // hw accelerated scroll
    457       this.doc.translate = {x:0,y:0,tx:"0px",ty:"0px"};
    458      
     532
     533    //derived from http://stackoverflow.com/questions/11236090/
     534    function getMatrixValues() {
     535      var tr = self.doc.css(cap.trstyle);
     536      if (tr && (tr.substr(0, 6) == "matrix")) {
     537        return tr.replace(/^.*\((.*)\)$/g, "$1").replace(/px/g, '').split(/, +/);
     538      }
     539      return false;
     540    }
     541
     542    if (this.ishwscroll) {    // hw accelerated scroll
     543
     544      this.doc.translate = {
     545        x: 0,
     546        y: 0,
     547        tx: "0px",
     548        ty: "0px"
     549      };
     550
    459551      //this one can help to enable hw accel on ios6 http://indiegamr.com/ios6-html-hardware-acceleration-changes-and-how-to-fix-them/
    460       if (cap.hastranslate3d&&cap.isios) this.doc.css("-webkit-backface-visibility","hidden");  // prevent flickering http://stackoverflow.com/questions/3461441/     
    461      
    462       //derived from http://stackoverflow.com/questions/11236090/
    463       function getMatrixValues() {
    464         var tr = self.doc.css(cap.trstyle);
    465         if (tr&&(tr.substr(0,6)=="matrix")) {
    466           return tr.replace(/^.*\((.*)\)$/g, "$1").replace(/px/g,'').split(/, +/);
    467         }
    468         return false;
    469       }
    470      
    471       this.getScrollTop = function(last) {
     552      if (cap.hastranslate3d && cap.isios) this.doc.css("-webkit-backface-visibility", "hidden"); // prevent flickering http://stackoverflow.com/questions/3461441/     
     553
     554      this.getScrollTop = function (last) {
    472555        if (!last) {
    473556          var mtx = getMatrixValues();
    474           if (mtx) return (mtx.length==16) ? -mtx[13] : -mtx[5]; //matrix3d 16 on IE10
    475           if (self.timerscroll&&self.timerscroll.bz) return self.timerscroll.bz.getNow();
     557          if (mtx) return (mtx.length == 16) ? -mtx[13] : -mtx[5]; //matrix3d 16 on IE10
     558          if (self.timerscroll && self.timerscroll.bz) return self.timerscroll.bz.getNow();
    476559        }
    477560        return self.doc.translate.y;
    478561      };
    479562
    480       this.getScrollLeft = function(last) {
     563      this.getScrollLeft = function (last) {
    481564        if (!last) {
    482           var mtx = getMatrixValues();         
    483           if (mtx) return (mtx.length==16) ? -mtx[12] : -mtx[4]; //matrix3d 16 on IE10
    484           if (self.timerscroll&&self.timerscroll.bh) return self.timerscroll.bh.getNow();
     565          var mtx = getMatrixValues();
     566          if (mtx) return (mtx.length == 16) ? -mtx[12] : -mtx[4]; //matrix3d 16 on IE10
     567          if (self.timerscroll && self.timerscroll.bh) return self.timerscroll.bh.getNow();
    485568        }
    486569        return self.doc.translate.x;
    487570      };
    488      
    489       if (document.createEvent) {
    490         this.notifyScrollEvent = function(el) {
    491           var e = document.createEvent("UIEvents");
    492           e.initUIEvent("scroll", false, true, window, 1);
    493           el.dispatchEvent(e);
    494         };
    495       }
    496       else if (document.fireEvent) {
    497         this.notifyScrollEvent = function(el) {
    498           var e = document.createEventObject();
    499           el.fireEvent("onscroll");
    500           e.cancelBubble = true;
    501         };
    502       }
    503       else {
    504         this.notifyScrollEvent = function(el,add) {}; //NOPE
    505       }
    506      
    507       if (cap.hastranslate3d&&self.opt.enabletranslate3d) {
    508         this.setScrollTop = function(val,silent) {
     571
     572      this.notifyScrollEvent = function (el) {
     573        var e = _doc.createEvent("UIEvents");
     574        e.initUIEvent("scroll", false, false, _win, 1);
     575        e.niceevent = true;
     576        el.dispatchEvent(e);
     577      };
     578
     579      var cxscrollleft = (this.isrtlmode) ? 1 : -1;
     580
     581      if (cap.hastranslate3d && opt.enabletranslate3d) {
     582        this.setScrollTop = function (val, silent) {
    509583          self.doc.translate.y = val;
    510           self.doc.translate.ty = (val*-1)+"px";
    511           self.doc.css(cap.trstyle,"translate3d("+self.doc.translate.tx+","+self.doc.translate.ty+",0px)");         
     584          self.doc.translate.ty = (val * -1) + "px";
     585          self.doc.css(cap.trstyle, "translate3d(" + self.doc.translate.tx + "," + self.doc.translate.ty + ",0)");
    512586          if (!silent) self.notifyScrollEvent(self.win[0]);
    513587        };
    514         this.setScrollLeft = function(val,silent) {         
     588        this.setScrollLeft = function (val, silent) {
    515589          self.doc.translate.x = val;
    516           self.doc.translate.tx = (val*-1)+"px";
    517           self.doc.css(cap.trstyle,"translate3d("+self.doc.translate.tx+","+self.doc.translate.ty+",0px)");         
     590          self.doc.translate.tx = (val * cxscrollleft) + "px";
     591          self.doc.css(cap.trstyle, "translate3d(" + self.doc.translate.tx + "," + self.doc.translate.ty + ",0)");
    518592          if (!silent) self.notifyScrollEvent(self.win[0]);
    519593        };
    520594      } else {
    521         this.setScrollTop = function(val,silent) {
     595        this.setScrollTop = function (val, silent) {
    522596          self.doc.translate.y = val;
    523           self.doc.translate.ty = (val*-1)+"px";
    524           self.doc.css(cap.trstyle,"translate("+self.doc.translate.tx+","+self.doc.translate.ty+")");
    525           if (!silent) self.notifyScrollEvent(self.win[0]);         
    526         };
    527         this.setScrollLeft = function(val,silent) {       
    528           self.doc.translate.x = val;
    529           self.doc.translate.tx = (val*-1)+"px";
    530           self.doc.css(cap.trstyle,"translate("+self.doc.translate.tx+","+self.doc.translate.ty+")");
     597          self.doc.translate.ty = (val * -1) + "px";
     598          self.doc.css(cap.trstyle, "translate(" + self.doc.translate.tx + "," + self.doc.translate.ty + ")");
    531599          if (!silent) self.notifyScrollEvent(self.win[0]);
    532600        };
    533       }
    534     } else {
    535     // native scroll
    536       this.getScrollTop = function() {
     601        this.setScrollLeft = function (val, silent) {
     602          self.doc.translate.x = val;
     603          self.doc.translate.tx = (val * cxscrollleft) + "px";
     604          self.doc.css(cap.trstyle, "translate(" + self.doc.translate.tx + "," + self.doc.translate.ty + ")");
     605          if (!silent) self.notifyScrollEvent(self.win[0]);
     606        };
     607      }
     608    } else {    // native scroll
     609
     610      this.getScrollTop = function () {
    537611        return self.docscroll.scrollTop();
    538612      };
    539       this.setScrollTop = function(val) {       
    540         return self.docscroll.scrollTop(val);
     613      this.setScrollTop = function (val) {
     614        self.docscroll.scrollTop(val);
    541615      };
    542       this.getScrollLeft = function() {
    543         return self.docscroll.scrollLeft();
     616
     617      this.getScrollLeft = function () {
     618        var val;
     619        if (!self.hasreversehr) {
     620          val = self.docscroll.scrollLeft();
     621        } else if (self.detected.ismozilla) {
     622          val = self.page.maxw - Math.abs(self.docscroll.scrollLeft());
     623        } else {
     624          val = self.page.maxw - self.docscroll.scrollLeft();
     625        }
     626        return val;
    544627      };
    545       this.setScrollLeft = function(val) {
    546         return self.docscroll.scrollLeft(val);
     628      this.setScrollLeft = function (val) {
     629        return setTimeout(function () {
     630          if (!self) return;
     631          if (self.hasreversehr) {
     632            if (self.detected.ismozilla) {
     633              val = -(self.page.maxw - val);
     634            } else {
     635              val = self.page.maxw - val;
     636            }
     637          }
     638          return self.docscroll.scrollLeft(val);
     639        }, 1);
    547640      };
    548641    }
    549    
    550     this.getTarget = function(e) {
     642
     643    this.getTarget = function (e) {
    551644      if (!e) return false;
    552645      if (e.target) return e.target;
     
    554647      return false;
    555648    };
    556    
    557     this.hasParent = function(e,id) {
     649
     650    this.hasParent = function (e, id) {
    558651      if (!e) return false;
    559       var el = e.target||e.srcElement||e||false;
     652      var el = e.target || e.srcElement || e || false;
    560653      while (el && el.id != id) {
    561         el = el.parentNode||false;
    562       }
    563       return (el!==false);
    564     };
    565    
     654        el = el.parentNode || false;
     655      }
     656      return (el !== false);
     657    };
     658
    566659    function getZIndex() {
    567660      var dom = self.win;
    568       if ("zIndex" in dom) return dom.zIndex();  // use jQuery UI method when available
    569       while (dom.length>0) {       
    570         if (dom[0].nodeType==9) return false;
    571         var zi = dom.css('zIndex');       
    572         if (!isNaN(zi)&&zi!=0) return parseInt(zi);
     661      if ("zIndex" in dom) return dom.zIndex(); // use jQuery UI method when available
     662      while (dom.length > 0) {
     663        if (dom[0].nodeType == 9) return false;
     664        var zi = dom.css('zIndex');
     665        if (!isNaN(zi) && zi !== 0) return parseInt(zi);
    573666        dom = dom.parent();
    574667      }
    575668      return false;
    576     };
    577    
    578 //inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie
    579     var _convertBorderWidth = {"thin":1,"medium":3,"thick":5};
    580     function getWidthToPixel(dom,prop,chkheight) {
     669    }
     670
     671    //inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie
     672    var _convertBorderWidth = {
     673      "thin": 1,
     674      "medium": 3,
     675      "thick": 5
     676    };
     677
     678    function getWidthToPixel(dom, prop, chkheight) {
    581679      var wd = dom.css(prop);
    582680      var px = parseFloat(wd);
    583681      if (isNaN(px)) {
    584         px = _convertBorderWidth[wd]||0;
    585         var brd = (px==3) ? ((chkheight)?(self.win.outerHeight() - self.win.innerHeight()):(self.win.outerWidth() - self.win.innerWidth())) : 1; //DON'T TRUST CSS
    586         if (self.isie8&&px) px+=1;
    587         return (brd) ? px : 0; 
     682        px = _convertBorderWidth[wd] || 0;
     683        var brd = (px == 3) ? ((chkheight) ? (self.win.outerHeight() - self.win.innerHeight()) : (self.win.outerWidth() - self.win.innerWidth())) : 1; //DON'T TRUST CSS
     684        if (self.isie8 && px) px += 1;
     685        return (brd) ? px : 0;
    588686      }
    589687      return px;
    590     };
    591    
    592     this.getOffset = function() {
    593       if (self.isfixed) return {top:parseFloat(self.win.css('top')),left:parseFloat(self.win.css('left'))};
    594       if (!self.viewport) return self.win.offset();
     688    }
     689
     690    this.getDocumentScrollOffset = function () {
     691      return {
     692        top: _win.pageYOffset || _doc.documentElement.scrollTop,
     693        left: _win.pageXOffset || _doc.documentElement.scrollLeft
     694      };
     695    };
     696
     697    this.getOffset = function () {
     698      if (self.isfixed) {
     699        var ofs = self.win.offset();  // fix Chrome auto issue (when right/bottom props only)
     700        var scrl = self.getDocumentScrollOffset();
     701        ofs.top -= scrl.top;
     702        ofs.left -= scrl.left;
     703        return ofs;
     704      }
    595705      var ww = self.win.offset();
     706      if (!self.viewport) return ww;
    596707      var vp = self.viewport.offset();
    597       return {top:ww.top-vp.top+self.viewport.scrollTop(),left:ww.left-vp.left+self.viewport.scrollLeft()};
    598     };
    599    
    600     this.updateScrollBar = function(len) {
     708      return {
     709        top: ww.top - vp.top,
     710        left: ww.left - vp.left
     711      };
     712    };
     713
     714    this.updateScrollBar = function (len) {
     715      var pos, off;
    601716      if (self.ishwscroll) {
    602         self.rail.css({height:self.win.innerHeight()});
    603         if (self.railh) self.railh.css({width:self.win.innerWidth()});
     717        self.rail.css({
     718          height: self.win.innerHeight() - (opt.railpadding.top + opt.railpadding.bottom)
     719        });
     720        if (self.railh) self.railh.css({
     721          width: self.win.innerWidth() - (opt.railpadding.left + opt.railpadding.right)
     722        });
    604723      } else {
    605724        var wpos = self.getOffset();
    606         var pos = {top:wpos.top,left:wpos.left};
    607         pos.top+= getWidthToPixel(self.win,'border-top-width',true);
    608         var brd = (self.win.outerWidth() - self.win.innerWidth())/2;
    609         pos.left+= (self.rail.align) ? self.win.outerWidth() - getWidthToPixel(self.win,'border-right-width') - self.rail.width : getWidthToPixel(self.win,'border-left-width');
    610        
    611         var off = self.opt.railoffset;
     725        pos = {
     726          top: wpos.top,
     727          left: wpos.left - (opt.railpadding.left + opt.railpadding.right)
     728        };
     729        pos.top += getWidthToPixel(self.win, 'border-top-width', true);
     730        pos.left += (self.rail.align) ? self.win.outerWidth() - getWidthToPixel(self.win, 'border-right-width') - self.rail.width : getWidthToPixel(self.win, 'border-left-width');
     731
     732        off = opt.railoffset;
    612733        if (off) {
    613           if (off.top) pos.top+=off.top;
    614           if (self.rail.align&&off.left) pos.left+=off.left;
    615         }
    616        
    617                 if (!self.locked) self.rail.css({top:pos.top,left:pos.left,height:(len)?len.h:self.win.innerHeight()});
    618                
    619                 if (self.zoom) {                 
    620                   self.zoom.css({top:pos.top+1,left:(self.rail.align==1) ? pos.left-20 : pos.left+self.rail.width+4});
    621               }
    622                
    623                 if (self.railh&&!self.locked) {
    624                     var pos = {top:wpos.top,left:wpos.left};
    625                     var y = (self.railh.align) ? pos.top + getWidthToPixel(self.win,'border-top-width',true) + self.win.innerHeight() - self.railh.height : pos.top + getWidthToPixel(self.win,'border-top-width',true);
    626                     var x = pos.left + getWidthToPixel(self.win,'border-left-width');
    627                     self.railh.css({top:y,left:x,width:self.railh.width});
    628                 }
    629        
    630                
    631       }
    632     };
    633    
    634     this.doRailClick = function(e,dbl,hr) {
    635 
    636       var fn,pg,cur,pos;
    637      
    638 //      if (self.rail.drag&&self.rail.drag.pt!=1) return;
    639       if (self.locked) return;
    640 //      if (self.rail.drag) return;
    641 
    642 //      self.cancelScroll();       
    643      
     734          if (off.top) pos.top += off.top;
     735          if (off.left) pos.left += off.left;
     736        }
     737
     738        if (!self.railslocked) self.rail.css({
     739          top: pos.top,
     740          left: pos.left,
     741          height: ((len) ? len.h : self.win.innerHeight()) - (opt.railpadding.top + opt.railpadding.bottom)
     742        });
     743
     744        if (self.zoom) {
     745          self.zoom.css({
     746            top: pos.top + 1,
     747            left: (self.rail.align == 1) ? pos.left - 20 : pos.left + self.rail.width + 4
     748          });
     749        }
     750
     751        if (self.railh && !self.railslocked) {
     752          pos = {
     753            top: wpos.top,
     754            left: wpos.left
     755          };
     756          off = opt.railhoffset;
     757          if (off) {
     758            if (off.top) pos.top += off.top;
     759            if (off.left) pos.left += off.left;
     760          }
     761          var y = (self.railh.align) ? pos.top + getWidthToPixel(self.win, 'border-top-width', true) + self.win.innerHeight() - self.railh.height : pos.top + getWidthToPixel(self.win, 'border-top-width', true);
     762          var x = pos.left + getWidthToPixel(self.win, 'border-left-width');
     763          self.railh.css({
     764            top: y - (opt.railpadding.top + opt.railpadding.bottom),
     765            left: x,
     766            width: self.railh.width
     767          });
     768        }
     769
     770      }
     771    };
     772
     773    this.doRailClick = function (e, dbl, hr) {
     774      var fn, pg, cur, pos;
     775
     776      if (self.railslocked) return;
     777
    644778      self.cancelEvent(e);
    645      
     779
     780      if (!("pageY" in e)) {
     781        e.pageX = e.clientX + _doc.documentElement.scrollLeft;
     782        e.pageY = e.clientY + _doc.documentElement.scrollTop;
     783      }
     784
    646785      if (dbl) {
    647786        fn = (hr) ? self.doScrollLeft : self.doScrollTop;
    648         cur = (hr) ? ((e.pageX - self.railh.offset().left - (self.cursorwidth/2)) * self.scrollratio.x) : ((e.pageY - self.rail.offset().top - (self.cursorheight/2)) * self.scrollratio.y);
    649         fn(cur);
     787        cur = (hr) ? ((e.pageX - self.railh.offset().left - (self.cursorwidth / 2)) * self.scrollratio.x) : ((e.pageY - self.rail.offset().top - (self.cursorheight / 2)) * self.scrollratio.y);
     788        self.unsynched("relativexy");
     789        fn(cur|0);
    650790      } else {
    651 //        console.log(e.pageY);
    652791        fn = (hr) ? self.doScrollLeftBy : self.doScrollBy;
    653792        cur = (hr) ? self.scroll.x : self.scroll.y;
    654793        pos = (hr) ? e.pageX - self.railh.offset().left : e.pageY - self.rail.offset().top;
    655         pg = (hr) ? self.view.w : self.view.h;       
    656         (cur>=pos) ? fn(pg) : fn(-pg);
    657       }
    658    
    659     }
    660    
    661     self.hasanimationframe = (setAnimationFrame);
    662     self.hascancelanimationframe = (clearAnimationFrame);
    663    
    664     if (!self.hasanimationframe) {
    665       setAnimationFrame=function(fn){return setTimeout(fn,15-Math.floor((+new Date)/1000)%16)}; // 1000/60)};
    666       clearAnimationFrame=clearInterval;
    667     }
    668     else if (!self.hascancelanimationframe) clearAnimationFrame=function(){self.cancelAnimationFrame=true};
    669    
    670     this.init = function() {
     794        pg = (hr) ? self.view.w : self.view.h;
     795        fn((cur >= pos) ? pg : -pg);
     796      }
     797
     798    };
     799
     800    self.newscrolly = self.newscrollx = 0;
     801
     802    self.hasanimationframe = ("requestAnimationFrame" in _win);
     803    self.hascancelanimationframe = ("cancelAnimationFrame" in _win);
     804
     805    self.hasborderbox = false;
     806
     807    this.init = function () {
    671808
    672809      self.saved.css = [];
    673      
    674       if (cap.isie7mobile) return true; // SORRY, DO NOT WORK!
    675      
    676       if (cap.hasmstouch) self.css((self.ispage)?$("html"):self.win,{'-ms-touch-action':'none'});
    677      
     810
     811      if (cap.isoperamini) return true; // SORRY, DO NOT WORK!
     812      if (cap.isandroid && !("hidden" in _doc)) return true; // Android 3- SORRY, DO NOT WORK!
     813
     814      opt.emulatetouch = opt.emulatetouch || opt.touchbehavior;  // mantain compatibility with "touchbehavior"     
     815
     816      self.hasborderbox = _win.getComputedStyle && (_win.getComputedStyle(_doc.body)['box-sizing'] === "border-box");
     817
     818      var _scrollyhidden = { 'overflow-y': 'hidden' };
     819      if (cap.isie11 || cap.isie10) _scrollyhidden['-ms-overflow-style'] = 'none';  // IE 10 & 11 is always a world apart!
     820
     821      if (self.ishwscroll) {
     822        this.doc.css(cap.transitionstyle, cap.prefixstyle + 'transform 0ms ease-out');
     823        if (cap.transitionend) self.bind(self.doc, cap.transitionend, self.onScrollTransitionEnd, false); //I have got to do something usefull!!
     824      }
     825
    678826      self.zindex = "auto";
    679       if (!self.ispage&&self.opt.zindex=="auto") {
    680         self.zindex = getZIndex()||"auto";
     827      if (!self.ispage && opt.zindex == "auto") {
     828        self.zindex = getZIndex() || "auto";
    681829      } else {
    682         self.zindex = self.opt.zindex;
    683       }
    684      
    685       if (!self.ispage&&self.zindex!="auto") {
    686         if (self.zindex>globalmaxzindex) globalmaxzindex=self.zindex;
    687       }
    688      
    689       if (self.isie&&self.zindex==0&&self.opt.zindex=="auto") {  // fix IE auto == 0
    690         self.zindex="auto";
    691       }
    692      
    693 /*     
    694       self.ispage = true;
    695       self.haswrapper = true;
    696 //      self.win = $(window);
    697       self.docscroll = $("body");
    698 //      self.doc = $("body");
    699 */
    700      
    701       if (!self.ispage || (!cap.cantouch && !cap.isieold && !cap.isie9mobile)) {
    702      
     830        self.zindex = opt.zindex;
     831      }
     832
     833      if (!self.ispage && self.zindex != "auto" && self.zindex > globalmaxzindex) {
     834        globalmaxzindex = self.zindex;
     835      }
     836
     837      if (self.isie && self.zindex === 0 && opt.zindex == "auto") { // fix IE auto == 0
     838        self.zindex = "auto";
     839      }
     840
     841      if (!self.ispage || !cap.isieold) {
     842
    703843        var cont = self.docscroll;
    704         if (self.ispage) cont = (self.haswrapper)?self.win:self.doc;
    705        
    706         if (!cap.isie9mobile) self.css(cont,{'overflow-y':'hidden'});     
    707        
    708         if (self.ispage&&cap.isie7) {
    709           if (self.doc[0].nodeName=='BODY') self.css($("html"),{'overflow-y':'hidden'});  //IE7 double scrollbar issue
    710           else if (self.doc[0].nodeName=='HTML') self.css($("body"),{'overflow-y':'hidden'});  //IE7 double scrollbar issue
    711         }
    712        
    713         if (cap.isios&&!self.ispage&&!self.haswrapper) self.css($("body"),{"-webkit-overflow-scrolling":"touch"});  //force hw acceleration
    714        
    715         var cursor = $(document.createElement('div'));
     844        if (self.ispage) cont = (self.haswrapper) ? self.win : self.doc;
     845
     846        self.css(cont, _scrollyhidden);
     847
     848        if (self.ispage && (cap.isie11 || cap.isie)) { // IE 7-11
     849          self.css($("html"), _scrollyhidden);
     850        }
     851
     852        if (cap.isios && !self.ispage && !self.haswrapper) self.css($body, {
     853          "-webkit-overflow-scrolling": "touch"
     854        }); //force hw acceleration
     855
     856        var cursor = $(_doc.createElement('div'));
    716857        cursor.css({
    717           position:"relative",top:0,"float":"right",width:self.opt.cursorwidth,height:"0px",
    718           'background-color':self.opt.cursorcolor,
    719           border:self.opt.cursorborder,
    720           'background-clip':'padding-box',
    721           '-webkit-border-radius':self.opt.cursorborderradius,
    722           '-moz-border-radius':self.opt.cursorborderradius,
    723           'border-radius':self.opt.cursorborderradius
    724         });   
    725        
    726         cursor.hborder = parseFloat(cursor.outerHeight() - cursor.innerHeight());       
    727         self.cursor = cursor;       
    728        
    729         var rail = $(document.createElement('div'));
    730         rail.attr('id',self.id);
    731         rail.addClass('nicescroll-rails');
    732        
    733         var v,a,kp = ["left","right"];  //"top","bottom"
    734         for(var n in kp) {
    735           a=kp[n];
    736           v = self.opt.railpadding[a];
    737           (v) ? rail.css("padding-"+a,v+"px") : self.opt.railpadding[a] = 0;
    738         }
    739        
     858          position: "relative",
     859          top: 0,
     860          "float": "right",
     861          width: opt.cursorwidth,
     862          height: 0,
     863          'background-color': opt.cursorcolor,
     864          border: opt.cursorborder,
     865          'background-clip': 'padding-box',
     866          '-webkit-border-radius': opt.cursorborderradius,
     867          '-moz-border-radius': opt.cursorborderradius,
     868          'border-radius': opt.cursorborderradius
     869        });
     870
     871        cursor.addClass('nicescroll-cursors');
     872
     873        self.cursor = cursor;
     874
     875        var rail = $(_doc.createElement('div'));
     876        rail.attr('id', self.id);
     877        rail.addClass('nicescroll-rails nicescroll-rails-vr');
     878
     879        var v, a, kp = ["left", "right", "top", "bottom"];  //**
     880        for (var n in kp) {
     881          a = kp[n];
     882          v = opt.railpadding[a] || 0;
     883          v && rail.css("padding-" + a, v + "px");
     884        }
     885
    740886        rail.append(cursor);
    741        
    742         rail.width = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerWidth()) + self.opt.railpadding['left'] + self.opt.railpadding['right'];
    743         rail.css({width:rail.width+"px",'zIndex':self.zindex,"background":self.opt.background,cursor:"default"});       
    744        
     887
     888        rail.width = Math.max(parseFloat(opt.cursorwidth), cursor.outerWidth());
     889        rail.css({
     890          width: rail.width + "px",
     891          zIndex: self.zindex,
     892          background: opt.background,
     893          cursor: "default"
     894        });
     895
    745896        rail.visibility = true;
    746897        rail.scrollable = true;
    747        
    748         rail.align = (self.opt.railalign=="left") ? 0 : 1;
    749        
     898
     899        rail.align = (opt.railalign == "left") ? 0 : 1;
     900
    750901        self.rail = rail;
    751        
     902
    752903        self.rail.drag = false;
    753        
     904
    754905        var zoom = false;
    755         if (self.opt.boxzoom&&!self.ispage&&!cap.isieold) {
    756           zoom = document.createElement('div');         
    757           self.bind(zoom,"click",self.doZoom);
     906        if (opt.boxzoom && !self.ispage && !cap.isieold) {
     907          zoom = _doc.createElement('div');
     908
     909          self.bind(zoom, "click", self.doZoom);
     910          self.bind(zoom, "mouseenter", function () {
     911            self.zoom.css('opacity', opt.cursoropacitymax);
     912          });
     913          self.bind(zoom, "mouseleave", function () {
     914            self.zoom.css('opacity', opt.cursoropacitymin);
     915          });
     916
    758917          self.zoom = $(zoom);
    759           self.zoom.css({"cursor":"pointer",'z-index':self.zindex,'backgroundImage':'url('+scriptpath+'zoomico.png)','height':18,'width':18,'backgroundPosition':'0px 0px'});
    760           if (self.opt.dblclickzoom) self.bind(self.win,"dblclick",self.doZoom);
    761           if (cap.cantouch&&self.opt.gesturezoom) {
    762             self.ongesturezoom = function(e) {
    763               if (e.scale>1.5) self.doZoomIn(e);
    764               if (e.scale<0.8) self.doZoomOut(e);
     918          self.zoom.css({
     919            cursor: "pointer",
     920            zIndex: self.zindex,
     921            backgroundImage: 'url(' + opt.scriptpath + 'zoomico.png)',
     922            height: 18,
     923            width: 18,
     924            backgroundPosition: '0 0'
     925          });
     926          if (opt.dblclickzoom) self.bind(self.win, "dblclick", self.doZoom);
     927          if (cap.cantouch && opt.gesturezoom) {
     928            self.ongesturezoom = function (e) {
     929              if (e.scale > 1.5) self.doZoomIn(e);
     930              if (e.scale < 0.8) self.doZoomOut(e);
    765931              return self.cancelEvent(e);
    766932            };
    767             self.bind(self.win,"gestureend",self.ongesturezoom);             
    768           }
    769         }
    770        
    771 // init HORIZ
     933            self.bind(self.win, "gestureend", self.ongesturezoom);
     934          }
     935        }
     936
     937        // init HORIZ
    772938
    773939        self.railh = false;
    774 
    775         if (self.opt.horizrailenabled) {
    776 
    777           self.css(cont,{'overflow-x':'hidden'});
    778 
    779           var cursor = $(document.createElement('div'));
     940        var railh;
     941
     942        if (opt.horizrailenabled) {
     943
     944          self.css(cont, {
     945            overflowX: 'hidden'
     946          });
     947
     948          cursor = $(_doc.createElement('div'));
    780949          cursor.css({
    781             position:"relative",top:0,height:self.opt.cursorwidth,width:"0px",
    782             'background-color':self.opt.cursorcolor,
    783             border:self.opt.cursorborder,
    784             'background-clip':'padding-box',
    785             '-webkit-border-radius':self.opt.cursorborderradius,
    786             '-moz-border-radius':self.opt.cursorborderradius,
    787             'border-radius':self.opt.cursorborderradius
    788           });   
    789          
    790           cursor.wborder = parseFloat(cursor.outerWidth() - cursor.innerWidth());
     950            position: "absolute",
     951            top: 0,
     952            height: opt.cursorwidth,
     953            width: 0,
     954            backgroundColor: opt.cursorcolor,
     955            border: opt.cursorborder,
     956            backgroundClip: 'padding-box',
     957            '-webkit-border-radius': opt.cursorborderradius,
     958            '-moz-border-radius': opt.cursorborderradius,
     959            'border-radius': opt.cursorborderradius
     960          });
     961
     962          if (cap.isieold) cursor.css('overflow', 'hidden');  //IE6 horiz scrollbar issue
     963
     964          cursor.addClass('nicescroll-cursors');
     965
    791966          self.cursorh = cursor;
    792          
    793           var railh = $(document.createElement('div'));
    794           railh.attr('id',self.id+'-hr');
    795           railh.addClass('nicescroll-rails');
    796           railh.height = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerHeight());
    797           railh.css({height:railh.height+"px",'zIndex':self.zindex,"background":self.opt.background});
    798          
     967
     968          railh = $(_doc.createElement('div'));
     969          railh.attr('id', self.id + '-hr');
     970          railh.addClass('nicescroll-rails nicescroll-rails-hr');
     971          railh.height = Math.max(parseFloat(opt.cursorwidth), cursor.outerHeight());
     972          railh.css({
     973            height: railh.height + "px",
     974            'zIndex': self.zindex,
     975            "background": opt.background
     976          });
     977
    799978          railh.append(cursor);
    800          
     979
    801980          railh.visibility = true;
    802981          railh.scrollable = true;
    803          
    804           railh.align = (self.opt.railvalign=="top") ? 0 : 1;
    805          
     982
     983          railh.align = (opt.railvalign == "top") ? 0 : 1;
     984
    806985          self.railh = railh;
    807          
     986
    808987          self.railh.drag = false;
    809          
    810         }
    811        
    812 //       
    813        
     988
     989        }
     990
    814991        if (self.ispage) {
    815           rail.css({position:"fixed",top:"0px",height:"100%"});
    816           (rail.align) ? rail.css({right:"0px"}) : rail.css({left:"0px"});
     992
     993          rail.css({
     994            position: "fixed",
     995            top: 0,
     996            height: "100%"
     997          });
     998
     999          rail.css((rail.align) ? { right: 0 } : { left: 0 });
     1000
    8171001          self.body.append(rail);
    8181002          if (self.railh) {
    819             railh.css({position:"fixed",left:"0px",width:"100%"});
    820             (railh.align) ? railh.css({bottom:"0px"}) : railh.css({top:"0px"});
     1003            railh.css({
     1004              position: "fixed",
     1005              left: 0,
     1006              width: "100%"
     1007            });
     1008
     1009            railh.css((railh.align) ? { bottom: 0 } : { top: 0 });
     1010
    8211011            self.body.append(railh);
    8221012          }
    823         } else {         
     1013        } else {
    8241014          if (self.ishwscroll) {
    825             if (self.win.css('position')=='static') self.css(self.win,{'position':'relative'});
     1015            if (self.win.css('position') == 'static') self.css(self.win, { 'position': 'relative' });
    8261016            var bd = (self.win[0].nodeName == 'HTML') ? self.body : self.win;
     1017            $(bd).scrollTop(0).scrollLeft(0);  // fix rail position if content already scrolled
    8271018            if (self.zoom) {
    828               self.zoom.css({position:"absolute",top:1,right:0,"margin-right":rail.width+4});
     1019              self.zoom.css({
     1020                position: "absolute",
     1021                top: 1,
     1022                right: 0,
     1023                "margin-right": rail.width + 4
     1024              });
    8291025              bd.append(self.zoom);
    8301026            }
    831             rail.css({position:"absolute",top:0});
    832             (rail.align) ? rail.css({right:0}) : rail.css({left:0});
     1027            rail.css({
     1028              position: "absolute",
     1029              top: 0
     1030            });
     1031            rail.css((rail.align) ? { right: 0 } : { left: 0 });
    8331032            bd.append(rail);
    8341033            if (railh) {
    835               railh.css({position:"absolute",left:0,bottom:0});
    836               (railh.align) ? railh.css({bottom:0}) : railh.css({top:0});
     1034              railh.css({
     1035                position: "absolute",
     1036                left: 0,
     1037                bottom: 0
     1038              });
     1039              railh.css((railh.align) ? { bottom: 0 } : { top: 0 });
    8371040              bd.append(railh);
    8381041            }
    8391042          } else {
    840             self.isfixed = (self.win.css("position")=="fixed");
     1043            self.isfixed = (self.win.css("position") == "fixed");
    8411044            var rlpos = (self.isfixed) ? "fixed" : "absolute";
    842            
     1045
    8431046            if (!self.isfixed) self.viewport = self.getViewport(self.win[0]);
    8441047            if (self.viewport) {
    845               self.body = self.viewport;             
    846               if ((/relative|absolute/.test(self.viewport.css("position")))==false) self.css(self.viewport,{"position":"relative"});
    847             }           
    848            
    849             rail.css({position:rlpos});
    850             if (self.zoom) self.zoom.css({position:rlpos});
     1048              self.body = self.viewport;
     1049              if (!(/fixed|absolute/.test(self.viewport.css("position")))) self.css(self.viewport, {
     1050                "position": "relative"
     1051              });
     1052            }
     1053
     1054            rail.css({
     1055              position: rlpos
     1056            });
     1057            if (self.zoom) self.zoom.css({
     1058              position: rlpos
     1059            });
    8511060            self.updateScrollBar();
    8521061            self.body.append(rail);
    8531062            if (self.zoom) self.body.append(self.zoom);
    8541063            if (self.railh) {
    855               railh.css({position:rlpos});
    856               self.body.append(railh);           
     1064              railh.css({
     1065                position: rlpos
     1066              });
     1067              self.body.append(railh);
    8571068            }
    8581069          }
    859          
    860           if (cap.isios) self.css(self.win,{'-webkit-tap-highlight-color':'rgba(0,0,0,0)','-webkit-touch-callout':'none'});  // prevent grey layer on click
    861          
    862                     if (cap.isie&&self.opt.disableoutline) self.win.attr("hideFocus","true");  // IE, prevent dotted rectangle on focused div
    863                     if (cap.iswebkit&&self.opt.disableoutline) self.win.css({"outline":"none"});
    864          
    865         }
    866        
    867         if (self.opt.autohidemode===false) {
     1070
     1071          if (cap.isios) self.css(self.win, {
     1072            '-webkit-tap-highlight-color': 'rgba(0,0,0,0)',
     1073            '-webkit-touch-callout': 'none'
     1074          }); // prevent grey layer on click
     1075
     1076          if (opt.disableoutline) {
     1077            if (cap.isie) self.win.attr("hideFocus", "true"); // IE, prevent dotted rectangle on focused div
     1078            if (cap.iswebkit) self.win.css('outline', 'none');  // Webkit outline
     1079          }
     1080
     1081        }
     1082
     1083        if (opt.autohidemode === false) {
    8681084          self.autohidedom = false;
    869           self.rail.css({opacity:self.opt.cursoropacitymax});         
    870           if (self.railh) self.railh.css({opacity:self.opt.cursoropacitymax});
    871         }
    872         else if (self.opt.autohidemode===true) {
    873           self.autohidedom = $().add(self.rail);         
    874           if (cap.isie8) self.autohidedom=self.autohidedom.add(self.cursor);
    875           if (self.railh) self.autohidedom=self.autohidedom.add(self.railh);
    876           if (self.railh&&cap.isie8) self.autohidedom=self.autohidedom.add(self.cursorh);
    877         }
    878         else if (self.opt.autohidemode=="scroll") {
     1085          self.rail.css({
     1086            opacity: opt.cursoropacitymax
     1087          });
     1088          if (self.railh) self.railh.css({
     1089            opacity: opt.cursoropacitymax
     1090          });
     1091        } else if ((opt.autohidemode === true) || (opt.autohidemode === "leave")) {
    8791092          self.autohidedom = $().add(self.rail);
    880           if (self.railh) self.autohidedom=self.autohidedom.add(self.railh);
    881         }
    882         else if (self.opt.autohidemode=="cursor") {
     1093          if (cap.isie8) self.autohidedom = self.autohidedom.add(self.cursor);
     1094          if (self.railh) self.autohidedom = self.autohidedom.add(self.railh);
     1095          if (self.railh && cap.isie8) self.autohidedom = self.autohidedom.add(self.cursorh);
     1096        } else if (opt.autohidemode == "scroll") {
     1097          self.autohidedom = $().add(self.rail);
     1098          if (self.railh) self.autohidedom = self.autohidedom.add(self.railh);
     1099        } else if (opt.autohidemode == "cursor") {
    8831100          self.autohidedom = $().add(self.cursor);
    884           if (self.railh) self.autohidedom=self.autohidedom.add(self.cursorh);
    885         }
    886         else if (self.opt.autohidemode=="hidden") {
     1101          if (self.railh) self.autohidedom = self.autohidedom.add(self.cursorh);
     1102        } else if (opt.autohidemode == "hidden") {
    8871103          self.autohidedom = false;
    8881104          self.hide();
    889           self.locked = false;
    890         }
    891        
    892         if (cap.isie9mobile) {
    893 
    894           self.scrollmom = new ScrollMomentumClass2D(self);       
    895 
    896           /*
    897           var trace = function(msg) {
    898             var db = $("#debug");
    899             if (isNaN(msg)&&(typeof msg != "string")) {
    900               var x = [];
    901               for(var a in msg) {
    902                 x.push(a+":"+msg[a]);
     1105          self.railslocked = false;
     1106        }
     1107
     1108        if (cap.cantouch || self.istouchcapable || opt.emulatetouch || cap.hasmstouch) {
     1109
     1110          self.scrollmom = new ScrollMomentumClass2D(self);
     1111
     1112          var delayedclick = null;
     1113
     1114          self.ontouchstart = function (e) {
     1115
     1116            if (self.locked) return false;
     1117
     1118            //if (e.pointerType && e.pointerType != 2 && e.pointerType != "touch") return false;
     1119            if (e.pointerType && (e.pointerType === 'mouse' || e.pointerType === e.MSPOINTER_TYPE_MOUSE)) return false;  // need test on surface!!
     1120
     1121            self.hasmoving = false;
     1122
     1123            if (self.scrollmom.timer) {
     1124              self.triggerScrollEnd();
     1125              self.scrollmom.stop();
     1126            }
     1127
     1128            if (!self.railslocked) {
     1129              var tg = self.getTarget(e);
     1130
     1131              if (tg) {
     1132                var skp = (/INPUT/i.test(tg.nodeName)) && (/range/i.test(tg.type));
     1133                if (skp) return self.stopPropagation(e);
    9031134              }
    904               msg ="{"+x.join(",")+"}";
    905             }
    906             if (db.children().length>0) {
    907               db.children().eq(0).before("<div>"+msg+"</div>");
    908             } else {
    909               db.append("<div>"+msg+"</div>");
    910             }
    911           }
    912           window.onerror = function(msg,url,ln) {
    913             trace("ERR: "+msg+" at "+ln);
    914           }
    915 */         
    916  
    917           self.onmangotouch = function(e) {
    918             var py = self.getScrollTop();
    919             var px = self.getScrollLeft();
    920            
    921             if ((py == self.scrollmom.lastscrolly)&&(px == self.scrollmom.lastscrollx)) return true;
    922 //            $("#debug").html('DRAG:'+py);
    923 
    924             var dfy = py-self.mangotouch.sy;
    925             var dfx = px-self.mangotouch.sx;           
    926             var df = Math.round(Math.sqrt(Math.pow(dfx,2)+Math.pow(dfy,2)));           
    927             if (df==0) return;
    928            
    929             var dry = (dfy<0)?-1:1;
    930             var drx = (dfx<0)?-1:1;
    931            
    932             var tm = +new Date();
    933             if (self.mangotouch.lazy) clearTimeout(self.mangotouch.lazy);
    934            
    935             if (((tm-self.mangotouch.tm)>80)||(self.mangotouch.dry!=dry)||(self.mangotouch.drx!=drx)) {
    936 //              trace('RESET+'+(tm-self.mangotouch.tm));
    937               self.scrollmom.stop();
    938               self.scrollmom.reset(px,py);
    939               self.mangotouch.sy = py;
    940               self.mangotouch.ly = py;
    941               self.mangotouch.sx = px;
    942               self.mangotouch.lx = px;
    943               self.mangotouch.dry = dry;
    944               self.mangotouch.drx = drx;
    945               self.mangotouch.tm = tm;
    946             } else {
    947              
    948               self.scrollmom.stop();
    949               self.scrollmom.update(self.mangotouch.sx-dfx,self.mangotouch.sy-dfy);
    950               var gap = tm - self.mangotouch.tm;             
    951               self.mangotouch.tm = tm;
    952              
    953 //              trace('MOVE:'+df+" - "+gap);
    954              
    955               var ds = Math.max(Math.abs(self.mangotouch.ly-py),Math.abs(self.mangotouch.lx-px));
    956               self.mangotouch.ly = py;
    957               self.mangotouch.lx = px;
    958              
    959               if (ds>2) {
    960                 self.mangotouch.lazy = setTimeout(function(){
    961 //                  trace('END:'+ds+'+'+gap);                 
    962                   self.mangotouch.lazy = false;
    963                   self.mangotouch.dry = 0;
    964                   self.mangotouch.drx = 0;
    965                   self.mangotouch.tm = 0;                 
    966                   self.scrollmom.doMomentum(30);
    967                 },100);
     1135
     1136              var ismouse = (e.type === "mousedown");
     1137
     1138              if (!("clientX" in e) && ("changedTouches" in e)) {
     1139                e.clientX = e.changedTouches[0].clientX;
     1140                e.clientY = e.changedTouches[0].clientY;
     1141              }
     1142
     1143              if (self.forcescreen) {
     1144                var le = e;
     1145                e = {
     1146                  "original": (e.original) ? e.original : e
     1147                };
     1148                e.clientX = le.screenX;
     1149                e.clientY = le.screenY;
     1150              }
     1151
     1152              self.rail.drag = {
     1153                x: e.clientX,
     1154                y: e.clientY,
     1155                sx: self.scroll.x,
     1156                sy: self.scroll.y,
     1157                st: self.getScrollTop(),
     1158                sl: self.getScrollLeft(),
     1159                pt: 2,
     1160                dl: false,
     1161                tg: tg
     1162              };
     1163
     1164              if (self.ispage || !opt.directionlockdeadzone) {
     1165
     1166                self.rail.drag.dl = "f";
     1167
     1168              } else {
     1169
     1170                var view = {
     1171                  w: $window.width(),
     1172                  h: $window.height()
     1173                };
     1174
     1175                var page = self.getContentSize();
     1176
     1177                var maxh = page.h - view.h;
     1178                var maxw = page.w - view.w;
     1179
     1180                if (self.rail.scrollable && !self.railh.scrollable) self.rail.drag.ck = (maxh > 0) ? "v" : false;
     1181                else if (!self.rail.scrollable && self.railh.scrollable) self.rail.drag.ck = (maxw > 0) ? "h" : false;
     1182                else self.rail.drag.ck = false;
     1183
     1184              }
     1185
     1186              if (opt.emulatetouch && self.isiframe && cap.isie) {
     1187                var wp = self.win.position();
     1188                self.rail.drag.x += wp.left;
     1189                self.rail.drag.y += wp.top;
     1190              }
     1191
     1192              self.hasmoving = false;
     1193              self.lastmouseup = false;
     1194              self.scrollmom.reset(e.clientX, e.clientY);
     1195
     1196              if (tg&&ismouse) {
     1197
     1198                var ip = /INPUT|SELECT|BUTTON|TEXTAREA/i.test(tg.nodeName);
     1199                if (!ip) {
     1200                  if (cap.hasmousecapture) tg.setCapture();
     1201                  if (opt.emulatetouch) {
     1202                    if (tg.onclick && !(tg._onclick || false)) { // intercept DOM0 onclick event
     1203                      tg._onclick = tg.onclick;
     1204                      tg.onclick = function (e) {
     1205                        if (self.hasmoving) return false;
     1206                        tg._onclick.call(this, e);
     1207                      };
     1208                    }
     1209                    return self.cancelEvent(e);
     1210                  }
     1211                  return self.stopPropagation(e);
     1212                }
     1213
     1214                if (/SUBMIT|CANCEL|BUTTON/i.test($(tg).attr('type'))) {
     1215                  self.preventclick = {
     1216                    "tg": tg,
     1217                    "click": false
     1218                  };
     1219                }
     1220
    9681221              }
    9691222            }
    970           }
    971          
    972           var top = self.getScrollTop();
    973           var lef = self.getScrollLeft();
    974           self.mangotouch = {sy:top,ly:top,dry:0,sx:lef,lx:lef,drx:0,lazy:false,tm:0};
    975          
    976           self.bind(self.docscroll,"scroll",self.onmangotouch);
    977        
    978         } else {
    979        
    980           if (cap.cantouch||self.istouchcapable||self.opt.touchbehavior||cap.hasmstouch) {
    981          
    982             self.scrollmom = new ScrollMomentumClass2D(self);
    983          
    984             self.ontouchstart = function(e) {
    985               if (e.pointerType&&e.pointerType!=2) return false;
    986              
    987               if (!self.locked) {
    988              
    989                 if (cap.hasmstouch) {
    990                   var tg = (e.target) ? e.target : false;
    991                   while (tg) {
    992                     var nc = $(tg).getNiceScroll();
    993                     if ((nc.length>0)&&(nc[0].me == self.me)) break;
    994                     if (nc.length>0) return false;
    995                     if ((tg.nodeName=='DIV')&&(tg.id==self.id)) break;
    996                     tg = (tg.parentNode) ? tg.parentNode : false;
     1223
     1224          };
     1225
     1226          self.ontouchend = function (e) {
     1227
     1228            if (!self.rail.drag) return true;
     1229
     1230            if (self.rail.drag.pt == 2) {
     1231              //if (e.pointerType && e.pointerType != 2 && e.pointerType != "touch") return false;
     1232              if (e.pointerType && (e.pointerType === 'mouse' || e.pointerType === e.MSPOINTER_TYPE_MOUSE)) return false;
     1233
     1234              self.rail.drag = false;
     1235
     1236              var ismouse = (e.type === "mouseup");
     1237
     1238              if (self.hasmoving) {
     1239                self.scrollmom.doMomentum();
     1240                self.lastmouseup = true;
     1241                self.hideCursor();
     1242                if (cap.hasmousecapture) _doc.releaseCapture();
     1243                if (ismouse) return self.cancelEvent(e);
     1244              }
     1245
     1246            }
     1247            else if (self.rail.drag.pt == 1) {
     1248              return self.onmouseup(e);
     1249            }
     1250
     1251          };
     1252
     1253          var moveneedoffset = (opt.emulatetouch && self.isiframe && !cap.hasmousecapture);
     1254
     1255          var locktollerance = opt.directionlockdeadzone * 0.3 | 0;
     1256
     1257          self.ontouchmove = function (e, byiframe) {
     1258
     1259            if (!self.rail.drag) return true;
     1260
     1261            if (e.targetTouches && opt.preventmultitouchscrolling) {
     1262              if (e.targetTouches.length > 1) return true; // multitouch
     1263            }
     1264
     1265            //if (e.pointerType && e.pointerType != 2 && e.pointerType != "touch") return false;
     1266            if (e.pointerType && (e.pointerType === 'mouse' || e.pointerType === e.MSPOINTER_TYPE_MOUSE)) return true;
     1267
     1268            if (self.rail.drag.pt == 2) {
     1269
     1270              if (("changedTouches" in e)) {
     1271                e.clientX = e.changedTouches[0].clientX;
     1272                e.clientY = e.changedTouches[0].clientY;
     1273              }
     1274
     1275              var ofy, ofx;
     1276              ofx = ofy = 0;
     1277
     1278              if (moveneedoffset && !byiframe) {
     1279                var wp = self.win.position();
     1280                ofx = -wp.left;
     1281                ofy = -wp.top;
     1282              }
     1283
     1284              var fy = e.clientY + ofy;
     1285              var my = (fy - self.rail.drag.y);
     1286              var fx = e.clientX + ofx;
     1287              var mx = (fx - self.rail.drag.x);
     1288
     1289              var ny = self.rail.drag.st - my;
     1290
     1291              if (self.ishwscroll && opt.bouncescroll) {
     1292                if (ny < 0) {
     1293                  ny = Math.round(ny / 2);
     1294                } else if (ny > self.page.maxh) {
     1295                  ny = self.page.maxh + Math.round((ny - self.page.maxh) / 2);
     1296                }
     1297              } else {
     1298                if (ny < 0) {
     1299                  ny = 0;
     1300                  fy = 0;
     1301                }
     1302                else if (ny > self.page.maxh) {
     1303                  ny = self.page.maxh;
     1304                  fy = 0;
     1305                }
     1306                if (fy === 0 && !self.hasmoving) {
     1307                  if (!self.ispage) self.rail.drag = false;
     1308                  return true;
     1309                }
     1310              }
     1311
     1312              var nx = self.getScrollLeft();
     1313
     1314              if (self.railh && self.railh.scrollable) {
     1315                nx = (self.isrtlmode) ? mx - self.rail.drag.sl : self.rail.drag.sl - mx;
     1316
     1317                if (self.ishwscroll && opt.bouncescroll) {
     1318                  if (nx < 0) {
     1319                    nx = Math.round(nx / 2);
     1320                  } else if (nx > self.page.maxw) {
     1321                    nx = self.page.maxw + Math.round((nx - self.page.maxw) / 2);
     1322                  }
     1323                } else {
     1324                  if (nx < 0) {
     1325                    nx = 0;
     1326                    fx = 0;
     1327                  }
     1328                  if (nx > self.page.maxw) {
     1329                    nx = self.page.maxw;
     1330                    fx = 0;
    9971331                  }
    9981332                }
    999              
    1000                 self.cancelScroll();
    1001                
    1002                 var tg = self.getTarget(e);
    1003                
    1004                 if (tg) {
    1005                   var skp = (/INPUT/i.test(tg.nodeName))&&(/range/i.test(tg.type));
    1006                   if (skp) return self.stopPropagation(e);
     1333
     1334              }
     1335
     1336
     1337              if (!self.hasmoving) {
     1338
     1339                if (self.rail.drag.y === e.clientY && self.rail.drag.x === e.clientX) return self.cancelEvent(e);  // prevent first useless move event
     1340
     1341                var ay = Math.abs(my);
     1342                var ax = Math.abs(mx);
     1343                var dz = opt.directionlockdeadzone;
     1344
     1345                if (!self.rail.drag.ck) {
     1346                  if (ay > dz && ax > dz) self.rail.drag.dl = "f";
     1347                  else if (ay > dz) self.rail.drag.dl = (ax > locktollerance) ? "f" : "v";
     1348                  else if (ax > dz) self.rail.drag.dl = (ay > locktollerance) ? "f" : "h";
    10071349                }
    1008                
    1009                 if (!("clientX" in e) && ("changedTouches" in e)) {
    1010                   e.clientX = e.changedTouches[0].clientX;
    1011                   e.clientY = e.changedTouches[0].clientY;
     1350                else if (self.rail.drag.ck == "v") {
     1351                  if (ax > dz && ay <= locktollerance) {
     1352                    self.rail.drag = false;
     1353                  }
     1354                  else if (ay > dz) self.rail.drag.dl = "v";
     1355
    10121356                }
    1013                
    1014                 if (self.forcescreen) {
    1015                   var le = e;
    1016                   var e = {"original":(e.original)?e.original:e};
    1017                   e.clientX = le.screenX;
    1018                   e.clientY = le.screenY;   
     1357                else if (self.rail.drag.ck == "h") {
     1358
     1359                  if (ay > dz && ax <= locktollerance) {
     1360                    self.rail.drag = false;
     1361                  }
     1362                  else if (ax > dz) self.rail.drag.dl = "h";
     1363
    10191364                }
    1020                
    1021                 self.rail.drag = {x:e.clientX,y:e.clientY,sx:self.scroll.x,sy:self.scroll.y,st:self.getScrollTop(),sl:self.getScrollLeft(),pt:2,dl:false};
    1022                
    1023                 if (self.ispage||!self.opt.directionlockdeadzone) {
    1024                   self.rail.drag.dl = "f";
    1025                 } else {
    1026                
    1027                   var view = {
    1028                     w:$(window).width(),
    1029                     h:$(window).height()
    1030                   };
    1031                  
    1032                   var page = {
    1033                     w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
    1034                     h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
     1365
     1366                if (!self.rail.drag.dl) return self.cancelEvent(e);
     1367
     1368                self.triggerScrollStart(e.clientX, e.clientY, 0, 0, 0);
     1369                self.hasmoving = true;
     1370              }
     1371
     1372              if (self.preventclick && !self.preventclick.click) {
     1373                self.preventclick.click = self.preventclick.tg.onclick || false;
     1374                self.preventclick.tg.onclick = self.onpreventclick;
     1375              }
     1376
     1377              if (self.rail.drag.dl) {
     1378                if (self.rail.drag.dl == "v") nx = self.rail.drag.sl;
     1379                else if (self.rail.drag.dl == "h") ny = self.rail.drag.st;
     1380              }
     1381
     1382              self.synched("touchmove", function () {
     1383                if (self.rail.drag && (self.rail.drag.pt == 2)) {
     1384                  if (self.prepareTransition) self.resetTransition();
     1385                  if (self.rail.scrollable) self.setScrollTop(ny);
     1386                  self.scrollmom.update(fx, fy);
     1387                  if (self.railh && self.railh.scrollable) {
     1388                    self.setScrollLeft(nx);
     1389                    self.showCursor(ny, nx);
     1390                  } else {
     1391                    self.showCursor(ny);
    10351392                  }
    1036                  
    1037                   var maxh = Math.max(0,page.h - view.h);
    1038                   var maxw = Math.max(0,page.w - view.w);               
    1039                
    1040                   if (!self.rail.scrollable&&self.railh.scrollable) self.rail.drag.ck = (maxh>0) ? "v" : false;
    1041                   else if (self.rail.scrollable&&!self.railh.scrollable) self.rail.drag.ck = (maxw>0) ? "h" : false;
    1042                   else self.rail.drag.ck = false;
    1043                   if (!self.rail.drag.ck) self.rail.drag.dl = "f";
     1393                  if (cap.isie10) _doc.selection.clear();
    10441394                }
    1045                
    1046                 if (self.opt.touchbehavior&&self.isiframe&&cap.isie) {
    1047                   var wp = self.win.position();
    1048                   self.rail.drag.x+=wp.left;
    1049                   self.rail.drag.y+=wp.top;
    1050                 }
    1051                
    1052                 self.hasmoving = false;
    1053                 self.lastmouseup = false;
    1054                 self.scrollmom.reset(e.clientX,e.clientY);
    1055                 if (!cap.cantouch&&!this.istouchcapable&&!cap.hasmstouch) {
    1056                  
    1057                   var ip = (tg)?/INPUT|SELECT|TEXTAREA/i.test(tg.nodeName):false;
    1058                   if (!ip) {
    1059                     if (!self.ispage&&cap.hasmousecapture) tg.setCapture();
    1060                     return self.cancelEvent(e);
    1061                   }
    1062                   if (/SUBMIT|CANCEL|BUTTON/i.test($(tg).attr('type'))) {
    1063                     pc = {"tg":tg,"click":false};
    1064                     self.preventclick = pc;
    1065                   }
    1066                  
    1067                 }
    1068               }
    1069              
     1395              });
     1396
     1397              return self.cancelEvent(e);
     1398
     1399            }
     1400            else if (self.rail.drag.pt == 1) { // drag on cursor
     1401              return self.onmousemove(e);
     1402            }
     1403
     1404          };
     1405
     1406          self.ontouchstartCursor = function (e, hronly) {
     1407            if (self.rail.drag && self.rail.drag.pt != 3) return;
     1408            if (self.locked) return self.cancelEvent(e);
     1409            self.cancelScroll();
     1410            self.rail.drag = {
     1411              x: e.touches[0].clientX,
     1412              y: e.touches[0].clientY,
     1413              sx: self.scroll.x,
     1414              sy: self.scroll.y,
     1415              pt: 3,
     1416              hr: (!!hronly)
    10701417            };
    1071            
    1072             self.ontouchend = function(e) {
    1073               if (e.pointerType&&e.pointerType!=2) return false;
    1074               if (self.rail.drag&&(self.rail.drag.pt==2)) {
    1075                 self.scrollmom.doMomentum();
    1076                 self.rail.drag = false;
    1077                 if (self.hasmoving) {
    1078                   self.hasmoving = false;
    1079                   self.lastmouseup = true;
    1080                   self.hideCursor();
    1081                   if (cap.hasmousecapture) document.releaseCapture();
    1082                   if (!cap.cantouch) return self.cancelEvent(e);
    1083                 }                           
    1084               }                       
    1085              
    1086             };
    1087            
    1088             var moveneedoffset = (self.opt.touchbehavior&&self.isiframe&&!cap.hasmousecapture);
    1089            
    1090             self.ontouchmove = function(e,byiframe) {
    1091              
    1092               if (e.pointerType&&e.pointerType!=2) return false;
    1093    
    1094               if (self.rail.drag&&(self.rail.drag.pt==2)) {
    1095                 if (cap.cantouch&&(typeof e.original == "undefined")) return true;  // prevent ios "ghost" events by clickable elements
    1096              
    1097                 self.hasmoving = true;
    1098 
    1099                 if (self.preventclick&&!self.preventclick.click) {
    1100                   self.preventclick.click = self.preventclick.tg.onclick||false;               
    1101                   self.preventclick.tg.onclick = self.onpreventclick;
    1102                 }
    1103 
    1104                 var ev = $.extend({"original":e},e);
    1105                 e = ev;
    1106                
    1107                 if (("changedTouches" in e)) {
    1108                   e.clientX = e.changedTouches[0].clientX;
    1109                   e.clientY = e.changedTouches[0].clientY;
    1110                 }               
    1111                
    1112                 if (self.forcescreen) {
    1113                   var le = e;
    1114                   var e = {"original":(e.original)?e.original:e};
    1115                   e.clientX = le.screenX;
    1116                   e.clientY = le.screenY;     
    1117                 }
    1118                
    1119                 var ofx = ofy = 0;
    1120                
    1121                 if (moveneedoffset&&!byiframe) {
    1122                   var wp = self.win.position();
    1123                   ofx=-wp.left;
    1124                   ofy=-wp.top;
    1125                 }               
    1126                
    1127                 var fy = e.clientY + ofy;
    1128                 var my = (fy-self.rail.drag.y);
    1129                 var fx = e.clientX + ofx;
    1130                 var mx = (fx-self.rail.drag.x);
    1131                
    1132                 var ny = self.rail.drag.st-my;
    1133                
    1134                 if (self.ishwscroll&&self.opt.bouncescroll) {
    1135                   if (ny<0) {
    1136                     ny = Math.round(ny/2);
    1137 //                    fy = 0;
    1138                   }
    1139                   else if (ny>self.page.maxh) {
    1140                     ny = self.page.maxh+Math.round((ny-self.page.maxh)/2);
    1141 //                    fy = 0;
    1142                   }
    1143                 } else {
    1144                   if (ny<0) {ny=0;fy=0}
    1145                   if (ny>self.page.maxh) {ny=self.page.maxh;fy=0}
    1146                 }
    1147                  
    1148                 if (self.railh&&self.railh.scrollable) {
    1149                   var nx = self.rail.drag.sl-mx;
    1150                  
    1151                   if (self.ishwscroll&&self.opt.bouncescroll) {                 
    1152                     if (nx<0) {
    1153                       nx = Math.round(nx/2);
    1154 //                      fx = 0;
    1155                     }
    1156                     else if (nx>self.page.maxw) {
    1157                       nx = self.page.maxw+Math.round((nx-self.page.maxw)/2);
    1158 //                      fx = 0;
    1159                     }
    1160                   } else {
    1161                     if (nx<0) {nx=0;fx=0}
    1162                     if (nx>self.page.maxw) {nx=self.page.maxw;fx=0}
    1163                   }
    1164                
    1165                 }
    1166                
    1167                 var grabbed = false;
    1168                 if (self.rail.drag.dl) {
    1169                   grabbed = true;
    1170                   if (self.rail.drag.dl=="v") nx = self.rail.drag.sl;
    1171                   else if (self.rail.drag.dl=="h") ny = self.rail.drag.st;                 
    1172                 } else {
    1173                   var ay = Math.abs(my);
    1174                   var ax = Math.abs(mx);
    1175                   var dz = self.opt.directionlockdeadzone;
    1176                   if (self.rail.drag.ck=="v") {   
    1177                     if (ay>dz&&(ax<=(ay*0.3))) {
    1178                       self.rail.drag = false;                     
    1179                       return true;
    1180                     }
    1181                     else if (ax>dz) {
    1182                       self.rail.drag.dl="f";                     
    1183                       $("body").scrollTop($("body").scrollTop());  // stop iOS native scrolling (when active javascript has blocked)
    1184                     }
    1185                   }
    1186                   else if (self.rail.drag.ck=="h") {
    1187                     if (ax>dz&&(ay<=(az*0.3))) {
    1188                       self.rail.drag = false;                     
    1189                       return true;
    1190                     }
    1191                     else if (ay>dz) {                     
    1192                       self.rail.drag.dl="f";
    1193                       $("body").scrollLeft($("body").scrollLeft());  // stop iOS native scrolling (when active javascript has blocked)
    1194                     }
    1195                   } 
    1196                 }
    1197                
    1198                 self.synched("touchmove",function(){
    1199                   if (self.rail.drag&&(self.rail.drag.pt==2)) {
    1200                     if (self.prepareTransition) self.prepareTransition(0);
    1201                     if (self.rail.scrollable) self.setScrollTop(ny);
    1202                     self.scrollmom.update(fx,fy);
    1203                     if (self.railh&&self.railh.scrollable) {
    1204                       self.setScrollLeft(nx);
    1205                       self.showCursor(ny,nx);
    1206                     } else {
    1207                       self.showCursor(ny);
    1208                     }
    1209                     if (cap.isie10) document.selection.clear();
    1210                   }
    1211                 });
    1212                
    1213                 if (cap.ischrome&&self.istouchcapable) grabbed=false;  //chrome touch emulation doesn't like!
    1214                 if (grabbed) return self.cancelEvent(e);
    1215               }
    1216              
    1217             };
    1218          
    1219           }
    1220          
    1221           self.onmousedown = function(e,hronly) {   
    1222             if (self.rail.drag&&self.rail.drag.pt!=1) return;
    1223             if (self.locked) return self.cancelEvent(e);           
    1224             self.cancelScroll();             
    1225             self.rail.drag = {x:e.clientX,y:e.clientY,sx:self.scroll.x,sy:self.scroll.y,pt:1,hr:(!!hronly)};
    12261418            var tg = self.getTarget(e);
    1227             if (!self.ispage&&cap.hasmousecapture) tg.setCapture();
    1228             if (self.isiframe&&!cap.hasmousecapture) {
    1229               self.saved["csspointerevents"] = self.doc.css("pointer-events");
    1230               self.css(self.doc,{"pointer-events":"none"});
     1419            if (!self.ispage && cap.hasmousecapture) tg.setCapture();
     1420            if (self.isiframe && !cap.hasmousecapture) {
     1421              self.saved.csspointerevents = self.doc.css("pointer-events");
     1422              self.css(self.doc, { "pointer-events": "none" });
    12311423            }
    12321424            return self.cancelEvent(e);
    12331425          };
    1234          
    1235           self.onmouseup = function(e) {
     1426
     1427          self.ontouchendCursor = function (e) {
    12361428            if (self.rail.drag) {
    1237               if (cap.hasmousecapture) document.releaseCapture();
    1238               if (self.isiframe&&!cap.hasmousecapture) self.doc.css("pointer-events",self.saved["csspointerevents"]);
    1239               if(self.rail.drag.pt!=1)return;
     1429              if (cap.hasmousecapture) _doc.releaseCapture();
     1430              if (self.isiframe && !cap.hasmousecapture) self.doc.css("pointer-events", self.saved.csspointerevents);
     1431              if (self.rail.drag.pt != 3) return;
    12401432              self.rail.drag = false;
    1241               //if (!self.rail.active) self.hideCursor();
    12421433              return self.cancelEvent(e);
    12431434            }
    1244           };       
    1245          
    1246           self.onmousemove = function(e) {
     1435          };
     1436
     1437          self.ontouchmoveCursor = function (e) {
    12471438            if (self.rail.drag) {
    1248               if(self.rail.drag.pt!=1)return;
    1249              
    1250               if (cap.ischrome&&e.which==0) return self.onmouseup(e);
    1251              
     1439              if (self.rail.drag.pt != 3) return;
     1440
    12521441              self.cursorfreezed = true;
    1253                  
     1442
    12541443              if (self.rail.drag.hr) {
    1255                 self.scroll.x = self.rail.drag.sx + (e.clientX-self.rail.drag.x);
    1256                 if (self.scroll.x<0) self.scroll.x=0;
     1444                self.scroll.x = self.rail.drag.sx + (e.touches[0].clientX - self.rail.drag.x);
     1445                if (self.scroll.x < 0) self.scroll.x = 0;
    12571446                var mw = self.scrollvaluemaxw;
    1258                 if (self.scroll.x>mw) self.scroll.x=mw;
    1259               } else {               
    1260                 self.scroll.y = self.rail.drag.sy + (e.clientY-self.rail.drag.y);
    1261                 if (self.scroll.y<0) self.scroll.y=0;
     1447                if (self.scroll.x > mw) self.scroll.x = mw;
     1448              } else {
     1449                self.scroll.y = self.rail.drag.sy + (e.touches[0].clientY - self.rail.drag.y);
     1450                if (self.scroll.y < 0) self.scroll.y = 0;
    12621451                var my = self.scrollvaluemax;
    1263                 if (self.scroll.y>my) self.scroll.y=my;
     1452                if (self.scroll.y > my) self.scroll.y = my;
    12641453              }
    1265              
    1266               self.synched('mousemove',function(){
    1267                 if (self.rail.drag&&(self.rail.drag.pt==1)) {
     1454
     1455              self.synched('touchmove', function () {
     1456                if (self.rail.drag && (self.rail.drag.pt == 3)) {
    12681457                  self.showCursor();
    1269                   if (self.rail.drag.hr) self.doScrollLeft(Math.round(self.scroll.x*self.scrollratio.x),self.opt.cursordragspeed);
    1270                   else self.doScrollTop(Math.round(self.scroll.y*self.scrollratio.y),self.opt.cursordragspeed);
     1458                  if (self.rail.drag.hr) self.doScrollLeft(Math.round(self.scroll.x * self.scrollratio.x), opt.cursordragspeed);
     1459                  else self.doScrollTop(Math.round(self.scroll.y * self.scrollratio.y), opt.cursordragspeed);
    12711460                }
    12721461              });
    1273              
     1462
    12741463              return self.cancelEvent(e);
    1275             }
    1276 /*             
    1277             else {
    1278               self.checkarea = true;
    12791464            }
    1280 */             
    1281           };         
    1282          
    1283           if (cap.cantouch||self.opt.touchbehavior) {
    1284          
    1285             self.onpreventclick = function(e) {
    1286               if (self.preventclick) {
    1287                 self.preventclick.tg.onclick = self.preventclick.click;
    1288                 self.preventclick = false;           
    1289                 return self.cancelEvent(e);
     1465
     1466          };
     1467
     1468        }
     1469
     1470        self.onmousedown = function (e, hronly) {
     1471          if (self.rail.drag && self.rail.drag.pt != 1) return;
     1472          if (self.railslocked) return self.cancelEvent(e);
     1473          self.cancelScroll();
     1474          self.rail.drag = {
     1475            x: e.clientX,
     1476            y: e.clientY,
     1477            sx: self.scroll.x,
     1478            sy: self.scroll.y,
     1479            pt: 1,
     1480            hr: hronly || false
     1481          };
     1482          var tg = self.getTarget(e);
     1483
     1484          if (cap.hasmousecapture) tg.setCapture();
     1485          if (self.isiframe && !cap.hasmousecapture) {
     1486            self.saved.csspointerevents = self.doc.css("pointer-events");
     1487            self.css(self.doc, {
     1488              "pointer-events": "none"
     1489            });
     1490          }
     1491          self.hasmoving = false;
     1492          return self.cancelEvent(e);
     1493        };
     1494
     1495        self.onmouseup = function (e) {
     1496          if (self.rail.drag) {
     1497            if (self.rail.drag.pt != 1) return true;
     1498
     1499            if (cap.hasmousecapture) _doc.releaseCapture();
     1500            if (self.isiframe && !cap.hasmousecapture) self.doc.css("pointer-events", self.saved.csspointerevents);
     1501            self.rail.drag = false;
     1502            self.cursorfreezed = false;
     1503            if (self.hasmoving) self.triggerScrollEnd();
     1504            return self.cancelEvent(e);
     1505          }
     1506        };
     1507
     1508        self.onmousemove = function (e) {
     1509          if (self.rail.drag) {
     1510            if (self.rail.drag.pt !== 1) return;
     1511
     1512            if (cap.ischrome && e.which === 0) return self.onmouseup(e);
     1513
     1514            self.cursorfreezed = true;
     1515
     1516            if (!self.hasmoving) self.triggerScrollStart(e.clientX, e.clientY, 0, 0, 0);
     1517
     1518            self.hasmoving = true;
     1519
     1520            if (self.rail.drag.hr) {
     1521              self.scroll.x = self.rail.drag.sx + (e.clientX - self.rail.drag.x);
     1522              if (self.scroll.x < 0) self.scroll.x = 0;
     1523              var mw = self.scrollvaluemaxw;
     1524              if (self.scroll.x > mw) self.scroll.x = mw;
     1525            } else {
     1526              self.scroll.y = self.rail.drag.sy + (e.clientY - self.rail.drag.y);
     1527              if (self.scroll.y < 0) self.scroll.y = 0;
     1528              var my = self.scrollvaluemax;
     1529              if (self.scroll.y > my) self.scroll.y = my;
     1530            }
     1531
     1532            self.synched('mousemove', function () {
     1533
     1534              if (self.cursorfreezed) {
     1535                self.showCursor();
     1536
     1537                if (self.rail.drag.hr) {
     1538                  self.scrollLeft(Math.round(self.scroll.x * self.scrollratio.x));
     1539                } else {
     1540                  self.scrollTop(Math.round(self.scroll.y * self.scrollratio.y));
     1541                }
     1542
    12901543              }
     1544            });
     1545
     1546            return self.cancelEvent(e);
     1547          }
     1548          else {
     1549            self.checkarea = 0;
     1550          }
     1551        };
     1552
     1553        if (cap.cantouch || opt.emulatetouch) {
     1554
     1555          self.onpreventclick = function (e) {
     1556            if (self.preventclick) {
     1557              self.preventclick.tg.onclick = self.preventclick.click;
     1558              self.preventclick = false;
     1559              return self.cancelEvent(e);
    12911560            }
    1292          
    1293 //            self.onmousedown = self.ontouchstart;           
    1294 //            self.onmouseup = self.ontouchend;
    1295 //            self.onmousemove = self.ontouchmove;
    1296 
    1297             self.bind(self.win,"mousedown",self.ontouchstart);  // control content dragging
    1298 
    1299             self.onclick = (cap.isios) ? false : function(e) {
    1300               if (self.lastmouseup) {
    1301                 self.lastmouseup = false;
    1302                 return self.cancelEvent(e);
    1303               } else {
    1304                 return true;
    1305               }
    1306             };
    1307            
    1308             if (self.opt.grabcursorenabled&&cap.cursorgrabvalue) {
    1309               self.css((self.ispage)?self.doc:self.win,{'cursor':cap.cursorgrabvalue});           
    1310               self.css(self.rail,{'cursor':cap.cursorgrabvalue});
     1561          };
     1562
     1563          self.onclick = (cap.isios) ? false : function (e) {  // it needs to check IE11 ???
     1564            if (self.lastmouseup) {
     1565              self.lastmouseup = false;
     1566              return self.cancelEvent(e);
     1567            } else {
     1568              return true;
    13111569            }
    1312            
     1570          };
     1571
     1572          if (opt.grabcursorenabled && cap.cursorgrabvalue) {
     1573            self.css((self.ispage) ? self.doc : self.win, {
     1574              'cursor': cap.cursorgrabvalue
     1575            });
     1576            self.css(self.rail, {
     1577              'cursor': cap.cursorgrabvalue
     1578            });
     1579          }
     1580
     1581        } else {
     1582
     1583          var checkSelectionScroll = function (e) {
     1584            if (!self.selectiondrag) return;
     1585
     1586            if (e) {
     1587              var ww = self.win.outerHeight();
     1588              var df = (e.pageY - self.selectiondrag.top);
     1589              if (df > 0 && df < ww) df = 0;
     1590              if (df >= ww) df -= ww;
     1591              self.selectiondrag.df = df;
     1592            }
     1593            if (self.selectiondrag.df === 0) return;
     1594
     1595            var rt = -(self.selectiondrag.df*2/6)|0;
     1596            self.doScrollBy(rt);
     1597
     1598            self.debounced("doselectionscroll", function () {
     1599              checkSelectionScroll();
     1600            }, 50);
     1601          };
     1602
     1603          if ("getSelection" in _doc) { // A grade - Major browsers
     1604            self.hasTextSelected = function () {
     1605              return (_doc.getSelection().rangeCount > 0);
     1606            };
     1607          } else if ("selection" in _doc) { //IE9-
     1608            self.hasTextSelected = function () {
     1609              return (_doc.selection.type != "None");
     1610            };
    13131611          } else {
    1314 
    1315             function checkSelectionScroll(e) {
    1316               if (!self.selectiondrag) return;
    1317              
    1318               if (e) {
    1319                 var ww = self.win.outerHeight();
    1320                 var df = (e.pageY - self.selectiondrag.top);
    1321                 if (df>0&&df<ww) df=0;
    1322                 if (df>=ww) df-=ww;
    1323                 self.selectiondrag.df = df;               
    1324               }
    1325               if (self.selectiondrag.df==0) return;
    1326              
    1327               var rt = -Math.floor(self.selectiondrag.df/6)*2;             
    1328 //              self.doScrollTop(self.getScrollTop(true)+rt);
    1329               self.doScrollBy(rt);
    1330              
    1331               self.debounced("doselectionscroll",function(){checkSelectionScroll()},50);
    1332             }
    1333            
    1334             if ("getSelection" in document) {  // A grade - Major browsers
    1335               self.hasTextSelected = function() { 
    1336                 return (document.getSelection().rangeCount>0);
    1337               }
    1338             }
    1339             else if ("selection" in document) {  //IE9-
    1340               self.hasTextSelected = function() {
    1341                 return (document.selection.type != "None");
    1342               }
    1343             }
    1344             else {
    1345               self.hasTextSelected = function() {  // no support
    1346                 return false;
    1347               }
    1348             }           
    1349            
    1350             self.onselectionstart = function(e) {
    1351               if (self.ispage) return;
    1352               self.selectiondrag = self.win.offset();
    1353             }
    1354             self.onselectionend = function(e) {
    1355               self.selectiondrag = false;
    1356             }
    1357             self.onselectiondrag = function(e) {             
    1358               if (!self.selectiondrag) return;
    1359               if (self.hasTextSelected()) self.debounced("selectionscroll",function(){checkSelectionScroll(e)},250);
    1360             }
    1361            
    1362            
    1363           }
    1364          
    1365           if (cap.hasmstouch) {
    1366             self.css(self.rail,{'-ms-touch-action':'none'});
    1367             self.css(self.cursor,{'-ms-touch-action':'none'});
    1368            
    1369             self.bind(self.win,"MSPointerDown",self.ontouchstart);
    1370             self.bind(document,"MSPointerUp",self.ontouchend);
    1371             self.bind(document,"MSPointerMove",self.ontouchmove);
    1372             self.bind(self.cursor,"MSGestureHold",function(e){e.preventDefault()});
    1373             self.bind(self.cursor,"contextmenu",function(e){e.preventDefault()});
    1374           }
    1375 
    1376           if (this.istouchcapable) {  //desktop with screen touch enabled
    1377             self.bind(self.win,"touchstart",self.ontouchstart);
    1378             self.bind(document,"touchend",self.ontouchend);
    1379             self.bind(document,"touchcancel",self.ontouchend);
    1380             self.bind(document,"touchmove",self.ontouchmove);           
    1381           }
    1382          
    1383           self.bind(self.cursor,"mousedown",self.onmousedown);
    1384           self.bind(self.cursor,"mouseup",self.onmouseup);
     1612            self.hasTextSelected = function () { // no support
     1613              return false;
     1614            };
     1615          }
     1616
     1617          self.onselectionstart = function (e) {
     1618            //  More testing - severe chrome issues           
     1619            /*
     1620                          if (!self.haswrapper&&(e.which&&e.which==2)) {  // fool browser to manage middle button scrolling
     1621                            self.win.css({'overflow':'auto'});
     1622                            setTimeout(function(){
     1623                              self.win.css({'overflow':'hidden'});
     1624                            },10);               
     1625                            return true;
     1626                          }           
     1627            */
     1628            if (self.ispage) return;
     1629            self.selectiondrag = self.win.offset();
     1630          };
     1631
     1632          self.onselectionend = function (e) {
     1633            self.selectiondrag = false;
     1634          };
     1635          self.onselectiondrag = function (e) {
     1636            if (!self.selectiondrag) return;
     1637            if (self.hasTextSelected()) self.debounced("selectionscroll", function () {
     1638              checkSelectionScroll(e);
     1639            }, 250);
     1640          };
     1641        }
     1642
     1643        if (cap.hasw3ctouch) { //IE11+
     1644          self.css((self.ispage) ? $("html") : self.win, { 'touch-action': 'none' });
     1645          self.css(self.rail, {
     1646            'touch-action': 'none'
     1647          });
     1648          self.css(self.cursor, {
     1649            'touch-action': 'none'
     1650          });
     1651          self.bind(self.win, "pointerdown", self.ontouchstart);
     1652          self.bind(_doc, "pointerup", self.ontouchend);
     1653          self.delegate(_doc, "pointermove", self.ontouchmove);
     1654        } else if (cap.hasmstouch) { //IE10
     1655          self.css((self.ispage) ? $("html") : self.win, { '-ms-touch-action': 'none' });
     1656          self.css(self.rail, {
     1657            '-ms-touch-action': 'none'
     1658          });
     1659          self.css(self.cursor, {
     1660            '-ms-touch-action': 'none'
     1661          });
     1662          self.bind(self.win, "MSPointerDown", self.ontouchstart);
     1663          self.bind(_doc, "MSPointerUp", self.ontouchend);
     1664          self.delegate(_doc, "MSPointerMove", self.ontouchmove);
     1665          self.bind(self.cursor, "MSGestureHold", function (e) {
     1666            e.preventDefault();
     1667          });
     1668          self.bind(self.cursor, "contextmenu", function (e) {
     1669            e.preventDefault();
     1670          });
     1671        } else if (cap.cantouch) { // smartphones/touch devices
     1672          self.bind(self.win, "touchstart", self.ontouchstart, false, true);
     1673          self.bind(_doc, "touchend", self.ontouchend, false, true);
     1674          self.bind(_doc, "touchcancel", self.ontouchend, false, true);
     1675          self.delegate(_doc, "touchmove", self.ontouchmove, false, true);
     1676        }
     1677
     1678        if (opt.emulatetouch) {
     1679          self.bind(self.win, "mousedown", self.ontouchstart, false, true);
     1680          self.bind(_doc, "mouseup", self.ontouchend, false, true);
     1681          self.bind(_doc, "mousemove", self.ontouchmove, false, true);
     1682        }
     1683
     1684        if (opt.cursordragontouch || (!cap.cantouch && !opt.emulatetouch)) {
     1685
     1686          self.rail.css({
     1687            cursor: "default"
     1688          });
     1689          self.railh && self.railh.css({
     1690            cursor: "default"
     1691          });
     1692
     1693          self.jqbind(self.rail, "mouseenter", function () {
     1694            if (!self.ispage && !self.win.is(":visible")) return false;
     1695            if (self.canshowonmouseevent) self.showCursor();
     1696            self.rail.active = true;
     1697          });
     1698          self.jqbind(self.rail, "mouseleave", function () {
     1699            self.rail.active = false;
     1700            if (!self.rail.drag) self.hideCursor();
     1701          });
     1702
     1703          if (opt.sensitiverail) {
     1704            self.bind(self.rail, "click", function (e) {
     1705              self.doRailClick(e, false, false);
     1706            });
     1707            self.bind(self.rail, "dblclick", function (e) {
     1708              self.doRailClick(e, true, false);
     1709            });
     1710            self.bind(self.cursor, "click", function (e) {
     1711              self.cancelEvent(e);
     1712            });
     1713            self.bind(self.cursor, "dblclick", function (e) {
     1714              self.cancelEvent(e);
     1715            });
     1716          }
    13851717
    13861718          if (self.railh) {
    1387             self.bind(self.cursorh,"mousedown",function(e){self.onmousedown(e,true)});
    1388             self.bind(self.cursorh,"mouseup",function(e){
    1389               if (self.rail.drag&&self.rail.drag.pt==2) return;
    1390               self.rail.drag = false;
    1391               self.hasmoving = false;
    1392               self.hideCursor();
    1393               if (cap.hasmousecapture) document.releaseCapture();
    1394               return self.cancelEvent(e);
    1395             });
    1396           }
    1397        
    1398           if (self.opt.cursordragontouch||!cap.cantouch&&!self.opt.touchbehavior) {
    1399 
    1400             self.rail.css({"cursor":"default"});
    1401             self.railh&&self.railh.css({"cursor":"default"});         
    1402          
    1403             self.jqbind(self.rail,"mouseenter",function() {
     1719            self.jqbind(self.railh, "mouseenter", function () {
     1720              if (!self.ispage && !self.win.is(":visible")) return false;
    14041721              if (self.canshowonmouseevent) self.showCursor();
    14051722              self.rail.active = true;
    14061723            });
    1407             self.jqbind(self.rail,"mouseleave",function() {
     1724            self.jqbind(self.railh, "mouseleave", function () {
    14081725              self.rail.active = false;
    14091726              if (!self.rail.drag) self.hideCursor();
    14101727            });
    1411            
    1412             if (self.opt.sensitiverail) {
    1413               self.bind(self.rail,"click",function(e){self.doRailClick(e,false,false)});
    1414               self.bind(self.rail,"dblclick",function(e){self.doRailClick(e,true,false)});
    1415               self.bind(self.cursor,"click",function(e){self.cancelEvent(e)});
    1416               self.bind(self.cursor,"dblclick",function(e){self.cancelEvent(e)});
     1728
     1729            if (opt.sensitiverail) {
     1730              self.bind(self.railh, "click", function (e) {
     1731                self.doRailClick(e, false, true);
     1732              });
     1733              self.bind(self.railh, "dblclick", function (e) {
     1734                self.doRailClick(e, true, true);
     1735              });
     1736              self.bind(self.cursorh, "click", function (e) {
     1737                self.cancelEvent(e);
     1738              });
     1739              self.bind(self.cursorh, "dblclick", function (e) {
     1740                self.cancelEvent(e);
     1741              });
    14171742            }
    14181743
    1419             if (self.railh) {
    1420               self.jqbind(self.railh,"mouseenter",function() {
    1421                 if (self.canshowonmouseevent) self.showCursor();
    1422                 self.rail.active = true;
    1423               });         
    1424               self.jqbind(self.railh,"mouseleave",function() {
    1425                 self.rail.active = false;
    1426                 if (!self.rail.drag) self.hideCursor();
    1427               });
    1428              
    1429               if (self.opt.sensitiverail) {
    1430                 self.bind(self.railh, "click", function(e){self.doRailClick(e,false,true)});
    1431                 self.bind(self.railh, "dblclick", function(e){self.doRailClick(e, true, true) });
    1432                 self.bind(self.cursorh, "click", function (e) { self.cancelEvent(e) });
    1433                 self.bind(self.cursorh, "dblclick", function (e) { self.cancelEvent(e) });
    1434               }
    1435              
    1436             }
    1437          
    1438           }
    1439    
    1440           if (!cap.cantouch&&!self.opt.touchbehavior) {
    1441 
    1442             self.bind((cap.hasmousecapture)?self.win:document,"mouseup",self.onmouseup);           
    1443             self.bind(document,"mousemove",self.onmousemove);
    1444             if (self.onclick) self.bind(document,"click",self.onclick);
    1445            
    1446             if (!self.ispage&&self.opt.enablescrollonselection) {
    1447               self.bind(self.win[0],"mousedown",self.onselectionstart);
    1448               self.bind(document,"mouseup",self.onselectionend);
    1449               self.bind(self.cursor,"mouseup",self.onselectionend);
    1450               if (self.cursorh) self.bind(self.cursorh,"mouseup",self.onselectionend);
    1451               self.bind(document,"mousemove",self.onselectiondrag);
    1452             }
    1453 
    1454                         if (self.zoom) {
    1455                             self.jqbind(self.zoom,"mouseenter",function() {
    1456                                 if (self.canshowonmouseevent) self.showCursor();
    1457                                 self.rail.active = true;
    1458                             });         
    1459                             self.jqbind(self.zoom,"mouseleave",function() {
    1460                                 self.rail.active = false;
    1461                                 if (!self.rail.drag) self.hideCursor();
    1462                             });
    1463                         }
    1464 
     1744          }
     1745
     1746        }
     1747
     1748        if (opt.cursordragontouch && (this.istouchcapable || cap.cantouch)) {
     1749          self.bind(self.cursor, "touchstart", self.ontouchstartCursor);
     1750          self.bind(self.cursor, "touchmove", self.ontouchmoveCursor);
     1751          self.bind(self.cursor, "touchend", self.ontouchendCursor);
     1752          self.cursorh && self.bind(self.cursorh, "touchstart", function (e) {
     1753            self.ontouchstartCursor(e, true);
     1754          });
     1755          self.cursorh && self.bind(self.cursorh, "touchmove", self.ontouchmoveCursor);
     1756          self.cursorh && self.bind(self.cursorh, "touchend", self.ontouchendCursor);
     1757        }
     1758
     1759//        if (!cap.cantouch && !opt.emulatetouch) {
     1760        if (!opt.emulatetouch && !cap.isandroid && !cap.isios) {
     1761
     1762          self.bind((cap.hasmousecapture) ? self.win : _doc, "mouseup", self.onmouseup);
     1763          self.bind(_doc, "mousemove", self.onmousemove);
     1764          if (self.onclick) self.bind(_doc, "click", self.onclick);
     1765
     1766          self.bind(self.cursor, "mousedown", self.onmousedown);
     1767          self.bind(self.cursor, "mouseup", self.onmouseup);
     1768
     1769          if (self.railh) {
     1770            self.bind(self.cursorh, "mousedown", function (e) {
     1771              self.onmousedown(e, true);
     1772            });
     1773            self.bind(self.cursorh, "mouseup", self.onmouseup);
     1774          }
     1775
     1776          if (!self.ispage && opt.enablescrollonselection) {
     1777            self.bind(self.win[0], "mousedown", self.onselectionstart);
     1778            self.bind(_doc, "mouseup", self.onselectionend);
     1779            self.bind(self.cursor, "mouseup", self.onselectionend);
     1780            if (self.cursorh) self.bind(self.cursorh, "mouseup", self.onselectionend);
     1781            self.bind(_doc, "mousemove", self.onselectiondrag);
     1782          }
     1783
     1784          if (self.zoom) {
     1785            self.jqbind(self.zoom, "mouseenter", function () {
     1786              if (self.canshowonmouseevent) self.showCursor();
     1787              self.rail.active = true;
     1788            });
     1789            self.jqbind(self.zoom, "mouseleave", function () {
     1790              self.rail.active = false;
     1791              if (!self.rail.drag) self.hideCursor();
     1792            });
     1793          }
     1794
     1795        } else {
     1796
     1797          self.bind((cap.hasmousecapture) ? self.win : _doc, "mouseup", self.ontouchend);
     1798          if (self.onclick) self.bind(_doc, "click", self.onclick);
     1799
     1800          if (opt.cursordragontouch) {
     1801            self.bind(self.cursor, "mousedown", self.onmousedown);
     1802            self.bind(self.cursor, "mouseup", self.onmouseup);
     1803            self.cursorh && self.bind(self.cursorh, "mousedown", function (e) {
     1804              self.onmousedown(e, true);
     1805            });
     1806            self.cursorh && self.bind(self.cursorh, "mouseup", self.onmouseup);
    14651807          } else {
    1466            
    1467             self.bind((cap.hasmousecapture)?self.win:document,"mouseup",self.ontouchend);
    1468             self.bind(document,"mousemove",self.ontouchmove);
    1469             if (self.onclick) self.bind(document,"click",self.onclick);
    1470            
    1471             if (self.opt.cursordragontouch) {
    1472               self.bind(self.cursor,"mousedown",self.onmousedown);
    1473               self.bind(self.cursor,"mousemove",self.onmousemove);
    1474               self.cursorh&&self.bind(self.cursorh,"mousedown",self.onmousedown);
    1475               self.cursorh&&self.bind(self.cursorh,"mousemove",self.onmousemove);
    1476             }
    1477          
    1478           }
    1479                        
    1480                     if (self.opt.enablemousewheel) {
    1481                         if (!self.isiframe) self.bind((cap.isie&&self.ispage) ? document : self.docscroll,"mousewheel",self.onmousewheel);
    1482                         self.bind(self.rail,"mousewheel",self.onmousewheel);
    1483                         if (self.railh) self.bind(self.railh,"mousewheel",self.onmousewheelhr);
    1484                     }                       
    1485                        
    1486           if (!self.ispage&&!cap.cantouch&&!(/HTML|BODY/.test(self.win[0].nodeName))) {
    1487             if (!self.win.attr("tabindex")) self.win.attr({"tabindex":tabindexcounter++});
    1488            
    1489             self.jqbind(self.win,"focus",function(e) {
    1490               domfocus = (self.getTarget(e)).id||true;
    1491               self.hasfocus = true;
    1492               if (self.canshowonmouseevent) self.noticeCursor();
    1493             });
    1494             self.jqbind(self.win,"blur",function(e) {
    1495               domfocus = false;
    1496               self.hasfocus = false;
    1497             });
    1498            
    1499             self.jqbind(self.win,"mouseenter",function(e) {
    1500               mousefocus = (self.getTarget(e)).id||true;
    1501               self.hasmousefocus = true;
    1502               if (self.canshowonmouseevent) self.noticeCursor();
    1503             });
    1504             self.jqbind(self.win,"mouseleave",function() {
    1505               mousefocus = false;
    1506               self.hasmousefocus = false;
    1507             });
    1508            
    1509           };
    1510          
    1511         }  // !ie9mobile
    1512        
     1808            self.bind(self.rail, "mousedown", function (e) { e.preventDefault(); });  // prevent text selection             
     1809            self.railh && self.bind(self.railh, "mousedown", function (e) { e.preventDefault(); });
     1810          }
     1811
     1812        }
     1813
     1814
     1815        if (opt.enablemousewheel) {
     1816          if (!self.isiframe) self.mousewheel((cap.isie && self.ispage) ? _doc : self.win, self.onmousewheel);
     1817          self.mousewheel(self.rail, self.onmousewheel);
     1818          if (self.railh) self.mousewheel(self.railh, self.onmousewheelhr);
     1819        }
     1820
     1821        if (!self.ispage && !cap.cantouch && !(/HTML|^BODY/.test(self.win[0].nodeName))) {
     1822          if (!self.win.attr("tabindex")) self.win.attr({
     1823            "tabindex": ++tabindexcounter
     1824          });
     1825
     1826          self.bind(self.win, "focus", function (e) {  // better using native events
     1827            domfocus = (self.getTarget(e)).id || self.getTarget(e) || false;
     1828            self.hasfocus = true;
     1829            if (self.canshowonmouseevent) self.noticeCursor();
     1830          });
     1831          self.bind(self.win, "blur", function (e) {  // *
     1832            domfocus = false;
     1833            self.hasfocus = false;
     1834          });
     1835
     1836          self.bind(self.win, "mouseenter", function (e) {   // *
     1837            mousefocus = (self.getTarget(e)).id || self.getTarget(e) || false;
     1838            self.hasmousefocus = true;
     1839            if (self.canshowonmouseevent) self.noticeCursor();
     1840          });
     1841          self.bind(self.win, "mouseleave", function (e) {   // *       
     1842            mousefocus = false;
     1843            self.hasmousefocus = false;
     1844            if (!self.rail.drag) self.hideCursor();
     1845          });
     1846
     1847        }
     1848
     1849
    15131850        //Thanks to http://www.quirksmode.org !!
    1514         self.onkeypress = function(e) {
    1515           if (self.locked&&self.page.maxh==0) return true;
    1516          
    1517           e = (e) ? e : window.e;
     1851        self.onkeypress = function (e) {
     1852          if (self.railslocked && self.page.maxh === 0) return true;
     1853
     1854          e = e || _win.event;
    15181855          var tg = self.getTarget(e);
    1519           if (tg&&/INPUT|TEXTAREA|SELECT|OPTION/.test(tg.nodeName)) {
    1520             var tp = tg.getAttribute('type')||tg.type||false;           
    1521             if ((!tp)||!(/submit|button|cancel/i.tp)) return true;
    1522           }
    1523          
    1524           if (self.hasfocus||(self.hasmousefocus&&!domfocus)||(self.ispage&&!domfocus&&!mousefocus)) {
     1856          if (tg && /INPUT|TEXTAREA|SELECT|OPTION/.test(tg.nodeName)) {
     1857            var tp = tg.getAttribute('type') || tg.type || false;
     1858            if ((!tp) || !(/submit|button|cancel/i.tp)) return true;
     1859          }
     1860
     1861          if ($(tg).attr('contenteditable')) return true;
     1862
     1863          if (self.hasfocus || (self.hasmousefocus && !domfocus) || (self.ispage && !domfocus && !mousefocus)) {
    15251864            var key = e.keyCode;
    1526            
    1527             if (self.locked&&key!=27) return self.cancelEvent(e);
    1528 
    1529             var ctrl = e.ctrlKey||false;
     1865
     1866            if (self.railslocked && key != 27) return self.cancelEvent(e);
     1867
     1868            var ctrl = e.ctrlKey || false;
    15301869            var shift = e.shiftKey || false;
    1531            
     1870
    15321871            var ret = false;
    15331872            switch (key) {
    15341873              case 38:
    15351874              case 63233: //safari
    1536                 self.doScrollBy(24*3);
     1875                self.doScrollBy(24 * 3);
    15371876                ret = true;
    15381877                break;
    15391878              case 40:
    15401879              case 63235: //safari
    1541                 self.doScrollBy(-24*3);
     1880                self.doScrollBy(-24 * 3);
    15421881                ret = true;
    15431882                break;
     
    15451884              case 63232: //safari
    15461885                if (self.railh) {
    1547                   (ctrl) ? self.doScrollLeft(0) : self.doScrollLeftBy(24*3);
     1886                  (ctrl) ? self.doScrollLeft(0) : self.doScrollLeftBy(24 * 3);
    15481887                  ret = true;
    15491888                }
     
    15521891              case 63234: //safari
    15531892                if (self.railh) {
    1554                   (ctrl) ? self.doScrollLeft(self.page.maxw) : self.doScrollLeftBy(-24*3);
     1893                  (ctrl) ? self.doScrollLeft(self.page.maxw) : self.doScrollLeftBy(-24 * 3);
    15551894                  ret = true;
    15561895                }
     
    15681907              case 36:
    15691908              case 63273: // safari               
    1570                 (self.railh&&ctrl) ? self.doScrollPos(0,0) : self.doScrollTo(0);
     1909                (self.railh && ctrl) ? self.doScrollPos(0, 0) : self.doScrollTo(0);
    15711910                ret = true;
    15721911                break;
    15731912              case 35:
    15741913              case 63275: // safari
    1575                 (self.railh&&ctrl) ? self.doScrollPos(self.page.maxw,self.page.maxh) : self.doScrollTo(self.page.maxh);
     1914                (self.railh && ctrl) ? self.doScrollPos(self.page.maxw, self.page.maxh) : self.doScrollTo(self.page.maxh);
    15761915                ret = true;
    15771916                break;
    15781917              case 32:
    1579                 if (self.opt.spacebarenabled) {
     1918                if (opt.spacebarenabled) {
    15801919                  (shift) ? self.doScrollBy(self.view.h) : self.doScrollBy(-self.view.h);
    15811920                  ret = true;
     
    15921931          }
    15931932        };
    1594        
    1595         if (self.opt.enablekeyboard) self.bind(document,(cap.isopera&&!cap.isopera12)?"keypress":"keydown",self.onkeypress);
    1596        
    1597         self.bind(window,'resize',self.lazyResize);
    1598         self.bind(window,'orientationchange',self.lazyResize);
    1599        
    1600         self.bind(window,"load",self.lazyResize);
    1601        
    1602         if (cap.ischrome&&!self.ispage&&!self.haswrapper) { //chrome void scrollbar bug - it persists in version 26
    1603           var tmp=self.win.attr("style");
    1604                     var ww = parseFloat(self.win.css("width"))+1;
    1605           self.win.css('width',ww);
    1606           self.synched("chromefix",function(){self.win.attr("style",tmp)});
    1607         }
    1608        
    1609        
    1610 // Trying a cross-browser implementation - good luck!
    1611 
    1612         self.onAttributeChange = function(e) {
    1613           self.lazyResize(250);
    1614         }
    1615        
    1616         if (!self.ispage&&!self.haswrapper) {
    1617           // redesigned MutationObserver for Chrome18+/Firefox14+/iOS6+ with support for: remove div, add/remove content
    1618           if (clsMutationObserver !== false) {
    1619             self.observer = new clsMutationObserver(function(mutations) {           
    1620               mutations.forEach(self.onAttributeChange);
     1933
     1934        if (opt.enablekeyboard) self.bind(_doc, (cap.isopera && !cap.isopera12) ? "keypress" : "keydown", self.onkeypress);
     1935
     1936        self.bind(_doc, "keydown", function (e) {
     1937          var ctrl = e.ctrlKey || false;
     1938          if (ctrl) self.wheelprevented = true;
     1939        });
     1940        self.bind(_doc, "keyup", function (e) {
     1941          var ctrl = e.ctrlKey || false;
     1942          if (!ctrl) self.wheelprevented = false;
     1943        });
     1944        self.bind(_win, "blur", function (e) {
     1945          self.wheelprevented = false;
     1946        });
     1947
     1948        self.bind(_win, 'resize', self.onscreenresize);
     1949        self.bind(_win, 'orientationchange', self.onscreenresize);
     1950
     1951        self.bind(_win, "load", self.lazyResize);
     1952
     1953        if (cap.ischrome && !self.ispage && !self.haswrapper) { //chrome void scrollbar bug - it persists in version 26
     1954          var tmp = self.win.attr("style");
     1955          var ww = parseFloat(self.win.css("width")) + 1;
     1956          self.win.css('width', ww);
     1957          self.synched("chromefix", function () {
     1958            self.win.attr("style", tmp);
     1959          });
     1960        }
     1961
     1962
     1963        // Trying a cross-browser implementation - good luck!
     1964
     1965        self.onAttributeChange = function (e) {
     1966          self.lazyResize(self.isieold ? 250 : 30);
     1967        };
     1968
     1969        if (opt.enableobserver) {
     1970
     1971          if ((!self.isie11) && (ClsMutationObserver !== false)) {  // IE11 crashes  #568
     1972            self.observerbody = new ClsMutationObserver(function (mutations) {
     1973              mutations.forEach(function (mut) {
     1974                if (mut.type == "attributes") {
     1975                  return ($body.hasClass("modal-open") && $body.hasClass("modal-dialog") && !$.contains($('.modal-dialog')[0], self.doc[0])) ? self.hide() : self.show();  // Support for Bootstrap modal; Added check if the nice scroll element is inside a modal
     1976                }
     1977              });
     1978              if (self.me.clientWidth != self.page.width || self.me.clientHeight != self.page.height) return self.lazyResize(30);
    16211979            });
    1622             self.observer.observe(self.win[0],{childList: true, characterData: false, attributes: true, subtree: false});
    1623            
    1624             self.observerremover = new clsMutationObserver(function(mutations) {
    1625                mutations.forEach(function(mo){
    1626                  if (mo.removedNodes.length>0) {
    1627                    for (var dd in mo.removedNodes) {
    1628                      if (mo.removedNodes[dd]==self.win[0]) return self.remove();
    1629                    }
    1630                  }
    1631                });
     1980            self.observerbody.observe(_doc.body, {
     1981              childList: true,
     1982              subtree: true,
     1983              characterData: false,
     1984              attributes: true,
     1985              attributeFilter: ['class']
    16321986            });
    1633             self.observerremover.observe(self.win[0].parentNode,{childList: true, characterData: false, attributes: false, subtree: false});
    1634            
    1635           } else {       
    1636             self.bind(self.win,(cap.isie&&!cap.isie9)?"propertychange":"DOMAttrModified",self.onAttributeChange);           
    1637             if (cap.isie9) self.win[0].attachEvent("onpropertychange",self.onAttributeChange); //IE9 DOMAttrModified bug
    1638             self.bind(self.win,"DOMNodeRemoved",function(e){
    1639               if (e.target==self.win[0]) self.remove();
     1987          }
     1988
     1989          if (!self.ispage && !self.haswrapper) {
     1990
     1991            var _dom = self.win[0];
     1992
     1993            // redesigned MutationObserver for Chrome18+/Firefox14+/iOS6+ with support for: remove div, add/remove content
     1994            if (ClsMutationObserver !== false) {
     1995              self.observer = new ClsMutationObserver(function (mutations) {
     1996                mutations.forEach(self.onAttributeChange);
     1997              });
     1998              self.observer.observe(_dom, {
     1999                childList: true,
     2000                characterData: false,
     2001                attributes: true,
     2002                subtree: false
     2003              });
     2004              self.observerremover = new ClsMutationObserver(function (mutations) {
     2005                mutations.forEach(function (mo) {
     2006                  if (mo.removedNodes.length > 0) {
     2007                    for (var dd in mo.removedNodes) {
     2008                      if (!!self && (mo.removedNodes[dd] === _dom)) return self.remove();
     2009                    }
     2010                  }
     2011                });
     2012              });
     2013              self.observerremover.observe(_dom.parentNode, {
     2014                childList: true,
     2015                characterData: false,
     2016                attributes: false,
     2017                subtree: false
     2018              });
     2019            } else {
     2020              self.bind(_dom, (cap.isie && !cap.isie9) ? "propertychange" : "DOMAttrModified", self.onAttributeChange);
     2021              if (cap.isie9) _dom.attachEvent("onpropertychange", self.onAttributeChange); //IE9 DOMAttrModified bug
     2022              self.bind(_dom, "DOMNodeRemoved", function (e) {
     2023                if (e.target === _dom) self.remove();
     2024              });
     2025            }
     2026          }
     2027
     2028        }
     2029
     2030        //
     2031
     2032        if (!self.ispage && opt.boxzoom) self.bind(_win, "resize", self.resizeZoom);
     2033        if (self.istextarea) {
     2034          self.bind(self.win, "keydown", self.lazyResize);
     2035          self.bind(self.win, "mouseup", self.lazyResize);
     2036        }
     2037
     2038        self.lazyResize(30);
     2039
     2040      }
     2041
     2042      if (this.doc[0].nodeName == 'IFRAME') {
     2043        var oniframeload = function () {
     2044          self.iframexd = false;
     2045          var doc;
     2046          try {
     2047            doc = 'contentDocument' in this ? this.contentDocument : this.contentWindow._doc;
     2048            var a = doc.domain;
     2049          } catch (e) {
     2050            self.iframexd = true;
     2051            doc = false;
     2052          }
     2053
     2054          if (self.iframexd) {
     2055            if ("console" in _win) console.log('NiceScroll error: policy restriced iframe');
     2056            return true; //cross-domain - I can't manage this       
     2057          }
     2058
     2059          self.forcescreen = true;
     2060
     2061          if (self.isiframe) {
     2062            self.iframe = {
     2063              "doc": $(doc),
     2064              "html": self.doc.contents().find('html')[0],
     2065              "body": self.doc.contents().find('body')[0]
     2066            };
     2067            self.getContentSize = function () {
     2068              return {
     2069                w: Math.max(self.iframe.html.scrollWidth, self.iframe.body.scrollWidth),
     2070                h: Math.max(self.iframe.html.scrollHeight, self.iframe.body.scrollHeight)
     2071              };
     2072            };
     2073            self.docscroll = $(self.iframe.body);
     2074          }
     2075
     2076          if (!cap.isios && opt.iframeautoresize && !self.isiframe) {
     2077            self.win.scrollTop(0); // reset position
     2078            self.doc.height(""); //reset height to fix browser bug
     2079            var hh = Math.max(doc.getElementsByTagName('html')[0].scrollHeight, doc.body.scrollHeight);
     2080            self.doc.height(hh);
     2081          }
     2082          self.lazyResize(30);
     2083
     2084          self.css($(self.iframe.body), _scrollyhidden);
     2085
     2086          if (cap.isios && self.haswrapper) {
     2087            self.css($(doc.body), {
     2088              '-webkit-transform': 'translate3d(0,0,0)'
     2089            }); // avoid iFrame content clipping - thanks to http://blog.derraab.com/2012/04/02/avoid-iframe-content-clipping-with-css-transform-on-ios/
     2090          }
     2091
     2092          if ('contentWindow' in this) {
     2093            self.bind(this.contentWindow, "scroll", self.onscroll); //IE8 & minor
     2094          } else {
     2095            self.bind(doc, "scroll", self.onscroll);
     2096          }
     2097
     2098          if (opt.enablemousewheel) {
     2099            self.mousewheel(doc, self.onmousewheel);
     2100          }
     2101
     2102          if (opt.enablekeyboard) self.bind(doc, (cap.isopera) ? "keypress" : "keydown", self.onkeypress);
     2103
     2104          if (cap.cantouch) {
     2105            self.bind(doc, "touchstart", self.ontouchstart);
     2106            self.bind(doc, "touchmove", self.ontouchmove);
     2107          }
     2108          else if (opt.emulatetouch) {
     2109            self.bind(doc, "mousedown", self.ontouchstart);
     2110            self.bind(doc, "mousemove", function (e) {
     2111              return self.ontouchmove(e, true);
    16402112            });
    1641           }
    1642         }
    1643        
    1644 //
    1645 
    1646         if (!self.ispage&&self.opt.boxzoom) self.bind(window,"resize",self.resizeZoom);
    1647         if (self.istextarea) self.bind(self.win,"mouseup",self.lazyResize);
    1648        
    1649         self.checkrtlmode = true;
    1650         self.lazyResize(30);
    1651        
    1652       }
    1653      
    1654       if (this.doc[0].nodeName == 'IFRAME') {
    1655         function oniframeload(e) {
    1656           self.iframexd = false;
    1657           try {
    1658             var doc = 'contentDocument' in this ? this.contentDocument : this.contentWindow.document;
    1659             var a = doc.domain;           
    1660           } catch(e){self.iframexd = true;doc=false};
    1661          
    1662           if (self.iframexd) {
    1663             if ("console" in window) console.log('NiceScroll error: policy restriced iframe');
    1664             return true;  //cross-domain - I can't manage this       
    1665           }
    1666          
    1667           self.forcescreen = true;
    1668          
    1669           if (self.isiframe) {           
    1670             self.iframe = {
    1671               "doc":$(doc),
    1672               "html":self.doc.contents().find('html')[0],
    1673               "body":self.doc.contents().find('body')[0]
    1674             };
    1675             self.getContentSize = function(){
    1676               return {
    1677                 w:Math.max(self.iframe.html.scrollWidth,self.iframe.body.scrollWidth),
    1678                 h:Math.max(self.iframe.html.scrollHeight,self.iframe.body.scrollHeight)
    1679               }
    1680             }           
    1681             self.docscroll = $(self.iframe.body);//$(this.contentWindow);
    1682           }
    1683          
    1684           if (!cap.isios&&self.opt.iframeautoresize&&!self.isiframe) {
    1685             self.win.scrollTop(0); // reset position
    1686             self.doc.height("");  //reset height to fix browser bug
    1687             var hh=Math.max(doc.getElementsByTagName('html')[0].scrollHeight,doc.body.scrollHeight);
    1688             self.doc.height(hh);         
    1689           }
    1690           self.lazyResize(30);
    1691          
    1692           if (cap.isie7) self.css($(self.iframe.html),{'overflow-y':'hidden'});
    1693           //self.css($(doc.body),{'overflow-y':'hidden'});
    1694           self.css($(self.iframe.body),{'overflow-y':'hidden'});
    1695          
    1696           if ('contentWindow' in this) {
    1697             self.bind(this.contentWindow,"scroll",self.onscroll);  //IE8 & minor
    1698           } else {         
    1699             self.bind(doc,"scroll",self.onscroll);
    1700           }                   
    1701          
    1702           if (self.opt.enablemousewheel) {
    1703             self.bind(doc,"mousewheel",self.onmousewheel);
    1704           }
    1705          
    1706           if (self.opt.enablekeyboard) self.bind(doc,(cap.isopera)?"keypress":"keydown",self.onkeypress);
    1707          
    1708           if (cap.cantouch||self.opt.touchbehavior) {
    1709             self.bind(doc,"mousedown",self.onmousedown);
    1710             self.bind(doc,"mousemove",function(e){self.onmousemove(e,true)});
    1711             if (self.opt.grabcursorenabled&&cap.cursorgrabvalue) self.css($(doc.body),{'cursor':cap.cursorgrabvalue});
    1712           }
    1713          
    1714           self.bind(doc,"mouseup",self.onmouseup);
    1715          
     2113            if (opt.grabcursorenabled && cap.cursorgrabvalue) self.css($(doc.body), {
     2114              'cursor': cap.cursorgrabvalue
     2115            });
     2116          }
     2117
     2118          self.bind(doc, "mouseup", self.ontouchend);
     2119
    17162120          if (self.zoom) {
    1717             if (self.opt.dblclickzoom) self.bind(doc,'dblclick',self.doZoom);
    1718             if (self.ongesturezoom) self.bind(doc,"gestureend",self.ongesturezoom);             
     2121            if (opt.dblclickzoom) self.bind(doc, 'dblclick', self.doZoom);
     2122            if (self.ongesturezoom) self.bind(doc, "gestureend", self.ongesturezoom);
    17192123          }
    17202124        };
    1721        
    1722         if (this.doc[0].readyState&&this.doc[0].readyState=="complete"){
    1723           setTimeout(function(){oniframeload.call(self.doc[0],false)},500);
    1724         }
    1725         self.bind(this.doc,"load",oniframeload);
    1726        
    1727       }
    1728      
    1729     };
    1730    
    1731     this.showCursor = function(py,px) {
     2125
     2126        if (this.doc[0].readyState && this.doc[0].readyState === "complete") {
     2127          setTimeout(function () {
     2128            oniframeload.call(self.doc[0], false);
     2129          }, 500);
     2130        }
     2131        self.bind(this.doc, "load", oniframeload);
     2132
     2133      }
     2134
     2135    };
     2136
     2137    this.showCursor = function (py, px) {
    17322138      if (self.cursortimeout) {
    17332139        clearTimeout(self.cursortimeout);
     
    17362142      if (!self.rail) return;
    17372143      if (self.autohidedom) {
    1738         self.autohidedom.stop().css({opacity:self.opt.cursoropacitymax});
     2144        self.autohidedom.stop().css({
     2145          opacity: opt.cursoropacitymax
     2146        });
    17392147        self.cursoractive = true;
    17402148      }
    1741      
    1742       if (!self.rail.drag||self.rail.drag.pt!=1) {     
    1743         if ((typeof py != "undefined")&&(py!==false)) {
    1744           self.scroll.y = Math.round(py * 1/self.scrollratio.y);
    1745         }
    1746         if (typeof px != "undefined") {
    1747           self.scroll.x = Math.round(px * 1/self.scrollratio.x);
    1748         }
    1749       }
    1750      
    1751       self.cursor.css({height:self.cursorheight,top:self.scroll.y});
     2149
     2150      if (!self.rail.drag || self.rail.drag.pt != 1) {
     2151        if (py !== undefined && py !== false) {
     2152          self.scroll.y = (py / self.scrollratio.y) | 0;
     2153        }
     2154        if (px !== undefined) {
     2155          self.scroll.x = (px / self.scrollratio.x) | 0;
     2156        }
     2157      }
     2158
     2159      self.cursor.css({
     2160        height: self.cursorheight,
     2161        top: self.scroll.y
     2162      });
    17522163      if (self.cursorh) {
    1753         (!self.rail.align&&self.rail.visibility) ? self.cursorh.css({width:self.cursorwidth,left:self.scroll.x+self.rail.width}) : self.cursorh.css({width:self.cursorwidth,left:self.scroll.x});
     2164        var lx = (self.hasreversehr) ? self.scrollvaluemaxw - self.scroll.x : self.scroll.x;
     2165        self.cursorh.css({
     2166          width: self.cursorwidth,
     2167          left: (!self.rail.align && self.rail.visibility) ? lx + self.rail.width : lx
     2168        });
    17542169        self.cursoractive = true;
    17552170      }
    1756      
    1757       if (self.zoom) self.zoom.stop().css({opacity:self.opt.cursoropacitymax});     
    1758     };
    1759    
    1760     this.hideCursor = function(tm) {
     2171
     2172      if (self.zoom) self.zoom.stop().css({
     2173        opacity: opt.cursoropacitymax
     2174      });
     2175    };
     2176
     2177    this.hideCursor = function (tm) {
    17612178      if (self.cursortimeout) return;
    17622179      if (!self.rail) return;
    17632180      if (!self.autohidedom) return;
    1764       self.cursortimeout = setTimeout(function() {
    1765          if (!self.rail.active||!self.showonmouseevent) {
    1766            self.autohidedom.stop().animate({opacity:self.opt.cursoropacitymin});
    1767            if (self.zoom) self.zoom.stop().animate({opacity:self.opt.cursoropacitymin});
    1768            self.cursoractive = false;
    1769          }
    1770          self.cursortimeout = 0;
    1771       },tm||self.opt.hidecursordelay);
    1772     };
    1773    
    1774     this.noticeCursor = function(tm,py,px) {
    1775       self.showCursor(py,px);
     2181
     2182      if (self.hasmousefocus && opt.autohidemode === "leave") return;
     2183      self.cursortimeout = setTimeout(function () {
     2184        if (!self.rail.active || !self.showonmouseevent) {
     2185          self.autohidedom.stop().animate({
     2186            opacity: opt.cursoropacitymin
     2187          });
     2188          if (self.zoom) self.zoom.stop().animate({
     2189            opacity: opt.cursoropacitymin
     2190          });
     2191          self.cursoractive = false;
     2192        }
     2193        self.cursortimeout = 0;
     2194      }, tm || opt.hidecursordelay);
     2195    };
     2196
     2197    this.noticeCursor = function (tm, py, px) {
     2198      self.showCursor(py, px);
    17762199      if (!self.rail.active) self.hideCursor(tm);
    17772200    };
    1778        
    1779     this.getContentSize = 
     2201
     2202    this.getContentSize =
    17802203      (self.ispage) ?
    1781         function(){
     2204        function () {
    17822205          return {
    1783             w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
    1784             h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
    1785           }
    1786         }
    1787       : (self.haswrapper) ?
    1788         function(){
    1789           return {
    1790             w:self.doc.outerWidth()+parseInt(self.win.css('paddingLeft'))+parseInt(self.win.css('paddingRight')),
    1791             h:self.doc.outerHeight()+parseInt(self.win.css('paddingTop'))+parseInt(self.win.css('paddingBottom'))
    1792           }
    1793         }
    1794       : function() {       
    1795         return {
    1796           w:self.docscroll[0].scrollWidth,
    1797           h:self.docscroll[0].scrollHeight
    1798         }
     2206            w: Math.max(_doc.body.scrollWidth, _doc.documentElement.scrollWidth),
     2207            h: Math.max(_doc.body.scrollHeight, _doc.documentElement.scrollHeight)
     2208          };
     2209        } : (self.haswrapper) ?
     2210          function () {
     2211            return {
     2212              w: self.doc[0].offsetWidth,
     2213              h: self.doc[0].offsetHeight
     2214            };
     2215          } : function () {
     2216            return {
     2217              w: self.docscroll[0].scrollWidth,
     2218              h: self.docscroll[0].scrollHeight
     2219            };
     2220          };
     2221
     2222    this.onResize = function (e, page) {
     2223
     2224      if (!self || !self.win) return false;
     2225
     2226      var premaxh = self.page.maxh,
     2227          premaxw = self.page.maxw,
     2228          previewh = self.view.h,
     2229          previeww = self.view.w;
     2230
     2231      self.view = {
     2232        w: (self.ispage) ? self.win.width() : self.win[0].clientWidth,
     2233        h: (self.ispage) ? self.win.height() : self.win[0].clientHeight
    17992234      };
    1800  
    1801     this.onResize = function(e,page) {
    1802    
    1803       if (!self.win) return false;
    1804    
    1805       if (!self.haswrapper&&!self.ispage) {
    1806         if (self.win.css('display')=='none') {
    1807           if (self.visibility) self.hideRail().hideRailHr();
    1808           return false;
    1809         } else {         
    1810           if (!self.hidden&&!self.visibility) self.showRail().showRailHr();
    1811         }       
    1812       }
    1813    
    1814       var premaxh = self.page.maxh;
    1815       var premaxw = self.page.maxw;
    1816 
    1817       var preview = {h:self.view.h,w:self.view.w};   
    1818      
    1819       self.view = {
    1820         w:(self.ispage) ? self.win.width() : parseInt(self.win[0].clientWidth),
    1821         h:(self.ispage) ? self.win.height() : parseInt(self.win[0].clientHeight)
    1822       };
    1823      
     2235
    18242236      self.page = (page) ? page : self.getContentSize();
    1825      
    1826       self.page.maxh = Math.max(0,self.page.h - self.view.h);
    1827       self.page.maxw = Math.max(0,self.page.w - self.view.w);
    1828      
    1829       if ((self.page.maxh==premaxh)&&(self.page.maxw==premaxw)&&(self.view.w==preview.w)) {
     2237
     2238      self.page.maxh = Math.max(0, self.page.h - self.view.h);
     2239      self.page.maxw = Math.max(0, self.page.w - self.view.w);
     2240
     2241      if ((self.page.maxh == premaxh) && (self.page.maxw == premaxw) && (self.view.w == previeww) && (self.view.h == previewh)) {
    18302242        // test position       
    18312243        if (!self.ispage) {
     
    18332245          if (self.lastposition) {
    18342246            var lst = self.lastposition;
    1835             if ((lst.top==pos.top)&&(lst.left==pos.left)) return self; //nothing to do           
     2247            if ((lst.top == pos.top) && (lst.left == pos.left)) return self; //nothing to do           
    18362248          }
    18372249          self.lastposition = pos;
     
    18402252        }
    18412253      }
    1842      
    1843       if (self.page.maxh==0) {
    1844         self.hideRail();       
     2254
     2255      if (self.page.maxh === 0) {
     2256        self.hideRail();
    18452257        self.scrollvaluemax = 0;
    18462258        self.scroll.y = 0;
     
    18482260        self.cursorheight = 0;
    18492261        self.setScrollTop(0);
    1850         self.rail.scrollable = false;
    1851       } else {       
     2262        if (self.rail) self.rail.scrollable = false;
     2263      } else {
     2264        self.page.maxh -= (opt.railpadding.top + opt.railpadding.bottom);
    18522265        self.rail.scrollable = true;
    18532266      }
    1854      
    1855       if (self.page.maxw==0) {
     2267
     2268      if (self.page.maxw === 0) {
    18562269        self.hideRailHr();
    18572270        self.scrollvaluemaxw = 0;
     
    18602273        self.cursorwidth = 0;
    18612274        self.setScrollLeft(0);
    1862         self.railh.scrollable = false;
    1863       } else {       
    1864         self.railh.scrollable = true;
    1865       }
    1866  
    1867       self.locked = (self.page.maxh==0)&&(self.page.maxw==0);
    1868       if (self.locked) {
    1869                 if (!self.ispage) self.updateScrollBar(self.view);
    1870               return false;
    1871           }
    1872 
    1873       if (!self.hidden&&!self.visibility) {
    1874         self.showRail().showRailHr();
    1875       }     
    1876       else if (!self.hidden&&!self.railh.visibility) self.showRailHr();
    1877      
    1878       if (self.istextarea&&self.win.css('resize')&&self.win.css('resize')!='none') self.view.h-=20;     
    1879 
    1880       self.cursorheight = Math.min(self.view.h,Math.round(self.view.h * (self.view.h / self.page.h)));
    1881       self.cursorheight = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight,self.cursorheight);
    1882 
    1883       self.cursorwidth = Math.min(self.view.w,Math.round(self.view.w * (self.view.w / self.page.w)));
    1884       self.cursorwidth = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight,self.cursorwidth);
    1885      
    1886       self.scrollvaluemax = self.view.h-self.cursorheight-self.cursor.hborder;
    1887      
     2275        if (self.railh) {
     2276          self.railh.scrollable = false;
     2277        }
     2278      } else {
     2279        self.page.maxw -= (opt.railpadding.left + opt.railpadding.right);
     2280        if (self.railh) self.railh.scrollable = (opt.horizrailenabled);
     2281      }
     2282
     2283      self.railslocked = (self.locked) || ((self.page.maxh === 0) && (self.page.maxw === 0));
     2284      if (self.railslocked) {
     2285        if (!self.ispage) self.updateScrollBar(self.view);
     2286        return false;
     2287      }
     2288
     2289      if (!self.hidden) {
     2290        if (!self.rail.visibility) self.showRail();
     2291        if (self.railh && !self.railh.visibility) self.showRailHr();
     2292      }
     2293
     2294      if (self.istextarea && self.win.css('resize') && self.win.css('resize') != 'none') self.view.h -= 20;
     2295
     2296      self.cursorheight = Math.min(self.view.h, Math.round(self.view.h * (self.view.h / self.page.h)));
     2297      self.cursorheight = (opt.cursorfixedheight) ? opt.cursorfixedheight : Math.max(opt.cursorminheight, self.cursorheight);
     2298
     2299      self.cursorwidth = Math.min(self.view.w, Math.round(self.view.w * (self.view.w / self.page.w)));
     2300      self.cursorwidth = (opt.cursorfixedheight) ? opt.cursorfixedheight : Math.max(opt.cursorminheight, self.cursorwidth);
     2301
     2302      self.scrollvaluemax = self.view.h - self.cursorheight - (opt.railpadding.top + opt.railpadding.bottom);
     2303      if (!self.hasborderbox) self.scrollvaluemax -= self.cursor[0].offsetHeight - self.cursor[0].clientHeight;
     2304
    18882305      if (self.railh) {
    1889         self.railh.width = (self.page.maxh>0) ? (self.view.w-self.rail.width) : self.view.w;
    1890         self.scrollvaluemaxw = self.railh.width-self.cursorwidth-self.cursorh.wborder;
    1891       }
    1892      
    1893       if (self.checkrtlmode&&self.railh) {
    1894         self.checkrtlmode = false;
    1895         if (self.opt.rtlmode&&self.scroll.x==0) self.setScrollLeft(self.page.maxw);
    1896       }
    1897      
     2306        self.railh.width = (self.page.maxh > 0) ? (self.view.w - self.rail.width) : self.view.w;
     2307        self.scrollvaluemaxw = self.railh.width - self.cursorwidth - (opt.railpadding.left + opt.railpadding.right);
     2308      }
     2309
    18982310      if (!self.ispage) self.updateScrollBar(self.view);
    1899      
     2311
    19002312      self.scrollratio = {
    1901         x:(self.page.maxw/self.scrollvaluemaxw),
    1902         y:(self.page.maxh/self.scrollvaluemax)
     2313        x: (self.page.maxw / self.scrollvaluemaxw),
     2314        y: (self.page.maxh / self.scrollvaluemax)
    19032315      };
    1904      
     2316
    19052317      var sy = self.getScrollTop();
    1906       if (sy>self.page.maxh) {
     2318      if (sy > self.page.maxh) {
    19072319        self.doScrollTop(self.page.maxh);
    1908       } else {     
    1909         self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
    1910         self.scroll.x = Math.round(self.getScrollLeft() * (1/self.scrollratio.x));
    1911         if (self.cursoractive) self.noticeCursor();     
    1912       }     
    1913      
    1914       if (self.scroll.y&&(self.getScrollTop()==0)) self.doScrollTo(Math.floor(self.scroll.y*self.scrollratio.y));
    1915      
     2320      } else {
     2321        self.scroll.y = (self.getScrollTop() / self.scrollratio.y) | 0;
     2322        self.scroll.x = (self.getScrollLeft() / self.scrollratio.x) | 0;
     2323        if (self.cursoractive) self.noticeCursor();
     2324      }
     2325
     2326      if (self.scroll.y && (self.getScrollTop() === 0)) self.doScrollTo((self.scroll.y * self.scrollratio.y)|0);
     2327
    19162328      return self;
    19172329    };
    1918    
     2330
    19192331    this.resize = self.onResize;
    1920    
    1921     this.lazyResize = function(tm) {   // event debounce
    1922       tm = (isNaN(tm)) ? 30 : tm;
    1923       self.delayed('resize',self.resize,tm);
     2332
     2333    var hlazyresize = 0;
     2334
     2335    this.onscreenresize = function(e) {
     2336      clearTimeout(hlazyresize);
     2337
     2338      var hiderails = (!self.ispage && !self.haswrapper);
     2339      if (hiderails) self.hideRails();
     2340
     2341      hlazyresize = setTimeout(function () {
     2342        if (self) {
     2343          if (hiderails) self.showRails();
     2344          self.resize();
     2345        }
     2346        hlazyresize=0;
     2347      }, 120);
     2348    };
     2349
     2350    this.lazyResize = function (tm) { // event debounce
     2351
     2352      clearTimeout(hlazyresize);
     2353
     2354      tm = isNaN(tm) ? 240 : tm;
     2355
     2356      hlazyresize = setTimeout(function () {
     2357        self && self.resize();
     2358        hlazyresize=0;
     2359      }, tm);
     2360
    19242361      return self;
    1925     }
    1926    
    1927 // modified by MDN https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/wheel
    1928     function _modernWheelEvent(dom,name,fn,bubble) {     
    1929       self._bind(dom,name,function(e){
    1930         var  e = (e) ? e : window.event;
     2362
     2363    };
     2364
     2365    // derived by MDN https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/wheel
     2366    function _modernWheelEvent(dom, name, fn, bubble) {
     2367      self._bind(dom, name, function (e) {
     2368        e = e || _win.event;
    19312369        var event = {
    19322370          original: e,
     
    19362374          deltaX: 0,
    19372375          deltaZ: 0,
    1938           preventDefault: function() {
     2376          preventDefault: function () {
    19392377            e.preventDefault ? e.preventDefault() : e.returnValue = false;
    19402378            return false;
    19412379          },
    1942           stopImmediatePropagation: function() {
     2380          stopImmediatePropagation: function () {
    19432381            (e.stopImmediatePropagation) ? e.stopImmediatePropagation() : e.cancelBubble = true;
    19442382          }
    19452383        };
    1946            
    1947         if (name=="mousewheel") {
    1948           event.deltaY = - 1/40 * e.wheelDelta;
    1949           e.wheelDeltaX && (event.deltaX = - 1/40 * e.wheelDeltaX);
     2384
     2385        if (name == "mousewheel") {
     2386          e.wheelDeltaX && (event.deltaX = -1 / 40 * e.wheelDeltaX);
     2387          e.wheelDeltaY && (event.deltaY = -1 / 40 * e.wheelDeltaY);
     2388          !event.deltaY && !event.deltaX && (event.deltaY = -1 / 40 * e.wheelDelta);
    19502389        } else {
    19512390          event.deltaY = e.detail;
    19522391        }
    19532392
    1954         return fn.call(dom,event);     
    1955       },bubble);
    1956     };     
    1957    
    1958     this._bind = function(el,name,fn,bubble) {  // primitive bind
    1959       self.events.push({e:el,n:name,f:fn,b:bubble,q:false});
    1960       if (el.addEventListener) {
    1961         el.addEventListener(name,fn,bubble||false);
    1962       }
    1963       else if (el.attachEvent) {
    1964         el.attachEvent("on"+name,fn);
    1965       }
    1966       else {
    1967         el["on"+name] = fn;       
    1968       }       
    1969     };
    1970    
    1971     this.jqbind = function(dom,name,fn) {  // use jquery bind for non-native events (mouseenter/mouseleave)
    1972       self.events.push({e:dom,n:name,f:fn,q:true});
    1973       $(dom).bind(name,fn);
     2393        return fn.call(dom, event);
     2394      }, bubble);
    19742395    }
    1975    
    1976     this.bind = function(dom,name,fn,bubble) {  // touch-oriented & fixing jquery bind
     2396
     2397
     2398
     2399    this.jqbind = function (dom, name, fn) { // use jquery bind for non-native events (mouseenter/mouseleave)
     2400      self.events.push({
     2401        e: dom,
     2402        n: name,
     2403        f: fn,
     2404        q: true
     2405      });
     2406      $(dom).on(name, fn);
     2407    };
     2408
     2409    this.mousewheel = function (dom, fn, bubble) { // bind mousewheel
    19772410      var el = ("jquery" in dom) ? dom[0] : dom;
    1978      
    1979       if (name=='mousewheel') {
    1980         if ("onwheel" in self.win) {           
    1981           self._bind(el,"wheel",fn,bubble||false);
    1982         } else {           
    1983           var wname = (typeof document.onmousewheel != "undefined") ? "mousewheel" : "DOMMouseScroll";  // older IE/Firefox
    1984           _modernWheelEvent(el,wname,fn,bubble||false);
    1985           if (wname=="DOMMouseScroll") _modernWheelEvent(el,"MozMousePixelScroll",fn,bubble||false);  // Firefox legacy
    1986         }
    1987       }
    1988       else if (el.addEventListener) {
    1989         if (cap.cantouch && /mouseup|mousedown|mousemove/.test(name)) {  // touch device support
    1990           var tt=(name=='mousedown')?'touchstart':(name=='mouseup')?'touchend':'touchmove';
    1991           self._bind(el,tt,function(e){
    1992             if (e.touches) {
    1993               if (e.touches.length<2) {var ev=(e.touches.length)?e.touches[0]:e;ev.original=e;fn.call(this,ev);}
    1994             }
    1995             else if (e.changedTouches) {var ev=e.changedTouches[0];ev.original=e;fn.call(this,ev);}  //blackberry
    1996           },bubble||false);
    1997         }
    1998         self._bind(el,name,fn,bubble||false);
    1999         if (cap.cantouch && name=="mouseup") self._bind(el,"touchcancel",fn,bubble||false);
    2000       }
    2001       else {
    2002         self._bind(el,name,function(e) {
    2003           e = e||window.event||false;
    2004           if (e) {
    2005             if (e.srcElement) e.target=e.srcElement;
    2006           }
    2007           if (!("pageY" in e)) {
    2008             e.pageX = e.clientX + document.documentElement.scrollLeft;
    2009             e.pageY = e.clientY + document.documentElement.scrollTop;
    2010           }
    2011           return ((fn.call(el,e)===false)||bubble===false) ? self.cancelEvent(e) : true;
    2012         });
    2013       }
    2014     };
    2015    
    2016     this._unbind = function(el,name,fn,bub) {  // primitive unbind
    2017       if (el.removeEventListener) {
    2018         el.removeEventListener(name,fn,bub);
    2019       }
    2020       else if (el.detachEvent) {
    2021         el.detachEvent('on'+name,fn);
     2411      if ("onwheel" in _doc.createElement("div")) { // Modern browsers support "wheel"
     2412        self._bind(el, "wheel", fn, bubble || false);
    20222413      } else {
    2023         el['on'+name] = false;
    2024       }
    2025     };
    2026    
    2027     this.unbindAll = function() {
    2028       for(var a=0;a<self.events.length;a++) {
    2029         var r = self.events[a];       
    2030         (r.q) ? r.e.unbind(r.n,r.f) : self._unbind(r.e,r.n,r.f,r.b);
    2031       }
    2032     };
    2033    
    2034     // Thanks to http://www.switchonthecode.com !!
    2035     this.cancelEvent = function(e) {
    2036       var e = (e.original) ? e.original : (e) ? e : window.event||false;
    2037       if (!e) return false;     
    2038       if(e.preventDefault) e.preventDefault();
    2039       if(e.stopPropagation) e.stopPropagation();
    2040       if(e.preventManipulation) e.preventManipulation();  //IE10
    2041       e.cancelBubble = true;
    2042       e.cancel = true;
    2043       e.returnValue = false;
    2044       return false;
    2045     };
    2046 
    2047     this.stopPropagation = function(e) {
    2048       var e = (e.original) ? e.original : (e) ? e : window.event||false;
    2049       if (!e) return false;
    2050       if (e.stopPropagation) return e.stopPropagation();
    2051       if (e.cancelBubble) e.cancelBubble=true;
    2052       return false;
     2414        var wname = (_doc.onmousewheel !== undefined) ? "mousewheel" : "DOMMouseScroll"; // older Webkit+IE support or older Firefox         
     2415        _modernWheelEvent(el, wname, fn, bubble || false);
     2416        if (wname == "DOMMouseScroll") _modernWheelEvent(el, "MozMousePixelScroll", fn, bubble || false); // Firefox legacy
     2417      }
     2418    };
     2419
     2420    var passiveSupported = false;
     2421
     2422    if (cap.haseventlistener) {  // W3C standard event model
     2423
     2424      // thanks to https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
     2425      try { var options = Object.defineProperty({}, "passive", { get: function () { passiveSupported = !0; } }); _win.addEventListener("test", null, options); } catch (err) { }
     2426
     2427      this.stopPropagation = function (e) {
     2428        if (!e) return false;
     2429        e = (e.original) ? e.original : e;
     2430        e.stopPropagation();
     2431        return false;
     2432      };
     2433
     2434      this.cancelEvent = function(e) {
     2435        if (e.cancelable) e.preventDefault();
     2436        e.stopImmediatePropagation();
     2437        if (e.preventManipulation) e.preventManipulation();  // IE10+
     2438        return false;
     2439      };     
     2440
     2441    } else {
     2442
     2443      // inspired from https://gist.github.com/jonathantneal/2415137     
     2444
     2445      Event.prototype.preventDefault = function () {
     2446        this.returnValue = false;
     2447      };
     2448
     2449      Event.prototype.stopPropagation = function () {
     2450        this.cancelBubble = true;
     2451      };
     2452
     2453      _win.constructor.prototype.addEventListener = _doc.constructor.prototype.addEventListener = Element.prototype.addEventListener = function (type, listener, useCapture) {
     2454        this.attachEvent("on" + type, listener);
     2455      };
     2456      _win.constructor.prototype.removeEventListener = _doc.constructor.prototype.removeEventListener = Element.prototype.removeEventListener = function (type, listener, useCapture) {
     2457        this.detachEvent("on" + type, listener);
     2458      };
     2459
     2460      // Thanks to http://www.switchonthecode.com !!
     2461      this.cancelEvent = function (e) {
     2462        e = e || _win.event;
     2463        if (e) {         
     2464          e.cancelBubble = true;
     2465          e.cancel = true;
     2466          e.returnValue = false;
     2467        } 
     2468        return false;
     2469      };
     2470
     2471      this.stopPropagation = function (e) {
     2472        e = e || _win.event;
     2473        if (e) e.cancelBubble = true;
     2474        return false;
     2475      };
     2476
    20532477    }
    2054    
    2055     this.showRail = function() {
    2056       if ((self.page.maxh!=0)&&(self.ispage||self.win.css('display')!='none')) {
    2057         self.visibility = true;
     2478
     2479    this.delegate = function (dom, name, fn, bubble, active) {
     2480
     2481      var de = delegatevents[name] || false;
     2482
     2483      if (!de) {
     2484
     2485        de = {
     2486          a: [],
     2487          l: [],
     2488          f: function (e) {
     2489            var lst = de.l, l = lst.length - 1;
     2490            var r = false;
     2491            for (var a = l; a >= 0; a--) {
     2492              r = lst[a].call(e.target, e);
     2493              if (r === false) return false;
     2494            }
     2495            return r;
     2496          }
     2497        };
     2498
     2499        self.bind(dom, name, de.f, bubble, active);
     2500
     2501        delegatevents[name] = de;
     2502
     2503      }
     2504
     2505      if (self.ispage) {
     2506        de.a = [self.id].concat(de.a);
     2507        de.l = [fn].concat(de.l);
     2508      } else {
     2509        de.a.push(self.id);
     2510        de.l.push(fn);       
     2511      }
     2512
     2513    };
     2514
     2515    this.undelegate = function (dom, name, fn, bubble, active) {
     2516      var de = delegatevents[name]||false;
     2517      if (de&&de.l) {  // quick fix #683
     2518        for (var a=0,l=de.l.length;a<l;a++) {
     2519          if (de.a[a] === self.id) {
     2520            de.a.splice(a);
     2521            de.l.splice(a);
     2522            if (de.a.length===0) {
     2523              self._unbind(dom,name,de.l.f);
     2524              delegatevents[name] = null;
     2525            }
     2526          }
     2527        }
     2528      }
     2529    };
     2530
     2531    this.bind = function (dom, name, fn, bubble, active) {
     2532      var el = ("jquery" in dom) ? dom[0] : dom;
     2533      self._bind(el, name, fn, bubble || false, active || false);
     2534    };
     2535
     2536    this._bind = function (el, name, fn, bubble, active) { // primitive bind
     2537
     2538      self.events.push({
     2539        e: el,
     2540        n: name,
     2541        f: fn,
     2542        b: bubble,
     2543        q: false
     2544      });
     2545
     2546      (passiveSupported && active) ? el.addEventListener(name, fn, { passive: false, capture: bubble }) : el.addEventListener(name, fn, bubble || false);
     2547    };
     2548
     2549    this._unbind = function (el, name, fn, bub) { // primitive unbind
     2550      if (delegatevents[name]) self.undelegate(el, name, fn, bub);
     2551      else el.removeEventListener(name, fn, bub);
     2552    };
     2553
     2554    this.unbindAll = function () {
     2555      for (var a = 0; a < self.events.length; a++) {
     2556        var r = self.events[a];
     2557        (r.q) ? r.e.unbind(r.n, r.f) : self._unbind(r.e, r.n, r.f, r.b);
     2558      }
     2559    };
     2560
     2561    this.showRails = function () {
     2562      return self.showRail().showRailHr();
     2563    };
     2564
     2565    this.showRail = function () {
     2566      if ((self.page.maxh !== 0) && (self.ispage || self.win.css('display') != 'none')) {
     2567        //self.visibility = true;
    20582568        self.rail.visibility = true;
    2059         self.rail.css('display','block');
     2569        self.rail.css('display', 'block');
    20602570      }
    20612571      return self;
    20622572    };
    20632573
    2064     this.showRailHr = function() {
    2065       if (!self.railh) return self;
    2066       if ((self.page.maxw!=0)&&(self.ispage||self.win.css('display')!='none')) {
    2067         self.railh.visibility = true;
    2068         self.railh.css('display','block');
     2574    this.showRailHr = function () {
     2575      if (self.railh) {
     2576        if ((self.page.maxw !== 0) && (self.ispage || self.win.css('display') != 'none')) {
     2577          self.railh.visibility = true;
     2578          self.railh.css('display', 'block');
     2579        }
    20692580      }
    20702581      return self;
    20712582    };
    2072    
    2073     this.hideRail = function() {
    2074       self.visibility = false;
     2583
     2584    this.hideRails = function () {
     2585      return self.hideRail().hideRailHr();
     2586    };
     2587
     2588    this.hideRail = function () {
     2589      //self.visibility = false;
    20752590      self.rail.visibility = false;
    2076       self.rail.css('display','none');
     2591      self.rail.css('display', 'none');
    20772592      return self;
    20782593    };
    20792594
    2080     this.hideRailHr = function() {
    2081       if (!self.railh) return self;
    2082       self.railh.visibility = false;
    2083       self.railh.css('display','none');
     2595    this.hideRailHr = function () {
     2596      if (self.railh) {
     2597        self.railh.visibility = false;
     2598        self.railh.css('display', 'none');
     2599      }
    20842600      return self;
    20852601    };
    2086    
    2087     this.show = function() {
     2602
     2603    this.show = function () {
    20882604      self.hidden = false;
    2089       self.locked = false;
    2090       return self.showRail().showRailHr();
    2091     };
    2092 
    2093     this.hide = function() {
     2605      self.railslocked = false;
     2606      return self.showRails();
     2607    };
     2608
     2609    this.hide = function () {
    20942610      self.hidden = true;
    2095       self.locked = true;
    2096       return self.hideRail().hideRailHr();
    2097     };
    2098    
    2099     this.toggle = function() {
     2611      self.railslocked = true;
     2612      return self.hideRails();
     2613    };
     2614
     2615    this.toggle = function () {
    21002616      return (self.hidden) ? self.show() : self.hide();
    21012617    };
    2102    
    2103     this.remove = function() {
     2618
     2619    this.remove = function () {
    21042620      self.stop();
    21052621      if (self.cursortimeout) clearTimeout(self.cursortimeout);
     2622      for (var n in self.delaylist) if (self.delaylist[n]) clearAnimationFrame(self.delaylist[n].h);
    21062623      self.doZoomOut();
    2107       self.unbindAll();     
     2624      self.unbindAll();
     2625
     2626      if (cap.isie9) self.win[0].detachEvent("onpropertychange", self.onAttributeChange); //IE9 DOMAttrModified bug
     2627
    21082628      if (self.observer !== false) self.observer.disconnect();
    2109       if (self.observerremover !== false) self.observerremover.disconnect();     
    2110       self.events = [];
     2629      if (self.observerremover !== false) self.observerremover.disconnect();
     2630      if (self.observerbody !== false) self.observerbody.disconnect();
     2631
     2632      self.events = null;
     2633
    21112634      if (self.cursor) {
    21122635        self.cursor.remove();
    2113         self.cursor = null;
    21142636      }
    21152637      if (self.cursorh) {
    21162638        self.cursorh.remove();
    2117         self.cursorh = null;
    21182639      }
    21192640      if (self.rail) {
    21202641        self.rail.remove();
    2121         self.rail = null;
    21222642      }
    21232643      if (self.railh) {
    21242644        self.railh.remove();
    2125         self.railh = null;
    21262645      }
    21272646      if (self.zoom) {
    21282647        self.zoom.remove();
    2129         self.zoom = null;
    2130       }
    2131       for(var a=0;a<self.saved.css.length;a++) {
    2132         var d=self.saved.css[a];
    2133         d[0].css(d[1],(typeof d[2]=="undefined") ? '' : d[2]);
    2134       }
    2135       self.saved = false;     
    2136       self.me.data('__nicescroll',''); //erase all traces
    2137       self.me = null;
    2138       self.doc = null;
    2139       self.docscroll = null;
    2140       self.win = null;
    2141       return self;
    2142     };
    2143    
    2144     this.scrollstart = function(fn) {
     2648      }
     2649      for (var a = 0; a < self.saved.css.length; a++) {
     2650        var d = self.saved.css[a];
     2651        d[0].css(d[1], (d[2] === undefined) ? '' : d[2]);
     2652      }
     2653      self.saved = false;
     2654      self.me.data('__nicescroll', ''); //erase all traces
     2655
     2656      // memory leak fixed by GianlucaGuarini - thanks a lot!
     2657      // remove the current nicescroll from the $.nicescroll array & normalize array
     2658      var lst = $.nicescroll;
     2659      lst.each(function (i) {
     2660        if (!this) return;
     2661        if (this.id === self.id) {
     2662          delete lst[i];
     2663          for (var b = ++i; b < lst.length; b++ , i++) lst[i] = lst[b];
     2664          lst.length--;
     2665          if (lst.length) delete lst[lst.length];
     2666        }
     2667      });
     2668
     2669      for (var i in self) {
     2670        self[i] = null;
     2671        delete self[i];
     2672      }
     2673
     2674      self = null;
     2675
     2676    };
     2677
     2678    this.scrollstart = function (fn) {
    21452679      this.onscrollstart = fn;
    21462680      return self;
    2147     }
    2148     this.scrollend = function(fn) {
     2681    };
     2682    this.scrollend = function (fn) {
    21492683      this.onscrollend = fn;
    21502684      return self;
    2151     }
    2152     this.scrollcancel = function(fn) {
     2685    };
     2686    this.scrollcancel = function (fn) {
    21532687      this.onscrollcancel = fn;
    21542688      return self;
    2155     }
    2156    
    2157     this.zoomin = function(fn) {
     2689    };
     2690
     2691    this.zoomin = function (fn) {
    21582692      this.onzoomin = fn;
    21592693      return self;
    2160     }
    2161     this.zoomout = function(fn) {
     2694    };
     2695    this.zoomout = function (fn) {
    21622696      this.onzoomout = fn;
    21632697      return self;
    2164     }
    2165    
    2166     this.isScrollable = function(e) {     
     2698    };
     2699
     2700    this.isScrollable = function (e) {
    21672701      var dom = (e.target) ? e.target : e;
    21682702      if (dom.nodeName == 'OPTION') return true;
    2169       while (dom&&(dom.nodeType==1)&&!(/BODY|HTML/.test(dom.nodeName))) {
     2703      while (dom && (dom.nodeType == 1) && (dom !== this.me[0]) && !(/^BODY|HTML/.test(dom.nodeName))) {
    21702704        var dd = $(dom);
    2171         var ov = dd.css('overflowY')||dd.css('overflowX')||dd.css('overflow')||'';
    2172         if (/scroll|auto/.test(ov)) return (dom.clientHeight!=dom.scrollHeight);
    2173         dom = (dom.parentNode) ? dom.parentNode : false;       
     2705        var ov = dd.css('overflowY') || dd.css('overflowX') || dd.css('overflow') || '';
     2706        if (/scroll|auto/.test(ov)) return (dom.clientHeight != dom.scrollHeight);
     2707        dom = (dom.parentNode) ? dom.parentNode : false;
    21742708      }
    21752709      return false;
    21762710    };
    21772711
    2178     this.getViewport = function(me) {     
    2179       var dom = (me&&me.parentNode) ? me.parentNode : false;
    2180       while (dom&&(dom.nodeType==1)&&!(/BODY|HTML/.test(dom.nodeName))) {
     2712    this.getViewport = function (me) {
     2713      var dom = (me && me.parentNode) ? me.parentNode : false;
     2714      while (dom && (dom.nodeType == 1) && !(/^BODY|HTML/.test(dom.nodeName))) {
    21812715        var dd = $(dom);
    2182         var ov = dd.css('overflowY')||dd.css('overflowX')||dd.css('overflow')||'';
    2183         if ((/scroll|auto/.test(ov))&&(dom.clientHeight!=dom.scrollHeight)) return dd;
    2184         if (dd.getNiceScroll().length>0) return dd;
     2716        if (/fixed|absolute/.test(dd.css("position"))) return dd;
     2717        var ov = dd.css('overflowY') || dd.css('overflowX') || dd.css('overflow') || '';
     2718        if ((/scroll|auto/.test(ov)) && (dom.clientHeight != dom.scrollHeight)) return dd;
     2719        if (dd.getNiceScroll().length > 0) return dd;
    21852720        dom = (dom.parentNode) ? dom.parentNode : false;
    21862721      }
    21872722      return false;
    21882723    };
    2189    
    2190     function execScrollWheel(e,hr,chkscroll) {
    2191       var px,py;
    2192       var rt = 1;
    2193 
    2194       if (e.deltaMode==0) {  // PIXEL
    2195         px = -Math.floor(e.deltaX*(self.opt.mousescrollstep/(18*3)));
    2196         py = -Math.floor(e.deltaY*(self.opt.mousescrollstep/(18*3)));
    2197       }
    2198       else if (e.deltaMode==1) {  // LINE
    2199         px = -Math.floor(e.deltaX*self.opt.mousescrollstep);
    2200         py = -Math.floor(e.deltaY*self.opt.mousescrollstep);
    2201       }
    2202      
    2203       if (hr&&(px==0)&&py) {  // classic vertical-only mousewheel + browser with x/y support
     2724
     2725    this.triggerScrollStart = function (cx, cy, rx, ry, ms) {
     2726
     2727      if (self.onscrollstart) {
     2728        var info = {
     2729          type: "scrollstart",
     2730          current: {
     2731            x: cx,
     2732            y: cy
     2733          },
     2734          request: {
     2735            x: rx,
     2736            y: ry
     2737          },
     2738          end: {
     2739            x: self.newscrollx,
     2740            y: self.newscrolly
     2741          },
     2742          speed: ms
     2743        };
     2744        self.onscrollstart.call(self, info);
     2745      }
     2746
     2747    };
     2748
     2749    this.triggerScrollEnd = function () {
     2750      if (self.onscrollend) {
     2751
     2752        var px = self.getScrollLeft();
     2753        var py = self.getScrollTop();
     2754
     2755        var info = {
     2756          type: "scrollend",
     2757          current: {
     2758            x: px,
     2759            y: py
     2760          },
     2761          end: {
     2762            x: px,
     2763            y: py
     2764          }
     2765        };
     2766
     2767        self.onscrollend.call(self, info);
     2768
     2769      }
     2770
     2771    };
     2772
     2773    var scrolldiry = 0, scrolldirx = 0, scrolltmr = 0, scrollspd = 1;
     2774
     2775    function doScrollRelative(px, py, chkscroll, iswheel) {
     2776
     2777      if (!self.scrollrunning) {
     2778        self.newscrolly = self.getScrollTop();
     2779        self.newscrollx = self.getScrollLeft();
     2780        scrolltmr = now();
     2781      }
     2782
     2783      var gap = (now() - scrolltmr);
     2784      scrolltmr = now();
     2785
     2786      if (gap > 350) {
     2787        scrollspd = 1;
     2788      } else {
     2789        scrollspd += (2 - scrollspd) / 10;
     2790      }
     2791
     2792      px = px * scrollspd | 0;
     2793      py = py * scrollspd | 0;
     2794
     2795      if (px) {
     2796
     2797        if (iswheel) { // mouse-only
     2798          if (px < 0) {  // fix apple magic mouse swipe back/forward
     2799            if (self.getScrollLeft() >= self.page.maxw) return true;
     2800          } else {
     2801            if (self.getScrollLeft() <= 0) return true;
     2802          }
     2803        }
     2804
     2805        var dx = px > 0 ? 1 : -1;
     2806
     2807        if (scrolldirx !== dx) {
     2808          if (self.scrollmom) self.scrollmom.stop();
     2809          self.newscrollx = self.getScrollLeft();
     2810          scrolldirx = dx;
     2811        }
     2812
     2813        self.lastdeltax -= px;
     2814
     2815      }
     2816
     2817      if (py) {
     2818
     2819        var chk = (function () {
     2820          var top = self.getScrollTop();
     2821          if (py < 0) {
     2822            if (top >= self.page.maxh) return true;
     2823          } else {
     2824            if (top <= 0) return true;
     2825          }
     2826        })();
     2827
     2828        if (chk) {
     2829          if (opt.nativeparentscrolling && chkscroll && !self.ispage && !self.zoomactive) return true;
     2830          var ny = self.view.h >> 1;
     2831          if (self.newscrolly < -ny) { self.newscrolly = -ny; py = -1; }
     2832          else if (self.newscrolly > self.page.maxh + ny) { self.newscrolly = self.page.maxh + ny; py = 1; }
     2833          else py = 0;
     2834        }
     2835
     2836        var dy = py > 0 ? 1 : -1;
     2837
     2838        if (scrolldiry !== dy) {
     2839          if (self.scrollmom) self.scrollmom.stop();
     2840          self.newscrolly = self.getScrollTop();
     2841          scrolldiry = dy;
     2842        }
     2843
     2844        self.lastdeltay -= py;
     2845
     2846      }
     2847
     2848      if (py || px) {
     2849        self.synched("relativexy", function () {
     2850
     2851          var dty = self.lastdeltay + self.newscrolly;
     2852          self.lastdeltay = 0;
     2853
     2854          var dtx = self.lastdeltax + self.newscrollx;
     2855          self.lastdeltax = 0;
     2856
     2857          if (!self.rail.drag) self.doScrollPos(dtx, dty);
     2858
     2859        });
     2860      }
     2861
     2862    }
     2863
     2864    var hasparentscrollingphase = false;
     2865
     2866    function execScrollWheel(e, hr, chkscroll) {
     2867      var px, py;
     2868
     2869      if (!chkscroll && hasparentscrollingphase) return true;
     2870
     2871      if (e.deltaMode === 0) { // PIXEL
     2872        px = -(e.deltaX * (opt.mousescrollstep / (18 * 3))) | 0;
     2873        py = -(e.deltaY * (opt.mousescrollstep / (18 * 3))) | 0;
     2874      } else if (e.deltaMode === 1) { // LINE
     2875        px = -(e.deltaX * opt.mousescrollstep * 50 / 80) | 0;
     2876        py = -(e.deltaY * opt.mousescrollstep * 50 / 80) | 0;
     2877      }
     2878
     2879      if (hr && opt.oneaxismousemode && (px === 0) && py) { // classic vertical-only mousewheel + browser with x/y support
    22042880        px = py;
    22052881        py = 0;
    2206       }
    2207 
    2208       if (px) {
    2209         if (self.scrollmom) {self.scrollmom.stop()}
    2210         self.lastdeltax+=px;
    2211         self.debounced("mousewheelx",function(){var dt=self.lastdeltax;self.lastdeltax=0;if(!self.rail.drag){self.doScrollLeftBy(dt)}},120);
    2212       }
    2213       if (py) {
    2214         if (self.opt.nativeparentscrolling&&chkscroll&&!self.ispage&&!self.zoomactive) {
    2215           if (py<0) {
    2216             if (self.getScrollTop()>=self.page.maxh) return true;
     2882
     2883        if (chkscroll) {
     2884          var hrend = (px < 0) ? (self.getScrollLeft() >= self.page.maxw) : (self.getScrollLeft() <= 0);
     2885          if (hrend) {  // preserve vertical scrolling
     2886            py = px;
     2887            px = 0;
     2888          }
     2889        }
     2890
     2891      }
     2892
     2893      // invert horizontal direction for rtl mode
     2894      if (self.isrtlmode) px = -px;
     2895
     2896      var chk = doScrollRelative(px, py, chkscroll, true);
     2897
     2898      if (chk) {
     2899        if (chkscroll) hasparentscrollingphase = true;
     2900      } else {
     2901        hasparentscrollingphase = false;
     2902        e.stopImmediatePropagation();
     2903        return e.preventDefault();
     2904      }
     2905
     2906    }
     2907
     2908    this.onmousewheel = function (e) {
     2909      if (self.wheelprevented||self.locked) return false;
     2910      if (self.railslocked) {
     2911        self.debounced("checkunlock", self.resize, 250);
     2912        return false;
     2913      }
     2914      if (self.rail.drag) return self.cancelEvent(e);
     2915
     2916      if (opt.oneaxismousemode === "auto" && e.deltaX !== 0) opt.oneaxismousemode = false; // check two-axis mouse support (not very elegant)
     2917
     2918      if (opt.oneaxismousemode && e.deltaX === 0) {
     2919        if (!self.rail.scrollable) {
     2920          if (self.railh && self.railh.scrollable) {
     2921            return self.onmousewheelhr(e);
    22172922          } else {
    2218             if (self.getScrollTop()<=0) return true;
    2219           }
    2220         }
    2221         if (self.scrollmom) {self.scrollmom.stop()}
    2222         self.lastdeltay+=py;
    2223         self.debounced("mousewheely",function(){var dt=self.lastdeltay;self.lastdeltay=0;if(!self.rail.drag){self.doScrollBy(dt)}},120);
    2224       }
    2225      
    2226       e.stopImmediatePropagation();
    2227       return e.preventDefault();
    2228 //      return self.cancelEvent(e);
    2229     };
    2230    
    2231     this.onmousewheel = function(e) {
    2232       if (self.locked) return true;
    2233       if (self.rail.drag) return self.cancelEvent(e);
    2234      
    2235       if (!self.rail.scrollable) {
    2236         if (self.railh&&self.railh.scrollable) {
    2237           return self.onmousewheelhr(e);
    2238         } else {
    2239           return true;
    2240         }
    2241       }
    2242      
    2243       var nw = +(new Date());
     2923            return true;
     2924          }
     2925        }
     2926      }
     2927
     2928      var nw = now();
    22442929      var chk = false;
    2245       if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
    2246 //        self.checkarea = false;
     2930      if (opt.preservenativescrolling && ((self.checkarea + 600) < nw)) {
    22472931        self.nativescrollingarea = self.isScrollable(e);
    22482932        chk = true;
     
    22502934      self.checkarea = nw;
    22512935      if (self.nativescrollingarea) return true; // this isn't my business
    2252 //      if (self.locked) return self.cancelEvent(e);
    2253       var ret = execScrollWheel(e,false,chk);
     2936      var ret = execScrollWheel(e, false, chk);
    22542937      if (ret) self.checkarea = 0;
    22552938      return ret;
    22562939    };
    22572940
    2258     this.onmousewheelhr = function(e) {
    2259       if (self.locked||!self.railh.scrollable) return true;
     2941    this.onmousewheelhr = function (e) {
     2942      if (self.wheelprevented) return;
     2943      if (self.railslocked || !self.railh.scrollable) return true;
    22602944      if (self.rail.drag) return self.cancelEvent(e);
    2261      
    2262       var nw = +(new Date());
     2945
     2946      var nw = now();
    22632947      var chk = false;
    2264       if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
    2265 //        self.checkarea = false;
    2266         self.nativescrollingarea = self.isScrollable(e);
     2948      if (opt.preservenativescrolling && ((self.checkarea + 600) < nw)) {
     2949        self.nativescrollingarea = self.isScrollable(e);
    22672950        chk = true;
    22682951      }
    22692952      self.checkarea = nw;
    2270       if (self.nativescrollingarea) return true; // this isn't my business
    2271       if (self.locked) return self.cancelEvent(e);
    2272 
    2273       return execScrollWheel(e,true,chk);
    2274     };
    2275    
    2276     this.stop = function() {
     2953      if (self.nativescrollingarea) return true; // this is not my business
     2954      if (self.railslocked) return self.cancelEvent(e);
     2955
     2956      return execScrollWheel(e, true, chk);
     2957    };
     2958
     2959    this.stop = function () {
    22772960      self.cancelScroll();
    22782961      if (self.scrollmon) self.scrollmon.stop();
    22792962      self.cursorfreezed = false;
    2280       self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));     
     2963      self.scroll.y = Math.round(self.getScrollTop() * (1 / self.scrollratio.y));
    22812964      self.noticeCursor();
    22822965      return self;
    22832966    };
    2284    
    2285     this.getTransitionSpeed = function(dif) {
    2286       var sp = Math.round(self.opt.scrollspeed*10);
    2287       var ex = Math.min(sp,Math.round((dif / 20) * self.opt.scrollspeed));
    2288       return (ex>20) ? ex : 0;
    2289     }
    2290    
    2291     if (!self.opt.smoothscroll) {
    2292       this.doScrollLeft = function(x,spd) { //direct
     2967
     2968    this.getTransitionSpeed = function (dif) {
     2969
     2970      return 80 + (dif / 72) * opt.scrollspeed |0;
     2971
     2972    };
     2973
     2974    if (!opt.smoothscroll) {
     2975      this.doScrollLeft = function (x, spd) { //direct
    22932976        var y = self.getScrollTop();
    2294         self.doScrollPos(x,y,spd);
    2295       }     
    2296       this.doScrollTop = function(y,spd) {  //direct
     2977        self.doScrollPos(x, y, spd);
     2978      };
     2979      this.doScrollTop = function (y, spd) { //direct
    22972980        var x = self.getScrollLeft();
    2298         self.doScrollPos(x,y,spd);
    2299       }
    2300       this.doScrollPos = function(x,y,spd) { //direct
    2301         var nx = (x>self.page.maxw) ? self.page.maxw : x;
    2302         if (nx<0) nx=0;
    2303         var ny = (y>self.page.maxh) ? self.page.maxh : y;
    2304         if (ny<0) ny=0;
    2305         self.synched('scroll',function(){
     2981        self.doScrollPos(x, y, spd);
     2982      };
     2983      this.doScrollPos = function (x, y, spd) { //direct
     2984        var nx = (x > self.page.maxw) ? self.page.maxw : x;
     2985        if (nx < 0) nx = 0;
     2986        var ny = (y > self.page.maxh) ? self.page.maxh : y;
     2987        if (ny < 0) ny = 0;
     2988        self.synched('scroll', function () {
    23062989          self.setScrollTop(ny);
    23072990          self.setScrollLeft(nx);
    23082991        });
    2309       }
    2310       this.cancelScroll = function() {}; // direct
    2311     }
    2312     else if (self.ishwscroll&&cap.hastransition&&self.opt.usetransition) {
    2313       this.prepareTransition = function(dif,istime) {
    2314         var ex = (istime) ? ((dif>20)?dif:0) : self.getTransitionSpeed(dif);       
    2315         var trans = (ex) ? cap.prefixstyle+'transform '+ex+'ms ease-out' : '';
    2316         if (!self.lasttransitionstyle||self.lasttransitionstyle!=trans) {
    2317           self.lasttransitionstyle = trans;
    2318           self.doc.css(cap.transitionstyle,trans);
     2992      };
     2993      this.cancelScroll = function () { }; // direct
     2994
     2995    } else if (self.ishwscroll && cap.hastransition && opt.usetransition && !!opt.smoothscroll) {
     2996
     2997      var lasttransitionstyle = '';
     2998
     2999      this.resetTransition = function () {
     3000        lasttransitionstyle = '';
     3001        self.doc.css(cap.prefixstyle + 'transition-duration', '0ms');
     3002      };
     3003
     3004      this.prepareTransition = function (dif, istime) {
     3005        var ex = (istime) ? dif : self.getTransitionSpeed(dif);
     3006        var trans = ex + 'ms';
     3007        if (lasttransitionstyle !== trans) {
     3008          lasttransitionstyle = trans;
     3009          self.doc.css(cap.prefixstyle + 'transition-duration', trans);
    23193010        }
    23203011        return ex;
    23213012      };
    2322      
    2323       this.doScrollLeft = function(x,spd) { //trans
     3013
     3014      this.doScrollLeft = function (x, spd) { //trans
    23243015        var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
    2325         self.doScrollPos(x,y,spd);
    2326       }     
    2327      
    2328       this.doScrollTop = function(y,spd) {  //trans
     3016        self.doScrollPos(x, y, spd);
     3017      };
     3018
     3019      this.doScrollTop = function (y, spd) { //trans
    23293020        var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
    2330         self.doScrollPos(x,y,spd);
    2331       }
    2332      
    2333       this.doScrollPos = function(x,y,spd) {  //trans
    2334    
     3021        self.doScrollPos(x, y, spd);
     3022      };
     3023
     3024      this.cursorupdate = {
     3025        running: false,
     3026        start: function () {
     3027          var m = this;
     3028
     3029          if (m.running) return;
     3030          m.running = true;
     3031
     3032          var loop = function () {
     3033            if (m.running) setAnimationFrame(loop);
     3034            self.showCursor(self.getScrollTop(), self.getScrollLeft());
     3035            self.notifyScrollEvent(self.win[0]);
     3036          };
     3037
     3038          setAnimationFrame(loop);
     3039        },
     3040        stop: function () {
     3041          this.running = false;
     3042        }
     3043      };
     3044
     3045      this.doScrollPos = function (x, y, spd) { //trans
     3046
    23353047        var py = self.getScrollTop();
    2336         var px = self.getScrollLeft();       
    2337      
    2338         if (((self.newscrolly-py)*(y-py)<0)||((self.newscrollx-px)*(x-px)<0)) self.cancelScroll();  //inverted movement detection     
    2339        
    2340         if (self.opt.bouncescroll==false) {
    2341           if (y<0) y=0;
    2342           else if (y>self.page.maxh) y=self.page.maxh;
    2343           if (x<0) x=0;
    2344           else if (x>self.page.maxw) x=self.page.maxw;
    2345         }
    2346        
    2347         if (self.scrollrunning&&x==self.newscrollx&&y==self.newscrolly) return false;
    2348        
     3048        var px = self.getScrollLeft();
     3049
     3050        if (((self.newscrolly - py) * (y - py) < 0) || ((self.newscrollx - px) * (x - px) < 0)) self.cancelScroll(); //inverted movement detection     
     3051
     3052        if (!opt.bouncescroll) {
     3053          if (y < 0) y = 0;
     3054          else if (y > self.page.maxh) y = self.page.maxh;
     3055          if (x < 0) x = 0;
     3056          else if (x > self.page.maxw) x = self.page.maxw;
     3057        } else {
     3058          if (y < 0) y = y / 2 | 0;
     3059          else if (y > self.page.maxh) y = self.page.maxh + (y - self.page.maxh) / 2 | 0;
     3060          if (x < 0) x = x / 2 | 0;
     3061          else if (x > self.page.maxw) x = self.page.maxw + (x - self.page.maxw) / 2 | 0;
     3062        }
     3063
     3064        if (self.scrollrunning && x == self.newscrollx && y == self.newscrolly) return false;
     3065
    23493066        self.newscrolly = y;
    23503067        self.newscrollx = x;
    2351        
    2352         self.newscrollspeed = spd||false;
    2353        
    2354         if (self.timer) return false;
    2355        
    2356         self.timer = setTimeout(function(){
    2357        
    2358           var top = self.getScrollTop();
    2359           var lft = self.getScrollLeft();
    2360          
    2361           var dst = {};
    2362           dst.x = x-lft;
    2363           dst.y = y-top;
    2364           dst.px = lft;
    2365           dst.py = top;
    2366          
    2367           var dd = Math.round(Math.sqrt(Math.pow(dst.x,2)+Math.pow(dst.y,2)));         
    2368          
    2369 //          var df = (self.newscrollspeed) ? self.newscrollspeed : dd;
    2370          
    2371           var ms = (self.newscrollspeed && self.newscrollspeed>1) ? self.newscrollspeed : self.getTransitionSpeed(dd);
    2372           if (self.newscrollspeed&&self.newscrollspeed<=1) ms*=self.newscrollspeed;
    2373          
    2374           self.prepareTransition(ms,true);
    2375          
    2376           if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);   
    2377          
    2378           if (ms>0) {
    2379          
    2380             if (!self.scrollrunning&&self.onscrollstart) {
    2381               var info = {"type":"scrollstart","current":{"x":lft,"y":top},"request":{"x":x,"y":y},"end":{"x":self.newscrollx,"y":self.newscrolly},"speed":ms};
    2382               self.onscrollstart.call(self,info);
    2383             }
    2384            
    2385             if (cap.transitionend) {
    2386               if (!self.scrollendtrapped) {
    2387                 self.scrollendtrapped = true;
    2388                 self.bind(self.doc,cap.transitionend,self.onScrollEnd,false); //I have got to do something usefull!!
    2389               }
    2390             } else {             
    2391               if (self.scrollendtrapped) clearTimeout(self.scrollendtrapped);
    2392               self.scrollendtrapped = setTimeout(self.onScrollEnd,ms);  // simulate transitionend event
    2393             }
    2394            
    2395             var py = top;
    2396             var px = lft;
    2397             self.timerscroll = {
    2398               bz: new BezierClass(py,self.newscrolly,ms,0,0,0.58,1),
    2399               bh: new BezierClass(px,self.newscrollx,ms,0,0,0.58,1)
    2400             };           
    2401             if (!self.cursorfreezed) self.timerscroll.tm=setInterval(function(){self.showCursor(self.getScrollTop(),self.getScrollLeft())},60);
    2402            
    2403           }
    2404          
    2405           self.synched("doScroll-set",function(){
    2406             self.timer = 0;
    2407             if (self.scrollendtrapped) self.scrollrunning = true;
    2408             self.setScrollTop(self.newscrolly);
    2409             self.setScrollLeft(self.newscrollx);
    2410             if (!self.scrollendtrapped) self.onScrollEnd();
    2411           });
    2412          
    2413          
    2414         },50);
    2415        
     3068
     3069        var top = self.getScrollTop();
     3070        var lft = self.getScrollLeft();
     3071
     3072        var dst = {};
     3073        dst.x = x - lft;
     3074        dst.y = y - top;
     3075
     3076        var dd = Math.sqrt((dst.x * dst.x) + (dst.y * dst.y)) | 0;
     3077
     3078        var ms = self.prepareTransition(dd);
     3079
     3080        if (!self.scrollrunning) {
     3081          self.scrollrunning = true;
     3082          self.triggerScrollStart(lft, top, x, y, ms);
     3083          self.cursorupdate.start();
     3084        }
     3085
     3086        self.scrollendtrapped = true;
     3087
     3088        if (!cap.transitionend) {
     3089          if (self.scrollendtrapped) clearTimeout(self.scrollendtrapped);
     3090          self.scrollendtrapped = setTimeout(self.onScrollTransitionEnd, ms); // simulate transitionend event
     3091        }
     3092
     3093        self.setScrollTop(self.newscrolly);
     3094        self.setScrollLeft(self.newscrollx);
     3095
    24163096      };
    2417      
    2418       this.cancelScroll = function() {
    2419         if (!self.scrollendtrapped) return true;       
     3097
     3098      this.cancelScroll = function () {
     3099        if (!self.scrollendtrapped) return true;
    24203100        var py = self.getScrollTop();
    24213101        var px = self.getScrollLeft();
     
    24233103        if (!cap.transitionend) clearTimeout(cap.transitionend);
    24243104        self.scrollendtrapped = false;
    2425         self._unbind(self.doc,cap.transitionend,self.onScrollEnd);       
    2426         self.prepareTransition(0);
     3105        self.resetTransition();
    24273106        self.setScrollTop(py); // fire event onscroll
    24283107        if (self.railh) self.setScrollLeft(px);
    2429         if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
     3108        if (self.timerscroll && self.timerscroll.tm) clearInterval(self.timerscroll.tm);
    24303109        self.timerscroll = false;
    2431        
     3110
    24323111        self.cursorfreezed = false;
    24333112
    2434         //self.noticeCursor(false,py,px);
    2435         self.showCursor(py,px);
     3113        self.cursorupdate.stop();
     3114        self.showCursor(py, px);
    24363115        return self;
    24373116      };
    2438       this.onScrollEnd = function() {               
    2439         if (self.scrollendtrapped) self._unbind(self.doc,cap.transitionend,self.onScrollEnd);
    2440         self.scrollendtrapped = false;       
    2441         self.prepareTransition(0);
    2442         if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
    2443         self.timerscroll = false;       
     3117
     3118      this.onScrollTransitionEnd = function () {
     3119
     3120        if (!self.scrollendtrapped) return;
     3121
    24443122        var py = self.getScrollTop();
    24453123        var px = self.getScrollLeft();
    2446         self.setScrollTop(py);  // fire event onscroll       
    2447         if (self.railh) self.setScrollLeft(px);  // fire event onscroll left
    2448        
    2449         self.noticeCursor(false,py,px);     
    2450        
     3124
     3125        if (py < 0) py = 0;
     3126        else if (py > self.page.maxh) py = self.page.maxh;
     3127        if (px < 0) px = 0;
     3128        else if (px > self.page.maxw) px = self.page.maxw;
     3129        if ((py != self.newscrolly) || (px != self.newscrollx)) return self.doScrollPos(px, py, opt.snapbackspeed);
     3130
     3131        if (self.scrollrunning) self.triggerScrollEnd();
     3132        self.scrollrunning = false;
     3133
     3134        self.scrollendtrapped = false;
     3135        self.resetTransition();
     3136        self.timerscroll = false;
     3137        self.setScrollTop(py); // fire event onscroll       
     3138        if (self.railh) self.setScrollLeft(px); // fire event onscroll left
     3139
     3140        self.cursorupdate.stop();
     3141        self.noticeCursor(false, py, px);
     3142
    24513143        self.cursorfreezed = false;
    2452        
    2453         if (py<0) py=0
    2454         else if (py>self.page.maxh) py=self.page.maxh;
    2455         if (px<0) px=0
    2456         else if (px>self.page.maxw) px=self.page.maxw;
    2457         if((py!=self.newscrolly)||(px!=self.newscrollx)) return self.doScrollPos(px,py,self.opt.snapbackspeed);
    2458        
    2459         if (self.onscrollend&&self.scrollrunning) {
    2460           var info = {"type":"scrollend","current":{"x":px,"y":py},"end":{"x":self.newscrollx,"y":self.newscrolly}};
    2461           self.onscrollend.call(self,info);
    2462         }
    2463         self.scrollrunning = false;
    2464        
     3144
    24653145      };
    24663146
    24673147    } else {
    24683148
    2469       this.doScrollLeft = function(x,spd) { //no-trans
     3149      this.doScrollLeft = function (x, spd) { //no-trans
    24703150        var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
    2471         self.doScrollPos(x,y,spd);
    2472       }
    2473 
    2474       this.doScrollTop = function(y,spd) { //no-trans
     3151        self.doScrollPos(x, y, spd);
     3152      };
     3153
     3154      this.doScrollTop = function (y, spd) { //no-trans
    24753155        var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
    2476         self.doScrollPos(x,y,spd);
    2477       }
    2478 
    2479       this.doScrollPos = function(x,y,spd) {  //no-trans
    2480         var y = ((typeof y == "undefined")||(y===false)) ? self.getScrollTop(true) : y;
    2481      
    2482         if  ((self.timer)&&(self.newscrolly==y)&&(self.newscrollx==x)) return true;
    2483      
    2484         if (self.timer) clearAnimationFrame(self.timer);
    2485         self.timer = 0;     
     3156        self.doScrollPos(x, y, spd);
     3157      };
     3158
     3159      this.doScrollPos = function (x, y, spd) { //no-trans
    24863160
    24873161        var py = self.getScrollTop();
    24883162        var px = self.getScrollLeft();
    2489        
    2490         if (((self.newscrolly-py)*(y-py)<0)||((self.newscrollx-px)*(x-px)<0)) self.cancelScroll();  //inverted movement detection
    2491        
     3163
     3164        if (((self.newscrolly - py) * (y - py) < 0) || ((self.newscrollx - px) * (x - px) < 0)) self.cancelScroll(); //inverted movement detection
     3165
     3166        var clipped = false;
     3167
     3168        if (!self.bouncescroll || !self.rail.visibility) {
     3169          if (y < 0) {
     3170            y = 0;
     3171            clipped = true;
     3172          } else if (y > self.page.maxh) {
     3173            y = self.page.maxh;
     3174            clipped = true;
     3175          }
     3176        }
     3177        if (!self.bouncescroll || !self.railh.visibility) {
     3178          if (x < 0) {
     3179            x = 0;
     3180            clipped = true;
     3181          } else if (x > self.page.maxw) {
     3182            x = self.page.maxw;
     3183            clipped = true;
     3184          }
     3185        }
     3186
     3187        if (self.scrollrunning && (self.newscrolly === y) && (self.newscrollx === x)) return true;
     3188
    24923189        self.newscrolly = y;
    24933190        self.newscrollx = x;
    2494        
    2495         if (!self.bouncescroll||!self.rail.visibility) {
    2496           if (self.newscrolly<0) {
    2497             self.newscrolly = 0;
    2498           }
    2499           else if (self.newscrolly>self.page.maxh) {
    2500             self.newscrolly = self.page.maxh;
    2501           }
    2502         }
    2503         if (!self.bouncescroll||!self.railh.visibility) {
    2504           if (self.newscrollx<0) {
    2505             self.newscrollx = 0;
    2506           }
    2507           else if (self.newscrollx>self.page.maxw) {
    2508             self.newscrollx = self.page.maxw;
    2509           }
    2510         }
    25113191
    25123192        self.dst = {};
    2513         self.dst.x = x-px;
    2514         self.dst.y = y-py;
     3193        self.dst.x = x - px;
     3194        self.dst.y = y - py;
    25153195        self.dst.px = px;
    25163196        self.dst.py = py;
    2517        
    2518         var dst = Math.round(Math.sqrt(Math.pow(self.dst.x,2)+Math.pow(self.dst.y,2)));
    2519        
    2520         self.dst.ax = self.dst.x / dst;
    2521         self.dst.ay = self.dst.y / dst;
    2522        
    2523         var pa = 0;
    2524         var pe = dst;
    2525        
    2526         if (self.dst.x==0) {
    2527           pa = py;
    2528           pe = y;
    2529           self.dst.ay = 1;
    2530           self.dst.py = 0;
    2531         } else if (self.dst.y==0) {
    2532           pa = px;
    2533           pe = x;
    2534           self.dst.ax = 1;
    2535           self.dst.px = 0;
    2536         }
    2537 
    2538         var ms = self.getTransitionSpeed(dst);
    2539         if (spd&&spd<=1) ms*=spd;
    2540         if (ms>0) {
    2541           self.bzscroll = (self.bzscroll) ? self.bzscroll.update(pe,ms) : new BezierClass(pa,pe,ms,0,1,0,1);
    2542         } else {
    2543           self.bzscroll = false;
    2544         }
    2545        
    2546         if (self.timer) return;
    2547        
    2548         if ((py==self.page.maxh&&y>=self.page.maxh)||(px==self.page.maxw&&x>=self.page.maxw)) self.checkContentSize();
    2549        
    2550         var sync = 1;
    2551        
    2552         function scrolling() {         
    2553           if (self.cancelAnimationFrame) return true;
    2554          
     3197
     3198        var dd = Math.sqrt((self.dst.x * self.dst.x) + (self.dst.y * self.dst.y)) | 0;
     3199        var ms = self.getTransitionSpeed(dd);
     3200
     3201        self.bzscroll = {};
     3202
     3203        var p3 = (clipped) ? 1 : 0.58;
     3204        self.bzscroll.x = new BezierClass(px, self.newscrollx, ms, 0, 0, p3, 1);
     3205        self.bzscroll.y = new BezierClass(py, self.newscrolly, ms, 0, 0, p3, 1);
     3206
     3207        var loopid = now();
     3208
     3209        var loop = function () {
     3210
     3211          if (!self.scrollrunning) return;
     3212          var x = self.bzscroll.y.getPos();
     3213
     3214          self.setScrollLeft(self.bzscroll.x.getNow());
     3215          self.setScrollTop(self.bzscroll.y.getNow());
     3216
     3217          if (x <= 1) {
     3218            self.timer = setAnimationFrame(loop);
     3219          } else {
     3220            self.scrollrunning = false;
     3221            self.timer = 0;
     3222            self.triggerScrollEnd();
     3223          }
     3224
     3225        };
     3226
     3227        if (!self.scrollrunning) {
     3228          self.triggerScrollStart(px, py, x, y, ms);
    25553229          self.scrollrunning = true;
    2556          
    2557           sync = 1-sync;
    2558           if (sync) return (self.timer = setAnimationFrame(scrolling)||1);
    2559 
    2560           var done = 0;
    2561          
    2562           var sc = sy = self.getScrollTop();
    2563           if (self.dst.ay) {           
    2564             sc = (self.bzscroll) ? self.dst.py + (self.bzscroll.getNow()*self.dst.ay) : self.newscrolly;
    2565             var dr=sc-sy;         
    2566             if ((dr<0&&sc<self.newscrolly)||(dr>0&&sc>self.newscrolly)) sc = self.newscrolly;
    2567             self.setScrollTop(sc);
    2568             if (sc == self.newscrolly) done=1;
    2569           } else {
    2570             done=1;
    2571           }
    2572          
    2573           var scx = sx = self.getScrollLeft();
    2574           if (self.dst.ax) {           
    2575             scx = (self.bzscroll) ? self.dst.px + (self.bzscroll.getNow()*self.dst.ax) : self.newscrollx;           
    2576             var dr=scx-sx;
    2577             if ((dr<0&&scx<self.newscrollx)||(dr>0&&scx>self.newscrollx)) scx = self.newscrollx;
    2578             self.setScrollLeft(scx);
    2579             if (scx == self.newscrollx) done+=1;
    2580           } else {
    2581             done+=1;
    2582           }
    2583          
    2584           if (done==2) {
    2585             self.timer = 0;
    2586             self.cursorfreezed = false;
    2587             self.bzscroll = false;
    2588             self.scrollrunning = false;
    2589             if (sc<0) sc=0;
    2590             else if (sc>self.page.maxh) sc=self.page.maxh;
    2591             if (scx<0) scx=0;
    2592             else if (scx>self.page.maxw) scx=self.page.maxw;
    2593             if ((scx!=self.newscrollx)||(sc!=self.newscrolly)) self.doScrollPos(scx,sc);
    2594             else {
    2595               if (self.onscrollend) {
    2596                 var info = {"type":"scrollend","current":{"x":sx,"y":sy},"end":{"x":self.newscrollx,"y":self.newscrolly}};
    2597                 self.onscrollend.call(self,info);
    2598               }             
    2599             }
    2600           } else {
    2601             self.timer = setAnimationFrame(scrolling)||1;
    2602           }
    2603         };
    2604         self.cancelAnimationFrame=false;
    2605         self.timer = 1;
    2606 
    2607         if (self.onscrollstart&&!self.scrollrunning) {
    2608           var info = {"type":"scrollstart","current":{"x":px,"y":py},"request":{"x":x,"y":y},"end":{"x":self.newscrollx,"y":self.newscrolly},"speed":ms};
    2609           self.onscrollstart.call(self,info);
    2610         }       
    2611 
    2612         scrolling();
    2613        
    2614         if ((py==self.page.maxh&&y>=py)||(px==self.page.maxw&&x>=px)) self.checkContentSize();
    2615        
    2616         self.noticeCursor();
     3230          self.timer = setAnimationFrame(loop);
     3231        }
     3232
    26173233      };
    2618  
    2619       this.cancelScroll = function() {       
     3234
     3235      this.cancelScroll = function () {
    26203236        if (self.timer) clearAnimationFrame(self.timer);
    26213237        self.timer = 0;
     
    26243240        return self;
    26253241      };
    2626      
     3242
    26273243    }
    2628    
    2629     this.doScrollBy = function(stp,relative) {
    2630       var ny = 0;
    2631       if (relative) {
    2632         ny = Math.floor((self.scroll.y-stp)*self.scrollratio.y)
    2633       } else {       
    2634         var sy = (self.timer) ? self.newscrolly : self.getScrollTop(true);
    2635         ny = sy-stp;
    2636       }
    2637       if (self.bouncescroll) {
    2638         var haf = Math.round(self.view.h/2);
    2639         if (ny<-haf) ny=-haf
    2640         else if (ny>(self.page.maxh+haf)) ny = (self.page.maxh+haf);
    2641       }
    2642       self.cursorfreezed = false;     
    2643 
    2644       py = self.getScrollTop(true);
    2645       if (ny<0&&py<=0) return self.noticeCursor();     
    2646       else if (ny>self.page.maxh&&py>=self.page.maxh) {
    2647         self.checkContentSize();
    2648         return self.noticeCursor();
    2649       }
    2650      
    2651       self.doScrollTop(ny);
    2652     };
    2653 
    2654     this.doScrollLeftBy = function(stp,relative) {
    2655       var nx = 0;
    2656       if (relative) {
    2657         nx = Math.floor((self.scroll.x-stp)*self.scrollratio.x)
    2658       } else {
    2659         var sx = (self.timer) ? self.newscrollx : self.getScrollLeft(true);
    2660         nx = sx-stp;
    2661       }
    2662       if (self.bouncescroll) {
    2663         var haf = Math.round(self.view.w/2);
    2664         if (nx<-haf) nx=-haf
    2665         else if (nx>(self.page.maxw+haf)) nx = (self.page.maxw+haf);
    2666       }
    2667       self.cursorfreezed = false;   
    2668 
    2669       px = self.getScrollLeft(true);
    2670       if (nx<0&&px<=0) return self.noticeCursor();     
    2671       else if (nx>self.page.maxw&&px>=self.page.maxw) return self.noticeCursor();
    2672      
    2673       self.doScrollLeft(nx);
    2674     };
    2675    
    2676     this.doScrollTo = function(pos,relative) {
    2677       var ny = (relative) ? Math.round(pos*self.scrollratio.y) : pos;
    2678       if (ny<0) ny=0
    2679       else if (ny>self.page.maxh) ny = self.page.maxh;
     3244
     3245    this.doScrollBy = function (stp, relative) {
     3246      doScrollRelative(0, stp);
     3247    };
     3248
     3249    this.doScrollLeftBy = function (stp, relative) {
     3250      doScrollRelative(stp, 0);
     3251    };
     3252
     3253    this.doScrollTo = function (pos, relative) {
     3254      var ny = (relative) ? Math.round(pos * self.scrollratio.y) : pos;
     3255      if (ny < 0) ny = 0;
     3256      else if (ny > self.page.maxh) ny = self.page.maxh;
    26803257      self.cursorfreezed = false;
    26813258      self.doScrollTop(pos);
    26823259    };
    2683    
    2684     this.checkContentSize = function() {     
     3260
     3261    this.checkContentSize = function () {
    26853262      var pg = self.getContentSize();
    2686       if ((pg.h!=self.page.h)||(pg.w!=self.page.w)) self.resize(false,pg);
    2687     };
    2688    
    2689     self.onscroll = function(e) {   
     3263      if ((pg.h != self.page.h) || (pg.w != self.page.w)) self.resize(false, pg);
     3264    };
     3265
     3266    self.onscroll = function (e) {
    26903267      if (self.rail.drag) return;
    26913268      if (!self.cursorfreezed) {
    2692         self.synched('scroll',function(){
    2693           self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
    2694           if (self.railh) self.scroll.x = Math.round(self.getScrollLeft() * (1/self.scrollratio.x));
     3269        self.synched('scroll', function () {
     3270          self.scroll.y = Math.round(self.getScrollTop() / self.scrollratio.y);
     3271          if (self.railh) self.scroll.x = Math.round(self.getScrollLeft() / self.scrollratio.x);
    26953272          self.noticeCursor();
    26963273        });
    26973274      }
    26983275    };
    2699     self.bind(self.docscroll,"scroll",self.onscroll);
    2700    
    2701     this.doZoomIn = function(e) {
     3276    self.bind(self.docscroll, "scroll", self.onscroll);
     3277
     3278    this.doZoomIn = function (e) {
    27023279      if (self.zoomactive) return;
    27033280      self.zoomactive = true;
    2704      
     3281
    27053282      self.zoomrestore = {
    2706         style:{}
     3283        style: {}
    27073284      };
    2708       var lst = ['position','top','left','zIndex','backgroundColor','marginTop','marginBottom','marginLeft','marginRight'];
     3285      var lst = ['position', 'top', 'left', 'zIndex', 'backgroundColor', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight'];
    27093286      var win = self.win[0].style;
    2710       for(var a in lst) {
     3287      for (var a in lst) {
    27113288        var pp = lst[a];
    2712         self.zoomrestore.style[pp] = (typeof win[pp] != "undefined") ? win[pp] : '';       
    2713       }
    2714      
     3289        self.zoomrestore.style[pp] = (win[pp] !== undefined) ? win[pp] : '';
     3290      }
     3291
    27153292      self.zoomrestore.style.width = self.win.css('width');
    27163293      self.zoomrestore.style.height = self.win.css('height');
    2717      
     3294
    27183295      self.zoomrestore.padding = {
    2719         w:self.win.outerWidth()-self.win.width(),
    2720         h:self.win.outerHeight()-self.win.height()
     3296        w: self.win.outerWidth() - self.win.width(),
     3297        h: self.win.outerHeight() - self.win.height()
    27213298      };
    2722      
     3299
    27233300      if (cap.isios4) {
    2724         self.zoomrestore.scrollTop = $(window).scrollTop();
    2725         $(window).scrollTop(0);
    2726       }
    2727      
     3301        self.zoomrestore.scrollTop = $window.scrollTop();
     3302        $window.scrollTop(0);
     3303      }
     3304
    27283305      self.win.css({
    2729         "position":(cap.isios4)?"absolute":"fixed",
    2730         "top":0,
    2731         "left":0,
    2732         "z-index":globalmaxzindex+100,
    2733         "margin":"0px"
     3306        position: (cap.isios4) ? "absolute" : "fixed",
     3307        top: 0,
     3308        left: 0,
     3309        zIndex: globalmaxzindex + 100,
     3310        margin: 0
    27343311      });
    2735       var bkg = self.win.css("backgroundColor");     
    2736       if (bkg==""||/transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor","#fff");
    2737       self.rail.css({"z-index":globalmaxzindex+101});
    2738       self.zoom.css({"z-index":globalmaxzindex+102});     
    2739       self.zoom.css('backgroundPosition','0px -18px');
     3312      var bkg = self.win.css("backgroundColor");
     3313      if ("" === bkg || /transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor", "#fff");
     3314      self.rail.css({
     3315        zIndex: globalmaxzindex + 101
     3316      });
     3317      self.zoom.css({
     3318        zIndex: globalmaxzindex + 102
     3319      });
     3320      self.zoom.css('backgroundPosition', '0 -18px');
    27403321      self.resizeZoom();
    2741      
     3322
    27423323      if (self.onzoomin) self.onzoomin.call(self);
    2743      
     3324
    27443325      return self.cancelEvent(e);
    27453326    };
    27463327
    2747     this.doZoomOut = function(e) {
     3328    this.doZoomOut = function (e) {
    27483329      if (!self.zoomactive) return;
    27493330      self.zoomactive = false;
    2750      
    2751       self.win.css("margin","");
     3331
     3332      self.win.css("margin", "");
    27523333      self.win.css(self.zoomrestore.style);
    2753      
     3334
    27543335      if (cap.isios4) {
    2755         $(window).scrollTop(self.zoomrestore.scrollTop);
    2756       }
    2757      
    2758       self.rail.css({"z-index":self.zindex});
    2759       self.zoom.css({"z-index":self.zindex});
     3336        $window.scrollTop(self.zoomrestore.scrollTop);
     3337      }
     3338
     3339      self.rail.css({
     3340        "z-index": self.zindex
     3341      });
     3342      self.zoom.css({
     3343        "z-index": self.zindex
     3344      });
    27603345      self.zoomrestore = false;
    2761       self.zoom.css('backgroundPosition','0px 0px');
     3346      self.zoom.css('backgroundPosition', '0 0');
    27623347      self.onResize();
    2763      
     3348
    27643349      if (self.onzoomout) self.onzoomout.call(self);
    2765      
     3350
    27663351      return self.cancelEvent(e);
    27673352    };
    2768    
    2769     this.doZoom = function(e) {
     3353
     3354    this.doZoom = function (e) {
    27703355      return (self.zoomactive) ? self.doZoomOut(e) : self.doZoomIn(e);
    27713356    };
    2772    
    2773     this.resizeZoom = function() {
     3357
     3358    this.resizeZoom = function () {
    27743359      if (!self.zoomactive) return;
    27753360
    27763361      var py = self.getScrollTop(); //preserve scrolling position
    27773362      self.win.css({
    2778         width:$(window).width()-self.zoomrestore.padding.w+"px",
    2779         height:$(window).height()-self.zoomrestore.padding.h+"px"
     3363        width: $window.width() - self.zoomrestore.padding.w + "px",
     3364        height: $window.height() - self.zoomrestore.padding.h + "px"
    27803365      });
    27813366      self.onResize();
    2782      
    2783       self.setScrollTop(Math.min(self.page.maxh,py));
    2784     };
    2785    
     3367
     3368      self.setScrollTop(Math.min(self.page.maxh, py));
     3369    };
     3370
    27863371    this.init();
    2787    
     3372
    27883373    $.nicescroll.push(this);
    27893374
    27903375  };
    2791  
    2792 // Inspired by the work of Kin Blas
    2793 // http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js 
    2794  
    2795  
    2796   var ScrollMomentumClass2D = function(nc) {
     3376
     3377  // Inspired by the work of Kin Blas
     3378  // http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js 
     3379  var ScrollMomentumClass2D = function (nc) {
    27973380    var self = this;
    27983381    this.nc = nc;
    2799    
     3382
    28003383    this.lastx = 0;
    28013384    this.lasty = 0;
     
    28083391    this.demulx = 0;
    28093392    this.demuly = 0;
    2810    
     3393
    28113394    this.lastscrollx = -1;
    28123395    this.lastscrolly = -1;
    2813    
     3396
    28143397    this.chkx = 0;
    28153398    this.chky = 0;
    2816    
     3399
    28173400    this.timer = 0;
    2818    
    2819     this.time = function() {
    2820       return +new Date();//beautifull hack
    2821     };
    2822    
    2823     this.reset = function(px,py) {
     3401
     3402    this.reset = function (px, py) {
    28243403      self.stop();
    2825       var now = self.time();
    28263404      self.steptime = 0;
    2827       self.lasttime = now;
     3405      self.lasttime = now();
    28283406      self.speedx = 0;
    28293407      self.speedy = 0;
     
    28333411      self.lastscrolly = -1;
    28343412    };
    2835    
    2836     this.update = function(px,py) {
    2837       var now = self.time();
    2838       self.steptime = now - self.lasttime;
    2839       self.lasttime = now;     
     3413
     3414    this.update = function (px, py) {
     3415      var tm = now();
     3416      self.steptime = tm - self.lasttime;
     3417      self.lasttime = tm;
    28403418      var dy = py - self.lasty;
    28413419      var dx = px - self.lastx;
     
    28443422      var newy = sy + dy;
    28453423      var newx = sx + dx;
    2846       self.snapx = (newx<0)||(newx>self.nc.page.maxw);
    2847       self.snapy = (newy<0)||(newy>self.nc.page.maxh);
     3424      self.snapx = (newx < 0) || (newx > self.nc.page.maxw);
     3425      self.snapy = (newy < 0) || (newy > self.nc.page.maxh);
    28483426      self.speedx = dx;
    28493427      self.speedy = dy;
     
    28513429      self.lasty = py;
    28523430    };
    2853    
    2854     this.stop = function() {
     3431
     3432    this.stop = function () {
    28553433      self.nc.unsynched("domomentum2d");
    28563434      if (self.timer) clearTimeout(self.timer);
     
    28593437      self.lastscrolly = -1;
    28603438    };
    2861    
    2862     this.doSnapy = function(nx,ny) {
     3439
     3440    this.doSnapy = function (nx, ny) {
    28633441      var snap = false;
    2864      
    2865       if (ny<0) {
    2866         ny=0;
    2867         snap=true;       
    2868       }
    2869       else if (ny>self.nc.page.maxh) {
    2870         ny=self.nc.page.maxh;
    2871         snap=true;
    2872       }
    2873 
    2874       if (nx<0) {
    2875         nx=0;
    2876         snap=true;       
    2877       }
    2878       else if (nx>self.nc.page.maxw) {
    2879         nx=self.nc.page.maxw;
    2880         snap=true;
    2881       }
    2882      
    2883       if (snap) self.nc.doScrollPos(nx,ny,self.nc.opt.snapbackspeed);
    2884     };
    2885    
    2886     this.doMomentum = function(gp) {
    2887       var t = self.time();
    2888       var l = (gp) ? t+gp : self.lasttime;
     3442
     3443      if (ny < 0) {
     3444        ny = 0;
     3445        snap = true;
     3446      } else if (ny > self.nc.page.maxh) {
     3447        ny = self.nc.page.maxh;
     3448        snap = true;
     3449      }
     3450
     3451      if (nx < 0) {
     3452        nx = 0;
     3453        snap = true;
     3454      } else if (nx > self.nc.page.maxw) {
     3455        nx = self.nc.page.maxw;
     3456        snap = true;
     3457      }
     3458
     3459      (snap) ? self.nc.doScrollPos(nx, ny, self.nc.opt.snapbackspeed) : self.nc.triggerScrollEnd();
     3460    };
     3461
     3462    this.doMomentum = function (gp) {
     3463      var t = now();
     3464      var l = (gp) ? t + gp : self.lasttime;
    28893465
    28903466      var sl = self.nc.getScrollLeft();
    28913467      var st = self.nc.getScrollTop();
    2892      
     3468
    28933469      var pageh = self.nc.page.maxh;
    28943470      var pagew = self.nc.page.maxw;
    2895      
    2896       self.speedx = (pagew>0) ? Math.min(60,self.speedx) : 0;
    2897       self.speedy = (pageh>0) ? Math.min(60,self.speedy) : 0;
    2898      
    2899       var chk = l && (t - l) <= 50;
    2900      
    2901       if ((st<0)||(st>pageh)||(sl<0)||(sl>pagew)) chk = false;
    2902      
     3471
     3472      self.speedx = (pagew > 0) ? Math.min(60, self.speedx) : 0;
     3473      self.speedy = (pageh > 0) ? Math.min(60, self.speedy) : 0;
     3474
     3475      var chk = l && (t - l) <= 60;
     3476
     3477      if ((st < 0) || (st > pageh) || (sl < 0) || (sl > pagew)) chk = false;
     3478
    29033479      var sy = (self.speedy && chk) ? self.speedy : false;
    29043480      var sx = (self.speedx && chk) ? self.speedx : false;
    2905      
    2906       if (sy||sx) {
    2907         var tm = Math.max(16,self.steptime); //timeout granularity
    2908        
    2909         if (tm>50) { // do smooth
    2910           var xm = tm/50;
    2911           self.speedx*=xm;
    2912           self.speedy*=xm;
     3481
     3482      if (sy || sx) {
     3483        var tm = Math.max(16, self.steptime); //timeout granularity
     3484
     3485        if (tm > 50) { // do smooth
     3486          var xm = tm / 50;
     3487          self.speedx *= xm;
     3488          self.speedy *= xm;
    29133489          tm = 50;
    29143490        }
    2915        
     3491
    29163492        self.demulxy = 0;
    29173493
     
    29203496        self.lastscrolly = self.nc.getScrollTop();
    29213497        self.chky = self.lastscrolly;
    2922        
     3498
    29233499        var nx = self.lastscrollx;
    29243500        var ny = self.lastscrolly;
    2925        
    2926         var onscroll = function(){
    2927           var df = ((self.time()-t)>600) ? 0.04 : 0.02;
    2928        
     3501
     3502        var onscroll = function () {
     3503          var df = ((now() - t) > 600) ? 0.04 : 0.02;
     3504
    29293505          if (self.speedx) {
    2930             nx = Math.floor(self.lastscrollx - (self.speedx*(1-self.demulxy)));
     3506            nx = Math.floor(self.lastscrollx - (self.speedx * (1 - self.demulxy)));
    29313507            self.lastscrollx = nx;
    2932             if ((nx<0)||(nx>pagew)) df=0.10;
     3508            if ((nx < 0) || (nx > pagew)) df = 0.10;
    29333509          }
    29343510
    29353511          if (self.speedy) {
    2936             ny = Math.floor(self.lastscrolly - (self.speedy*(1-self.demulxy)));
     3512            ny = Math.floor(self.lastscrolly - (self.speedy * (1 - self.demulxy)));
    29373513            self.lastscrolly = ny;
    2938             if ((ny<0)||(ny>pageh)) df=0.10;
    2939           }
    2940          
    2941           self.demulxy = Math.min(1,self.demulxy+df);
    2942          
    2943           self.nc.synched("domomentum2d",function(){
     3514            if ((ny < 0) || (ny > pageh)) df = 0.10;
     3515          }
     3516
     3517          self.demulxy = Math.min(1, self.demulxy + df);
     3518
     3519          self.nc.synched("domomentum2d", function () {
    29443520
    29453521            if (self.speedx) {
    29463522              var scx = self.nc.getScrollLeft();
    2947               if (scx!=self.chkx) self.stop();
    2948               self.chkx=nx;
     3523              //              if (scx != self.chkx) self.stop();
     3524              self.chkx = nx;
    29493525              self.nc.setScrollLeft(nx);
    29503526            }
    2951          
     3527
    29523528            if (self.speedy) {
    29533529              var scy = self.nc.getScrollTop();
    2954               if (scy!=self.chky) self.stop();         
    2955               self.chky=ny;
     3530              //              if (scy != self.chky) self.stop();
     3531              self.chky = ny;
    29563532              self.nc.setScrollTop(ny);
    29573533            }
    2958            
    2959             if(!self.timer) {
     3534
     3535            if (!self.timer) {
    29603536              self.nc.hideCursor();
    2961               self.doSnapy(nx,ny);
     3537              self.doSnapy(nx, ny);
    29623538            }
    2963            
     3539
    29643540          });
    2965          
    2966           if (self.demulxy<1) {           
    2967             self.timer = setTimeout(onscroll,tm);
     3541
     3542          if (self.demulxy < 1) {
     3543            self.timer = setTimeout(onscroll, tm);
    29683544          } else {
    29693545            self.stop();
    29703546            self.nc.hideCursor();
    2971             self.doSnapy(nx,ny);
     3547            self.doSnapy(nx, ny);
    29723548          }
    29733549        };
    2974        
     3550
    29753551        onscroll();
    2976        
     3552
    29773553      } else {
    2978         self.doSnapy(self.nc.getScrollLeft(),self.nc.getScrollTop());
    2979       }     
    2980      
    2981     }
    2982    
     3554        self.doSnapy(self.nc.getScrollLeft(), self.nc.getScrollTop());
     3555      }
     3556
     3557    };
     3558
    29833559  };
    29843560
    2985  
    2986 // override jQuery scrollTop
    2987  
     3561
     3562  // override jQuery scrollTop
    29883563  var _scrollTop = jQuery.fn.scrollTop; // preserve original function
    2989    
    2990   jQuery.cssHooks["pageYOffset"] = {
    2991     get: function(elem,computed,extra) {     
    2992       var nice = $.data(elem,'__nicescroll')||false;
    2993       return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
     3564
     3565  jQuery.cssHooks.pageYOffset = {
     3566    get: function (elem, computed, extra) {
     3567      var nice = $.data(elem, '__nicescroll') || false;
     3568      return (nice && nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
    29943569    },
    2995     set: function(elem,value) {
    2996       var nice = $.data(elem,'__nicescroll')||false;   
    2997       (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call(elem,value);
     3570    set: function (elem, value) {
     3571      var nice = $.data(elem, '__nicescroll') || false;
     3572      (nice && nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call(elem, value);
    29983573      return this;
    29993574    }
    30003575  };
    3001  
    3002 /* 
    3003   $.fx.step["scrollTop"] = function(fx){   
    3004     $.cssHooks["scrollTop"].set( fx.elem, fx.now + fx.unit );
    3005   };
    3006 */ 
    3007  
    3008   jQuery.fn.scrollTop = function(value) {   
    3009     if (typeof value == "undefined") {
    3010       var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
    3011       return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
    3012     } else {     
    3013       return this.each(function() {
    3014         var nice = $.data(this,'__nicescroll')||false;
    3015         (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call($(this),value);
     3576
     3577  jQuery.fn.scrollTop = function (value) {
     3578    if (value === undefined) {
     3579      var nice = (this[0]) ? $.data(this[0], '__nicescroll') || false : false;
     3580      return (nice && nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
     3581    } else {
     3582      return this.each(function () {
     3583        var nice = $.data(this, '__nicescroll') || false;
     3584        (nice && nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call($(this), value);
    30163585      });
    30173586    }
    3018   }
    3019 
    3020 // override jQuery scrollLeft
    3021  
     3587  };
     3588
     3589  // override jQuery scrollLeft
    30223590  var _scrollLeft = jQuery.fn.scrollLeft; // preserve original function
    3023    
     3591
    30243592  $.cssHooks.pageXOffset = {
    3025     get: function(elem,computed,extra) {
    3026       var nice = $.data(elem,'__nicescroll')||false;
    3027       return (nice&&nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(elem);
     3593    get: function (elem, computed, extra) {
     3594      var nice = $.data(elem, '__nicescroll') || false;
     3595      return (nice && nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(elem);
    30283596    },
    3029     set: function(elem,value) {
    3030       var nice = $.data(elem,'__nicescroll')||false;   
    3031       (nice&&nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call(elem,value);
     3597    set: function (elem, value) {
     3598      var nice = $.data(elem, '__nicescroll') || false;
     3599      (nice && nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call(elem, value);
    30323600      return this;
    30333601    }
    30343602  };
    3035  
    3036 /* 
    3037   $.fx.step["scrollLeft"] = function(fx){
    3038     $.cssHooks["scrollLeft"].set( fx.elem, fx.now + fx.unit );
    3039   }; 
    3040 */ 
    3041  
    3042   jQuery.fn.scrollLeft = function(value) {   
    3043     if (typeof value == "undefined") {
    3044       var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
    3045       return (nice&&nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(this);
     3603
     3604  jQuery.fn.scrollLeft = function (value) {
     3605    if (value === undefined) {
     3606      var nice = (this[0]) ? $.data(this[0], '__nicescroll') || false : false;
     3607      return (nice && nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(this);
    30463608    } else {
    3047       return this.each(function() {     
    3048         var nice = $.data(this,'__nicescroll')||false;
    3049         (nice&&nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call($(this),value);
     3609      return this.each(function () {
     3610        var nice = $.data(this, '__nicescroll') || false;
     3611        (nice && nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call($(this), value);
    30503612      });
    30513613    }
    3052   }
    3053  
    3054   var NiceScrollArray = function(doms) {
     3614  };
     3615
     3616  var NiceScrollArray = function (doms) {
    30553617    var self = this;
    30563618    this.length = 0;
    30573619    this.name = "nicescrollarray";
    3058  
    3059     this.each = function(fn) {
    3060       for(var a=0;a<self.length;a++) fn.call(self[a]);
     3620
     3621    this.each = function (fn) {
     3622      $.each(self, fn);
    30613623      return self;
    30623624    };
    3063    
    3064     this.push = function(nice) {
    3065       self[self.length]=nice;
     3625
     3626    this.push = function (nice) {
     3627      self[self.length] = nice;
    30663628      self.length++;
    30673629    };
    3068    
    3069     this.eq = function(idx) {
     3630
     3631    this.eq = function (idx) {
    30703632      return self[idx];
    30713633    };
    3072    
     3634
    30733635    if (doms) {
    3074       for(a=0;a<doms.length;a++) {
    3075         var nice = $.data(doms[a],'__nicescroll')||false;
     3636      for (var a = 0; a < doms.length; a++) {
     3637        var nice = $.data(doms[a], '__nicescroll') || false;
    30763638        if (nice) {
    3077           this[this.length]=nice;
     3639          this[this.length] = nice;
    30783640          this.length++;
    30793641        }
    3080       };
     3642      }
    30813643    }
    3082    
     3644
    30833645    return this;
    30843646  };
    3085  
    3086   function mplex(el,lst,fn) {
    3087     for(var a=0;a<lst.length;a++) fn(el,lst[a]);
    3088   }
     3647
     3648  function mplex(el, lst, fn) {
     3649    for (var a = 0, l = lst.length; a < l; a++) fn(el, lst[a]);
     3650  }
    30893651  mplex(
    3090     NiceScrollArray.prototype,
    3091     ['show','hide','toggle','onResize','resize','remove','stop','doScrollPos'],
    3092     function(e,n) {
    3093       e[n] = function(){
     3652    NiceScrollArray.prototype, ['show', 'hide', 'toggle', 'onResize', 'resize', 'remove', 'stop', 'doScrollPos'],
     3653    function (e, n) {
     3654      e[n] = function () {
    30943655        var args = arguments;
    3095         return this.each(function(){         
    3096           this[n].apply(this,args);
     3656        return this.each(function () {
     3657          this[n].apply(this, args);
    30973658        });
    30983659      };
    30993660    }
    3100   ); 
    3101  
    3102   jQuery.fn.getNiceScroll = function(index) {
    3103     if (typeof index == "undefined") {
     3661  );
     3662
     3663  jQuery.fn.getNiceScroll = function (index) {
     3664    if (index === undefined) {
    31043665      return new NiceScrollArray(this);
    31053666    } else {
    3106       var nice = $.data(this[index],'__nicescroll')||false;
    3107       return nice;
     3667      return this[index] && $.data(this[index], '__nicescroll') || false;
    31083668    }
    31093669  };
    3110  
    3111   jQuery.extend(jQuery.expr[':'], {
    3112     nicescroll: function(a) {
    3113       return ($.data(a,'__nicescroll'))?true:false;
     3670
     3671  var pseudos = jQuery.expr.pseudos || jQuery.expr[':'];  // jQuery 3 migration
     3672  pseudos.nicescroll = function (a) {
     3673    return $.data(a, '__nicescroll') !== undefined;
     3674  };
     3675
     3676  $.fn.niceScroll = function (wrapper, _opt) {
     3677    if (_opt === undefined && typeof wrapper == "object" && !("jquery" in wrapper)) {
     3678      _opt = wrapper;
     3679      wrapper = false;
    31143680    }
    3115   }); 
    3116  
    3117   $.fn.niceScroll = function(wrapper,opt) {       
    3118     if (typeof opt=="undefined") {
    3119       if ((typeof wrapper=="object")&&!("jquery" in wrapper)) {
    3120         opt = wrapper;
    3121         wrapper = false;       
    3122       }
    3123     }
     3681
    31243682    var ret = new NiceScrollArray();
    3125     if (typeof opt=="undefined") opt = {};
    3126    
    3127     if (wrapper||false) {     
    3128       opt.doc = $(wrapper);
    3129       opt.win = $(this);
    3130     }   
    3131     var docundef = !("doc" in opt);   
    3132     if (!docundef&&!("win" in opt)) opt.win = $(this);   
    3133    
    3134     this.each(function() {
    3135       var nice = $(this).data('__nicescroll')||false;
     3683
     3684    this.each(function () {
     3685      var $this = $(this);
     3686
     3687      var opt = $.extend({}, _opt); // cloning
     3688
     3689      if (wrapper || false) {
     3690        var wrp = $(wrapper);
     3691        opt.doc = (wrp.length > 1) ? $(wrapper, $this) : wrp;
     3692        opt.win = $this;
     3693      }
     3694      var docundef = !("doc" in opt);
     3695      if (!docundef && !("win" in opt)) opt.win = $this;
     3696
     3697      var nice = $this.data('__nicescroll') || false;
    31363698      if (!nice) {
    3137         opt.doc = (docundef) ? $(this) : opt.doc;
    3138         nice = new NiceScrollClass(opt,$(this));       
    3139         $(this).data('__nicescroll',nice);
     3699        opt.doc = opt.doc || $this;
     3700        nice = new NiceScrollClass(opt, $this);
     3701        $this.data('__nicescroll', nice);
    31403702      }
    31413703      ret.push(nice);
    31423704    });
    3143     return (ret.length==1) ? ret[0] : ret;
     3705
     3706    return (ret.length === 1) ? ret[0] : ret;
    31443707  };
    3145  
    3146   window.NiceScroll = {
    3147     getjQuery:function(){return jQuery}
     3708
     3709  _win.NiceScroll = {
     3710    getjQuery: function () {
     3711      return jQuery;
     3712    }
    31483713  };
    3149  
     3714
    31503715  if (!$.nicescroll) {
    3151    $.nicescroll = new NiceScrollArray();
    3152    $.nicescroll.options = _globaloptions;
     3716    $.nicescroll = new NiceScrollArray();
     3717    $.nicescroll.options = _globaloptions;
    31533718  }
    3154  
    3155 })( jQuery );
    3156  
     3719
     3720}));
  • ws-custom-scrollbar/trunk/js/jquery.nicescroll.min.js

    r1271098 r3126870  
    1 /* jquery.nicescroll 3.2.0 InuYaksa*2013 MIT http://areaaperta.com/nicescroll */(function(e){var y=!1,D=!1,J=5E3,K=2E3,x=0,L=function(){var e=document.getElementsByTagName("script"),e=e[e.length-1].src.split("?")[0];return 0<e.split("/").length?e.split("/").slice(0,-1).join("/")+"/":""}();Array.prototype.forEach||(Array.prototype.forEach=function(e,c){for(var h=0,l=this.length;h<l;++h)e.call(c,this[h],h,this)});var v=window.requestAnimationFrame||!1,w=window.cancelAnimationFrame||!1;["ms","moz","webkit","o"].forEach(function(e){v||(v=window[e+"RequestAnimationFrame"]);w||(w=
    2 window[e+"CancelAnimationFrame"]||window[e+"CancelRequestAnimationFrame"])});var z=window.MutationObserver||window.WebKitMutationObserver||!1,F={zindex:"auto",cursoropacitymin:0,cursoropacitymax:1,cursorcolor:"#424242",cursorwidth:"5px",cursorborder:"1px solid #fff",cursorborderradius:"5px",scrollspeed:60,mousescrollstep:24,touchbehavior:!1,hwacceleration:!0,usetransition:!0,boxzoom:!1,dblclickzoom:!0,gesturezoom:!0,grabcursorenabled:!0,autohidemode:!0,background:"",iframeautoresize:!0,cursorminheight:32,
    3 preservenativescrolling:!0,railoffset:!1,bouncescroll:!0,spacebarenabled:!0,railpadding:{top:0,right:0,left:0,bottom:0},disableoutline:!0,horizrailenabled:!0,railalign:"right",railvalign:"bottom",enabletranslate3d:!0,enablemousewheel:!0,enablekeyboard:!0,smoothscroll:!0,sensitiverail:!0,enablemouselockapi:!0,cursorfixedheight:!1,directionlockdeadzone:6,hidecursordelay:400,nativeparentscrolling:!0,enablescrollonselection:!0,overflowx:!0,overflowy:!0,cursordragspeed:0.3,rtlmode:!1,cursordragontouch:!1},
    4 E=!1,M=function(){if(E)return E;var e=document.createElement("DIV"),c={haspointerlock:"pointerLockElement"in document||"mozPointerLockElement"in document||"webkitPointerLockElement"in document};c.isopera="opera"in window;c.isopera12=c.isopera&&"getUserMedia"in navigator;c.isie="all"in document&&"attachEvent"in e&&!c.isopera;c.isieold=c.isie&&!("msInterpolationMode"in e.style);c.isie7=c.isie&&!c.isieold&&(!("documentMode"in document)||7==document.documentMode);c.isie8=c.isie&&"documentMode"in document&&
    5 8==document.documentMode;c.isie9=c.isie&&"performance"in window&&9<=document.documentMode;c.isie10=c.isie&&"performance"in window&&10<=document.documentMode;c.isie9mobile=/iemobile.9/i.test(navigator.userAgent);c.isie9mobile&&(c.isie9=!1);c.isie7mobile=!c.isie9mobile&&c.isie7&&/iemobile/i.test(navigator.userAgent);c.ismozilla="MozAppearance"in e.style;c.iswebkit="WebkitAppearance"in e.style;c.ischrome="chrome"in window;c.ischrome22=c.ischrome&&c.haspointerlock;c.ischrome26=c.ischrome&&"transition"in
    6 e.style;c.cantouch="ontouchstart"in document.documentElement||"ontouchstart"in window;c.hasmstouch=window.navigator.msPointerEnabled||!1;c.ismac=/^mac$/i.test(navigator.platform);c.isios=c.cantouch&&/iphone|ipad|ipod/i.test(navigator.platform);c.isios4=c.isios&&!("seal"in Object);c.isandroid=/android/i.test(navigator.userAgent);c.trstyle=!1;c.hastransform=!1;c.hastranslate3d=!1;c.transitionstyle=!1;c.hastransition=!1;c.transitionend=!1;for(var h=["transform","msTransform","webkitTransform","MozTransform",
    7 "OTransform"],l=0;l<h.length;l++)if("undefined"!=typeof e.style[h[l]]){c.trstyle=h[l];break}c.hastransform=!1!=c.trstyle;c.hastransform&&(e.style[c.trstyle]="translate3d(1px,2px,3px)",c.hastranslate3d=/translate3d/.test(e.style[c.trstyle]));c.transitionstyle=!1;c.prefixstyle="";c.transitionend=!1;for(var h="transition webkitTransition MozTransition OTransition OTransition msTransition KhtmlTransition".split(" "),n=" -webkit- -moz- -o- -o -ms- -khtml-".split(" "),t="transitionend webkitTransitionEnd transitionend otransitionend oTransitionEnd msTransitionEnd KhtmlTransitionEnd".split(" "),
    8 l=0;l<h.length;l++)if(h[l]in e.style){c.transitionstyle=h[l];c.prefixstyle=n[l];c.transitionend=t[l];break}c.ischrome26&&(c.prefixstyle=n[1]);c.hastransition=c.transitionstyle;a:{h=["-moz-grab","-webkit-grab","grab"];if(c.ischrome&&!c.ischrome22||c.isie)h=[];for(l=0;l<h.length;l++)if(n=h[l],e.style.cursor=n,e.style.cursor==n){h=n;break a}h="url(http://www.google.com/intl/en_ALL/mapfiles/openhand.cur),n-resize"}c.cursorgrabvalue=h;c.hasmousecapture="setCapture"in e;c.hasMutationObserver=!1!==z;return E=
    9 c},N=function(k,c){function h(){var d=b.win;if("zIndex"in d)return d.zIndex();for(;0<d.length&&9!=d[0].nodeType;){var c=d.css("zIndex");if(!isNaN(c)&&0!=c)return parseInt(c);d=d.parent()}return!1}function l(d,c,g){c=d.css(c);d=parseFloat(c);return isNaN(d)?(d=u[c]||0,g=3==d?g?b.win.outerHeight()-b.win.innerHeight():b.win.outerWidth()-b.win.innerWidth():1,b.isie8&&d&&(d+=1),g?d:0):d}function n(d,c,g,e){b._bind(d,c,function(b){b=b?b:window.event;var e={original:b,target:b.target||b.srcElement,type:"wheel",
    10 deltaMode:"MozMousePixelScroll"==b.type?0:1,deltaX:0,deltaZ:0,preventDefault:function(){b.preventDefault?b.preventDefault():b.returnValue=!1;return!1},stopImmediatePropagation:function(){b.stopImmediatePropagation?b.stopImmediatePropagation():b.cancelBubble=!0}};"mousewheel"==c?(e.deltaY=-0.025*b.wheelDelta,b.wheelDeltaX&&(e.deltaX=-0.025*b.wheelDeltaX)):e.deltaY=b.detail;return g.call(d,e)},e)}function t(d,c,g){var e,f;0==d.deltaMode?(e=-Math.floor(d.deltaX*(b.opt.mousescrollstep/54)),f=-Math.floor(d.deltaY*
    11 (b.opt.mousescrollstep/54))):1==d.deltaMode&&(e=-Math.floor(d.deltaX*b.opt.mousescrollstep),f=-Math.floor(d.deltaY*b.opt.mousescrollstep));c&&(0==e&&f)&&(e=f,f=0);e&&(b.scrollmom&&b.scrollmom.stop(),b.lastdeltax+=e,b.debounced("mousewheelx",function(){var d=b.lastdeltax;b.lastdeltax=0;b.rail.drag||b.doScrollLeftBy(d)},120));if(f){if(b.opt.nativeparentscrolling&&g&&!b.ispage&&!b.zoomactive)if(0>f){if(b.getScrollTop()>=b.page.maxh)return!0}else if(0>=b.getScrollTop())return!0;b.scrollmom&&b.scrollmom.stop();
    12 b.lastdeltay+=f;b.debounced("mousewheely",function(){var d=b.lastdeltay;b.lastdeltay=0;b.rail.drag||b.doScrollBy(d)},120)}d.stopImmediatePropagation();return d.preventDefault()}var b=this;this.version="3.4.0";this.name="nicescroll";this.me=c;this.opt={doc:e("body"),win:!1};e.extend(this.opt,F);this.opt.snapbackspeed=80;if(k)for(var q in b.opt)"undefined"!=typeof k[q]&&(b.opt[q]=k[q]);this.iddoc=(this.doc=b.opt.doc)&&this.doc[0]?this.doc[0].id||"":"";this.ispage=/BODY|HTML/.test(b.opt.win?b.opt.win[0].nodeName:
    13 this.doc[0].nodeName);this.haswrapper=!1!==b.opt.win;this.win=b.opt.win||(this.ispage?e(window):this.doc);this.docscroll=this.ispage&&!this.haswrapper?e(window):this.win;this.body=e("body");this.iframe=this.isfixed=this.viewport=!1;this.isiframe="IFRAME"==this.doc[0].nodeName&&"IFRAME"==this.win[0].nodeName;this.istextarea="TEXTAREA"==this.win[0].nodeName;this.forcescreen=!1;this.canshowonmouseevent="scroll"!=b.opt.autohidemode;this.page=this.view=this.onzoomout=this.onzoomin=this.onscrollcancel=
    14 this.onscrollend=this.onscrollstart=this.onclick=this.ongesturezoom=this.onkeypress=this.onmousewheel=this.onmousemove=this.onmouseup=this.onmousedown=!1;this.scroll={x:0,y:0};this.scrollratio={x:0,y:0};this.cursorheight=20;this.scrollvaluemax=0;this.observerremover=this.observer=this.scrollmom=this.scrollrunning=this.checkrtlmode=!1;do this.id="ascrail"+K++;while(document.getElementById(this.id));this.hasmousefocus=this.hasfocus=this.zoomactive=this.zoom=this.selectiondrag=this.cursorfreezed=this.cursor=
    15 this.rail=!1;this.visibility=!0;this.hidden=this.locked=!1;this.cursoractive=!0;this.overflowx=b.opt.overflowx;this.overflowy=b.opt.overflowy;this.nativescrollingarea=!1;this.checkarea=0;this.events=[];this.saved={};this.delaylist={};this.synclist={};this.lastdeltay=this.lastdeltax=0;this.detected=M();var f=e.extend({},this.detected);this.ishwscroll=(this.canhwscroll=f.hastransform&&b.opt.hwacceleration)&&b.haswrapper;this.istouchcapable=!1;f.cantouch&&(f.ischrome&&!f.isios&&!f.isandroid)&&(this.istouchcapable=
    16 !0,f.cantouch=!1);f.cantouch&&(f.ismozilla&&!f.isios)&&(this.istouchcapable=!0,f.cantouch=!1);b.opt.enablemouselockapi||(f.hasmousecapture=!1,f.haspointerlock=!1);this.delayed=function(d,c,g,e){var f=b.delaylist[d],h=(new Date).getTime();if(!e&&f&&f.tt)return!1;f&&f.tt&&clearTimeout(f.tt);if(f&&f.last+g>h&&!f.tt)b.delaylist[d]={last:h+g,tt:setTimeout(function(){b.delaylist[d].tt=0;c.call()},g)};else if(!f||!f.tt)b.delaylist[d]={last:h,tt:0},setTimeout(function(){c.call()},0)};this.debounced=function(d,
    17 c,g){var f=b.delaylist[d];(new Date).getTime();b.delaylist[d]=c;f||setTimeout(function(){var c=b.delaylist[d];b.delaylist[d]=!1;c.call()},g)};this.synched=function(d,c){b.synclist[d]=c;(function(){b.onsync||(v(function(){b.onsync=!1;for(d in b.synclist){var c=b.synclist[d];c&&c.call(b);b.synclist[d]=!1}}),b.onsync=!0)})();return d};this.unsynched=function(d){b.synclist[d]&&(b.synclist[d]=!1)};this.css=function(d,c){for(var g in c)b.saved.css.push([d,g,d.css(g)]),d.css(g,c[g])};this.scrollTop=function(d){return"undefined"==
    18 typeof d?b.getScrollTop():b.setScrollTop(d)};this.scrollLeft=function(d){return"undefined"==typeof d?b.getScrollLeft():b.setScrollLeft(d)};BezierClass=function(b,c,g,f,e,h,l){this.st=b;this.ed=c;this.spd=g;this.p1=f||0;this.p2=e||1;this.p3=h||0;this.p4=l||1;this.ts=(new Date).getTime();this.df=this.ed-this.st};BezierClass.prototype={B2:function(b){return 3*b*b*(1-b)},B3:function(b){return 3*b*(1-b)*(1-b)},B4:function(b){return(1-b)*(1-b)*(1-b)},getNow:function(){var b=1-((new Date).getTime()-this.ts)/
    19 this.spd,c=this.B2(b)+this.B3(b)+this.B4(b);return 0>b?this.ed:this.st+Math.round(this.df*c)},update:function(b,c){this.st=this.getNow();this.ed=b;this.spd=c;this.ts=(new Date).getTime();this.df=this.ed-this.st;return this}};if(this.ishwscroll){this.doc.translate={x:0,y:0,tx:"0px",ty:"0px"};f.hastranslate3d&&f.isios&&this.doc.css("-webkit-backface-visibility","hidden");var r=function(){var d=b.doc.css(f.trstyle);return d&&"matrix"==d.substr(0,6)?d.replace(/^.*\((.*)\)$/g,"$1").replace(/px/g,"").split(/, +/):
    20 !1};this.getScrollTop=function(d){if(!d){if(d=r())return 16==d.length?-d[13]:-d[5];if(b.timerscroll&&b.timerscroll.bz)return b.timerscroll.bz.getNow()}return b.doc.translate.y};this.getScrollLeft=function(d){if(!d){if(d=r())return 16==d.length?-d[12]:-d[4];if(b.timerscroll&&b.timerscroll.bh)return b.timerscroll.bh.getNow()}return b.doc.translate.x};this.notifyScrollEvent=document.createEvent?function(b){var c=document.createEvent("UIEvents");c.initUIEvent("scroll",!1,!0,window,1);b.dispatchEvent(c)}:
    21 document.fireEvent?function(b){var c=document.createEventObject();b.fireEvent("onscroll");c.cancelBubble=!0}:function(b,c){};f.hastranslate3d&&b.opt.enabletranslate3d?(this.setScrollTop=function(d,c){b.doc.translate.y=d;b.doc.translate.ty=-1*d+"px";b.doc.css(f.trstyle,"translate3d("+b.doc.translate.tx+","+b.doc.translate.ty+",0px)");c||b.notifyScrollEvent(b.win[0])},this.setScrollLeft=function(d,c){b.doc.translate.x=d;b.doc.translate.tx=-1*d+"px";b.doc.css(f.trstyle,"translate3d("+b.doc.translate.tx+
    22 ","+b.doc.translate.ty+",0px)");c||b.notifyScrollEvent(b.win[0])}):(this.setScrollTop=function(d,c){b.doc.translate.y=d;b.doc.translate.ty=-1*d+"px";b.doc.css(f.trstyle,"translate("+b.doc.translate.tx+","+b.doc.translate.ty+")");c||b.notifyScrollEvent(b.win[0])},this.setScrollLeft=function(d,c){b.doc.translate.x=d;b.doc.translate.tx=-1*d+"px";b.doc.css(f.trstyle,"translate("+b.doc.translate.tx+","+b.doc.translate.ty+")");c||b.notifyScrollEvent(b.win[0])})}else this.getScrollTop=function(){return b.docscroll.scrollTop()},
    23 this.setScrollTop=function(d){return b.docscroll.scrollTop(d)},this.getScrollLeft=function(){return b.docscroll.scrollLeft()},this.setScrollLeft=function(d){return b.docscroll.scrollLeft(d)};this.getTarget=function(b){return!b?!1:b.target?b.target:b.srcElement?b.srcElement:!1};this.hasParent=function(b,c){if(!b)return!1;for(var g=b.target||b.srcElement||b||!1;g&&g.id!=c;)g=g.parentNode||!1;return!1!==g};var u={thin:1,medium:3,thick:5};this.getOffset=function(){if(b.isfixed)return{top:parseFloat(b.win.css("top")),
    24 left:parseFloat(b.win.css("left"))};if(!b.viewport)return b.win.offset();var d=b.win.offset(),c=b.viewport.offset();return{top:d.top-c.top+b.viewport.scrollTop(),left:d.left-c.left+b.viewport.scrollLeft()}};this.updateScrollBar=function(d){if(b.ishwscroll)b.rail.css({height:b.win.innerHeight()}),b.railh&&b.railh.css({width:b.win.innerWidth()});else{var c=b.getOffset(),g=c.top,f=c.left,g=g+l(b.win,"border-top-width",!0);b.win.outerWidth();b.win.innerWidth();var f=f+(b.rail.align?b.win.outerWidth()-
    25 l(b.win,"border-right-width")-b.rail.width:l(b.win,"border-left-width")),e=b.opt.railoffset;e&&(e.top&&(g+=e.top),b.rail.align&&e.left&&(f+=e.left));b.locked||b.rail.css({top:g,left:f,height:d?d.h:b.win.innerHeight()});b.zoom&&b.zoom.css({top:g+1,left:1==b.rail.align?f-20:f+b.rail.width+4});b.railh&&!b.locked&&(g=c.top,f=c.left,d=b.railh.align?g+l(b.win,"border-top-width",!0)+b.win.innerHeight()-b.railh.height:g+l(b.win,"border-top-width",!0),f+=l(b.win,"border-left-width"),b.railh.css({top:d,left:f,
    26 width:b.railh.width}))}};this.doRailClick=function(d,c,g){var f;b.locked||(b.cancelEvent(d),c?(c=g?b.doScrollLeft:b.doScrollTop,f=g?(d.pageX-b.railh.offset().left-b.cursorwidth/2)*b.scrollratio.x:(d.pageY-b.rail.offset().top-b.cursorheight/2)*b.scrollratio.y,c(f)):(c=g?b.doScrollLeftBy:b.doScrollBy,f=g?b.scroll.x:b.scroll.y,d=g?d.pageX-b.railh.offset().left:d.pageY-b.rail.offset().top,g=g?b.view.w:b.view.h,f>=d?c(g):c(-g)))};b.hasanimationframe=v;b.hascancelanimationframe=w;b.hasanimationframe?b.hascancelanimationframe||
    27 (w=function(){b.cancelAnimationFrame=!0}):(v=function(b){return setTimeout(b,15-Math.floor(+new Date/1E3)%16)},w=clearInterval);this.init=function(){b.saved.css=[];if(f.isie7mobile)return!0;f.hasmstouch&&b.css(b.ispage?e("html"):b.win,{"-ms-touch-action":"none"});b.zindex="auto";b.zindex=!b.ispage&&"auto"==b.opt.zindex?h()||"auto":b.opt.zindex;!b.ispage&&"auto"!=b.zindex&&b.zindex>x&&(x=b.zindex);b.isie&&(0==b.zindex&&"auto"==b.opt.zindex)&&(b.zindex="auto");if(!b.ispage||!f.cantouch&&!f.isieold&&
    28 !f.isie9mobile){var d=b.docscroll;b.ispage&&(d=b.haswrapper?b.win:b.doc);f.isie9mobile||b.css(d,{"overflow-y":"hidden"});b.ispage&&f.isie7&&("BODY"==b.doc[0].nodeName?b.css(e("html"),{"overflow-y":"hidden"}):"HTML"==b.doc[0].nodeName&&b.css(e("body"),{"overflow-y":"hidden"}));f.isios&&(!b.ispage&&!b.haswrapper)&&b.css(e("body"),{"-webkit-overflow-scrolling":"touch"});var c=e(document.createElement("div"));c.css({position:"relative",top:0,"float":"right",width:b.opt.cursorwidth,height:"0px","background-color":b.opt.cursorcolor,
    29 border:b.opt.cursorborder,"background-clip":"padding-box","-webkit-border-radius":b.opt.cursorborderradius,"-moz-border-radius":b.opt.cursorborderradius,"border-radius":b.opt.cursorborderradius});c.hborder=parseFloat(c.outerHeight()-c.innerHeight());b.cursor=c;var g=e(document.createElement("div"));g.attr("id",b.id);g.addClass("nicescroll-rails");var l,k,n=["left","right"],G;for(G in n)k=n[G],(l=b.opt.railpadding[k])?g.css("padding-"+k,l+"px"):b.opt.railpadding[k]=0;g.append(c);g.width=Math.max(parseFloat(b.opt.cursorwidth),
    30 c.outerWidth())+b.opt.railpadding.left+b.opt.railpadding.right;g.css({width:g.width+"px",zIndex:b.zindex,background:b.opt.background,cursor:"default"});g.visibility=!0;g.scrollable=!0;g.align="left"==b.opt.railalign?0:1;b.rail=g;c=b.rail.drag=!1;b.opt.boxzoom&&(!b.ispage&&!f.isieold)&&(c=document.createElement("div"),b.bind(c,"click",b.doZoom),b.zoom=e(c),b.zoom.css({cursor:"pointer","z-index":b.zindex,backgroundImage:"url("+L+"zoomico.png)",height:18,width:18,backgroundPosition:"0px 0px"}),b.opt.dblclickzoom&&
    31 b.bind(b.win,"dblclick",b.doZoom),f.cantouch&&b.opt.gesturezoom&&(b.ongesturezoom=function(d){1.5<d.scale&&b.doZoomIn(d);0.8>d.scale&&b.doZoomOut(d);return b.cancelEvent(d)},b.bind(b.win,"gestureend",b.ongesturezoom)));b.railh=!1;if(b.opt.horizrailenabled){b.css(d,{"overflow-x":"hidden"});c=e(document.createElement("div"));c.css({position:"relative",top:0,height:b.opt.cursorwidth,width:"0px","background-color":b.opt.cursorcolor,border:b.opt.cursorborder,"background-clip":"padding-box","-webkit-border-radius":b.opt.cursorborderradius,
    32 "-moz-border-radius":b.opt.cursorborderradius,"border-radius":b.opt.cursorborderradius});c.wborder=parseFloat(c.outerWidth()-c.innerWidth());b.cursorh=c;var m=e(document.createElement("div"));m.attr("id",b.id+"-hr");m.addClass("nicescroll-rails");m.height=Math.max(parseFloat(b.opt.cursorwidth),c.outerHeight());m.css({height:m.height+"px",zIndex:b.zindex,background:b.opt.background});m.append(c);m.visibility=!0;m.scrollable=!0;m.align="top"==b.opt.railvalign?0:1;b.railh=m;b.railh.drag=!1}b.ispage?
    33 (g.css({position:"fixed",top:"0px",height:"100%"}),g.align?g.css({right:"0px"}):g.css({left:"0px"}),b.body.append(g),b.railh&&(m.css({position:"fixed",left:"0px",width:"100%"}),m.align?m.css({bottom:"0px"}):m.css({top:"0px"}),b.body.append(m))):(b.ishwscroll?("static"==b.win.css("position")&&b.css(b.win,{position:"relative"}),d="HTML"==b.win[0].nodeName?b.body:b.win,b.zoom&&(b.zoom.css({position:"absolute",top:1,right:0,"margin-right":g.width+4}),d.append(b.zoom)),g.css({position:"absolute",top:0}),
    34 g.align?g.css({right:0}):g.css({left:0}),d.append(g),m&&(m.css({position:"absolute",left:0,bottom:0}),m.align?m.css({bottom:0}):m.css({top:0}),d.append(m))):(b.isfixed="fixed"==b.win.css("position"),d=b.isfixed?"fixed":"absolute",b.isfixed||(b.viewport=b.getViewport(b.win[0])),b.viewport&&(b.body=b.viewport,!1==/relative|absolute/.test(b.viewport.css("position"))&&b.css(b.viewport,{position:"relative"})),g.css({position:d}),b.zoom&&b.zoom.css({position:d}),b.updateScrollBar(),b.body.append(g),b.zoom&&
    35 b.body.append(b.zoom),b.railh&&(m.css({position:d}),b.body.append(m))),f.isios&&b.css(b.win,{"-webkit-tap-highlight-color":"rgba(0,0,0,0)","-webkit-touch-callout":"none"}),f.isie&&b.opt.disableoutline&&b.win.attr("hideFocus","true"),f.iswebkit&&b.opt.disableoutline&&b.win.css({outline:"none"}));!1===b.opt.autohidemode?(b.autohidedom=!1,b.rail.css({opacity:b.opt.cursoropacitymax}),b.railh&&b.railh.css({opacity:b.opt.cursoropacitymax})):!0===b.opt.autohidemode?(b.autohidedom=e().add(b.rail),f.isie8&&
    36 (b.autohidedom=b.autohidedom.add(b.cursor)),b.railh&&(b.autohidedom=b.autohidedom.add(b.railh)),b.railh&&f.isie8&&(b.autohidedom=b.autohidedom.add(b.cursorh))):"scroll"==b.opt.autohidemode?(b.autohidedom=e().add(b.rail),b.railh&&(b.autohidedom=b.autohidedom.add(b.railh))):"cursor"==b.opt.autohidemode?(b.autohidedom=e().add(b.cursor),b.railh&&(b.autohidedom=b.autohidedom.add(b.cursorh))):"hidden"==b.opt.autohidemode&&(b.autohidedom=!1,b.hide(),b.locked=!1);if(f.isie9mobile)b.scrollmom=new H(b),b.onmangotouch=
    37 function(d){d=b.getScrollTop();var c=b.getScrollLeft();if(d==b.scrollmom.lastscrolly&&c==b.scrollmom.lastscrollx)return!0;var g=d-b.mangotouch.sy,f=c-b.mangotouch.sx;if(0!=Math.round(Math.sqrt(Math.pow(f,2)+Math.pow(g,2)))){var p=0>g?-1:1,e=0>f?-1:1,h=+new Date;b.mangotouch.lazy&&clearTimeout(b.mangotouch.lazy);80<h-b.mangotouch.tm||b.mangotouch.dry!=p||b.mangotouch.drx!=e?(b.scrollmom.stop(),b.scrollmom.reset(c,d),b.mangotouch.sy=d,b.mangotouch.ly=d,b.mangotouch.sx=c,b.mangotouch.lx=c,b.mangotouch.dry=
    38 p,b.mangotouch.drx=e,b.mangotouch.tm=h):(b.scrollmom.stop(),b.scrollmom.update(b.mangotouch.sx-f,b.mangotouch.sy-g),b.mangotouch.tm=h,g=Math.max(Math.abs(b.mangotouch.ly-d),Math.abs(b.mangotouch.lx-c)),b.mangotouch.ly=d,b.mangotouch.lx=c,2<g&&(b.mangotouch.lazy=setTimeout(function(){b.mangotouch.lazy=!1;b.mangotouch.dry=0;b.mangotouch.drx=0;b.mangotouch.tm=0;b.scrollmom.doMomentum(30)},100)))}},g=b.getScrollTop(),m=b.getScrollLeft(),b.mangotouch={sy:g,ly:g,dry:0,sx:m,lx:m,drx:0,lazy:!1,tm:0},b.bind(b.docscroll,
    39 "scroll",b.onmangotouch);else{if(f.cantouch||b.istouchcapable||b.opt.touchbehavior||f.hasmstouch){b.scrollmom=new H(b);b.ontouchstart=function(d){if(d.pointerType&&2!=d.pointerType)return!1;if(!b.locked){if(f.hasmstouch)for(var c=d.target?d.target:!1;c;){var g=e(c).getNiceScroll();if(0<g.length&&g[0].me==b.me)break;if(0<g.length)return!1;if("DIV"==c.nodeName&&c.id==b.id)break;c=c.parentNode?c.parentNode:!1}b.cancelScroll();if((c=b.getTarget(d))&&/INPUT/i.test(c.nodeName)&&/range/i.test(c.type))return b.stopPropagation(d);
    40 !("clientX"in d)&&"changedTouches"in d&&(d.clientX=d.changedTouches[0].clientX,d.clientY=d.changedTouches[0].clientY);b.forcescreen&&(g=d,d={original:d.original?d.original:d},d.clientX=g.screenX,d.clientY=g.screenY);b.rail.drag={x:d.clientX,y:d.clientY,sx:b.scroll.x,sy:b.scroll.y,st:b.getScrollTop(),sl:b.getScrollLeft(),pt:2,dl:!1};if(b.ispage||!b.opt.directionlockdeadzone)b.rail.drag.dl="f";else{var g=e(window).width(),p=e(window).height(),h=Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
    41 l=Math.max(document.body.scrollHeight,document.documentElement.scrollHeight),p=Math.max(0,l-p),g=Math.max(0,h-g);b.rail.drag.ck=!b.rail.scrollable&&b.railh.scrollable?0<p?"v":!1:b.rail.scrollable&&!b.railh.scrollable?0<g?"h":!1:!1;b.rail.drag.ck||(b.rail.drag.dl="f")}b.opt.touchbehavior&&(b.isiframe&&f.isie)&&(g=b.win.position(),b.rail.drag.x+=g.left,b.rail.drag.y+=g.top);b.hasmoving=!1;b.lastmouseup=!1;b.scrollmom.reset(d.clientX,d.clientY);if(!f.cantouch&&!this.istouchcapable&&!f.hasmstouch){if(!c||
    42 !/INPUT|SELECT|TEXTAREA/i.test(c.nodeName))return!b.ispage&&f.hasmousecapture&&c.setCapture(),b.cancelEvent(d);/SUBMIT|CANCEL|BUTTON/i.test(e(c).attr("type"))&&(pc={tg:c,click:!1},b.preventclick=pc)}}};b.ontouchend=function(d){if(d.pointerType&&2!=d.pointerType)return!1;if(b.rail.drag&&2==b.rail.drag.pt&&(b.scrollmom.doMomentum(),b.rail.drag=!1,b.hasmoving&&(b.hasmoving=!1,b.lastmouseup=!0,b.hideCursor(),f.hasmousecapture&&document.releaseCapture(),!f.cantouch)))return b.cancelEvent(d)};var q=b.opt.touchbehavior&&
    43 b.isiframe&&!f.hasmousecapture;b.ontouchmove=function(d,c){if(d.pointerType&&2!=d.pointerType)return!1;if(b.rail.drag&&2==b.rail.drag.pt){if(f.cantouch&&"undefined"==typeof d.original)return!0;b.hasmoving=!0;b.preventclick&&!b.preventclick.click&&(b.preventclick.click=b.preventclick.tg.onclick||!1,b.preventclick.tg.onclick=b.onpreventclick);d=e.extend({original:d},d);"changedTouches"in d&&(d.clientX=d.changedTouches[0].clientX,d.clientY=d.changedTouches[0].clientY);if(b.forcescreen){var g=d;d={original:d.original?
    44 d.original:d};d.clientX=g.screenX;d.clientY=g.screenY}g=ofy=0;if(q&&!c){var p=b.win.position(),g=-p.left;ofy=-p.top}var h=d.clientY+ofy,p=h-b.rail.drag.y,l=d.clientX+g,k=l-b.rail.drag.x,s=b.rail.drag.st-p;b.ishwscroll&&b.opt.bouncescroll?0>s?s=Math.round(s/2):s>b.page.maxh&&(s=b.page.maxh+Math.round((s-b.page.maxh)/2)):(0>s&&(h=s=0),s>b.page.maxh&&(s=b.page.maxh,h=0));if(b.railh&&b.railh.scrollable){var m=b.rail.drag.sl-k;b.ishwscroll&&b.opt.bouncescroll?0>m?m=Math.round(m/2):m>b.page.maxw&&(m=b.page.maxw+
    45 Math.round((m-b.page.maxw)/2)):(0>m&&(l=m=0),m>b.page.maxw&&(m=b.page.maxw,l=0))}g=!1;if(b.rail.drag.dl)g=!0,"v"==b.rail.drag.dl?m=b.rail.drag.sl:"h"==b.rail.drag.dl&&(s=b.rail.drag.st);else{var p=Math.abs(p),k=Math.abs(k),n=b.opt.directionlockdeadzone;if("v"==b.rail.drag.ck){if(p>n&&k<=0.3*p)return b.rail.drag=!1,!0;k>n&&(b.rail.drag.dl="f",e("body").scrollTop(e("body").scrollTop()))}else if("h"==b.rail.drag.ck){if(k>n&&p<=0.3*az)return b.rail.drag=!1,!0;p>n&&(b.rail.drag.dl="f",e("body").scrollLeft(e("body").scrollLeft()))}}b.synched("touchmove",
    46 function(){b.rail.drag&&2==b.rail.drag.pt&&(b.prepareTransition&&b.prepareTransition(0),b.rail.scrollable&&b.setScrollTop(s),b.scrollmom.update(l,h),b.railh&&b.railh.scrollable?(b.setScrollLeft(m),b.showCursor(s,m)):b.showCursor(s),f.isie10&&document.selection.clear())});f.ischrome&&b.istouchcapable&&(g=!1);if(g)return b.cancelEvent(d)}}}b.onmousedown=function(d,c){if(!(b.rail.drag&&1!=b.rail.drag.pt)){if(b.locked)return b.cancelEvent(d);b.cancelScroll();b.rail.drag={x:d.clientX,y:d.clientY,sx:b.scroll.x,
    47 sy:b.scroll.y,pt:1,hr:!!c};var g=b.getTarget(d);!b.ispage&&f.hasmousecapture&&g.setCapture();b.isiframe&&!f.hasmousecapture&&(b.saved.csspointerevents=b.doc.css("pointer-events"),b.css(b.doc,{"pointer-events":"none"}));return b.cancelEvent(d)}};b.onmouseup=function(d){if(b.rail.drag&&(f.hasmousecapture&&document.releaseCapture(),b.isiframe&&!f.hasmousecapture&&b.doc.css("pointer-events",b.saved.csspointerevents),1==b.rail.drag.pt))return b.rail.drag=!1,b.cancelEvent(d)};b.onmousemove=function(d){if(b.rail.drag&&
    48 1==b.rail.drag.pt){if(f.ischrome&&0==d.which)return b.onmouseup(d);b.cursorfreezed=!0;if(b.rail.drag.hr){b.scroll.x=b.rail.drag.sx+(d.clientX-b.rail.drag.x);0>b.scroll.x&&(b.scroll.x=0);var c=b.scrollvaluemaxw;b.scroll.x>c&&(b.scroll.x=c)}else b.scroll.y=b.rail.drag.sy+(d.clientY-b.rail.drag.y),0>b.scroll.y&&(b.scroll.y=0),c=b.scrollvaluemax,b.scroll.y>c&&(b.scroll.y=c);b.synched("mousemove",function(){b.rail.drag&&1==b.rail.drag.pt&&(b.showCursor(),b.rail.drag.hr?b.doScrollLeft(Math.round(b.scroll.x*
    49 b.scrollratio.x),b.opt.cursordragspeed):b.doScrollTop(Math.round(b.scroll.y*b.scrollratio.y),b.opt.cursordragspeed))});return b.cancelEvent(d)}};if(f.cantouch||b.opt.touchbehavior)b.onpreventclick=function(d){if(b.preventclick)return b.preventclick.tg.onclick=b.preventclick.click,b.preventclick=!1,b.cancelEvent(d)},b.bind(b.win,"mousedown",b.ontouchstart),b.onclick=f.isios?!1:function(d){return b.lastmouseup?(b.lastmouseup=!1,b.cancelEvent(d)):!0},b.opt.grabcursorenabled&&f.cursorgrabvalue&&(b.css(b.ispage?
    50 b.doc:b.win,{cursor:f.cursorgrabvalue}),b.css(b.rail,{cursor:f.cursorgrabvalue}));else{var r=function(d){if(b.selectiondrag){if(d){var c=b.win.outerHeight();d=d.pageY-b.selectiondrag.top;0<d&&d<c&&(d=0);d>=c&&(d-=c);b.selectiondrag.df=d}0!=b.selectiondrag.df&&(b.doScrollBy(2*-Math.floor(b.selectiondrag.df/6)),b.debounced("doselectionscroll",function(){r()},50))}};b.hasTextSelected="getSelection"in document?function(){return 0<document.getSelection().rangeCount}:"selection"in document?function(){return"None"!=
    51 document.selection.type}:function(){return!1};b.onselectionstart=function(d){b.ispage||(b.selectiondrag=b.win.offset())};b.onselectionend=function(d){b.selectiondrag=!1};b.onselectiondrag=function(d){b.selectiondrag&&b.hasTextSelected()&&b.debounced("selectionscroll",function(){r(d)},250)}}f.hasmstouch&&(b.css(b.rail,{"-ms-touch-action":"none"}),b.css(b.cursor,{"-ms-touch-action":"none"}),b.bind(b.win,"MSPointerDown",b.ontouchstart),b.bind(document,"MSPointerUp",b.ontouchend),b.bind(document,"MSPointerMove",
    52 b.ontouchmove),b.bind(b.cursor,"MSGestureHold",function(b){b.preventDefault()}),b.bind(b.cursor,"contextmenu",function(b){b.preventDefault()}));this.istouchcapable&&(b.bind(b.win,"touchstart",b.ontouchstart),b.bind(document,"touchend",b.ontouchend),b.bind(document,"touchcancel",b.ontouchend),b.bind(document,"touchmove",b.ontouchmove));b.bind(b.cursor,"mousedown",b.onmousedown);b.bind(b.cursor,"mouseup",b.onmouseup);b.railh&&(b.bind(b.cursorh,"mousedown",function(d){b.onmousedown(d,!0)}),b.bind(b.cursorh,
    53 "mouseup",function(d){if(!(b.rail.drag&&2==b.rail.drag.pt))return b.rail.drag=!1,b.hasmoving=!1,b.hideCursor(),f.hasmousecapture&&document.releaseCapture(),b.cancelEvent(d)}));if(b.opt.cursordragontouch||!f.cantouch&&!b.opt.touchbehavior)b.rail.css({cursor:"default"}),b.railh&&b.railh.css({cursor:"default"}),b.jqbind(b.rail,"mouseenter",function(){b.canshowonmouseevent&&b.showCursor();b.rail.active=!0}),b.jqbind(b.rail,"mouseleave",function(){b.rail.active=!1;b.rail.drag||b.hideCursor()}),b.opt.sensitiverail&&
    54 (b.bind(b.rail,"click",function(d){b.doRailClick(d,!1,!1)}),b.bind(b.rail,"dblclick",function(d){b.doRailClick(d,!0,!1)}),b.bind(b.cursor,"click",function(d){b.cancelEvent(d)}),b.bind(b.cursor,"dblclick",function(d){b.cancelEvent(d)})),b.railh&&(b.jqbind(b.railh,"mouseenter",function(){b.canshowonmouseevent&&b.showCursor();b.rail.active=!0}),b.jqbind(b.railh,"mouseleave",function(){b.rail.active=!1;b.rail.drag||b.hideCursor()}),b.opt.sensitiverail&&(b.bind(b.railh,"click",function(d){b.doRailClick(d,
    55 !1,!0)}),b.bind(b.railh,"dblclick",function(d){b.doRailClick(d,!0,!0)}),b.bind(b.cursorh,"click",function(d){b.cancelEvent(d)}),b.bind(b.cursorh,"dblclick",function(d){b.cancelEvent(d)})));!f.cantouch&&!b.opt.touchbehavior?(b.bind(f.hasmousecapture?b.win:document,"mouseup",b.onmouseup),b.bind(document,"mousemove",b.onmousemove),b.onclick&&b.bind(document,"click",b.onclick),!b.ispage&&b.opt.enablescrollonselection&&(b.bind(b.win[0],"mousedown",b.onselectionstart),b.bind(document,"mouseup",b.onselectionend),
    56 b.bind(b.cursor,"mouseup",b.onselectionend),b.cursorh&&b.bind(b.cursorh,"mouseup",b.onselectionend),b.bind(document,"mousemove",b.onselectiondrag)),b.zoom&&(b.jqbind(b.zoom,"mouseenter",function(){b.canshowonmouseevent&&b.showCursor();b.rail.active=!0}),b.jqbind(b.zoom,"mouseleave",function(){b.rail.active=!1;b.rail.drag||b.hideCursor()}))):(b.bind(f.hasmousecapture?b.win:document,"mouseup",b.ontouchend),b.bind(document,"mousemove",b.ontouchmove),b.onclick&&b.bind(document,"click",b.onclick),b.opt.cursordragontouch&&
    57 (b.bind(b.cursor,"mousedown",b.onmousedown),b.bind(b.cursor,"mousemove",b.onmousemove),b.cursorh&&b.bind(b.cursorh,"mousedown",b.onmousedown),b.cursorh&&b.bind(b.cursorh,"mousemove",b.onmousemove)));b.opt.enablemousewheel&&(b.isiframe||b.bind(f.isie&&b.ispage?document:b.docscroll,"mousewheel",b.onmousewheel),b.bind(b.rail,"mousewheel",b.onmousewheel),b.railh&&b.bind(b.railh,"mousewheel",b.onmousewheelhr));!b.ispage&&(!f.cantouch&&!/HTML|BODY/.test(b.win[0].nodeName))&&(b.win.attr("tabindex")||b.win.attr({tabindex:J++}),
    58 b.jqbind(b.win,"focus",function(d){y=b.getTarget(d).id||!0;b.hasfocus=!0;b.canshowonmouseevent&&b.noticeCursor()}),b.jqbind(b.win,"blur",function(d){y=!1;b.hasfocus=!1}),b.jqbind(b.win,"mouseenter",function(d){D=b.getTarget(d).id||!0;b.hasmousefocus=!0;b.canshowonmouseevent&&b.noticeCursor()}),b.jqbind(b.win,"mouseleave",function(){D=!1;b.hasmousefocus=!1}))}b.onkeypress=function(d){if(b.locked&&0==b.page.maxh)return!0;d=d?d:window.e;var c=b.getTarget(d);if(c&&/INPUT|TEXTAREA|SELECT|OPTION/.test(c.nodeName)&&
    59 (!c.getAttribute("type")&&!c.type||!/submit|button|cancel/i.tp))return!0;if(b.hasfocus||b.hasmousefocus&&!y||b.ispage&&!y&&!D){c=d.keyCode;if(b.locked&&27!=c)return b.cancelEvent(d);var g=d.ctrlKey||!1,p=d.shiftKey||!1,f=!1;switch(c){case 38:case 63233:b.doScrollBy(72);f=!0;break;case 40:case 63235:b.doScrollBy(-72);f=!0;break;case 37:case 63232:b.railh&&(g?b.doScrollLeft(0):b.doScrollLeftBy(72),f=!0);break;case 39:case 63234:b.railh&&(g?b.doScrollLeft(b.page.maxw):b.doScrollLeftBy(-72),f=!0);break;
    60 case 33:case 63276:b.doScrollBy(b.view.h);f=!0;break;case 34:case 63277:b.doScrollBy(-b.view.h);f=!0;break;case 36:case 63273:b.railh&&g?b.doScrollPos(0,0):b.doScrollTo(0);f=!0;break;case 35:case 63275:b.railh&&g?b.doScrollPos(b.page.maxw,b.page.maxh):b.doScrollTo(b.page.maxh);f=!0;break;case 32:b.opt.spacebarenabled&&(p?b.doScrollBy(b.view.h):b.doScrollBy(-b.view.h),f=!0);break;case 27:b.zoomactive&&(b.doZoom(),f=!0)}if(f)return b.cancelEvent(d)}};b.opt.enablekeyboard&&b.bind(document,f.isopera&&
    61 !f.isopera12?"keypress":"keydown",b.onkeypress);b.bind(window,"resize",b.lazyResize);b.bind(window,"orientationchange",b.lazyResize);b.bind(window,"load",b.lazyResize);if(f.ischrome&&!b.ispage&&!b.haswrapper){var t=b.win.attr("style"),g=parseFloat(b.win.css("width"))+1;b.win.css("width",g);b.synched("chromefix",function(){b.win.attr("style",t)})}b.onAttributeChange=function(d){b.lazyResize(250)};!b.ispage&&!b.haswrapper&&(!1!==z?(b.observer=new z(function(d){d.forEach(b.onAttributeChange)}),b.observer.observe(b.win[0],
    62 {childList:!0,characterData:!1,attributes:!0,subtree:!1}),b.observerremover=new z(function(d){d.forEach(function(d){if(0<d.removedNodes.length)for(var c in d.removedNodes)if(d.removedNodes[c]==b.win[0])return b.remove()})}),b.observerremover.observe(b.win[0].parentNode,{childList:!0,characterData:!1,attributes:!1,subtree:!1})):(b.bind(b.win,f.isie&&!f.isie9?"propertychange":"DOMAttrModified",b.onAttributeChange),f.isie9&&b.win[0].attachEvent("onpropertychange",b.onAttributeChange),b.bind(b.win,"DOMNodeRemoved",
    63 function(d){d.target==b.win[0]&&b.remove()})));!b.ispage&&b.opt.boxzoom&&b.bind(window,"resize",b.resizeZoom);b.istextarea&&b.bind(b.win,"mouseup",b.lazyResize);b.checkrtlmode=!0;b.lazyResize(30)}if("IFRAME"==this.doc[0].nodeName){var I=function(d){b.iframexd=!1;try{var c="contentDocument"in this?this.contentDocument:this.contentWindow.document}catch(g){b.iframexd=!0,c=!1}if(b.iframexd)return"console"in window&&console.log("NiceScroll error: policy restriced iframe"),!0;b.forcescreen=!0;b.isiframe&&
    64 (b.iframe={doc:e(c),html:b.doc.contents().find("html")[0],body:b.doc.contents().find("body")[0]},b.getContentSize=function(){return{w:Math.max(b.iframe.html.scrollWidth,b.iframe.body.scrollWidth),h:Math.max(b.iframe.html.scrollHeight,b.iframe.body.scrollHeight)}},b.docscroll=e(b.iframe.body));!f.isios&&(b.opt.iframeautoresize&&!b.isiframe)&&(b.win.scrollTop(0),b.doc.height(""),d=Math.max(c.getElementsByTagName("html")[0].scrollHeight,c.body.scrollHeight),b.doc.height(d));b.lazyResize(30);f.isie7&&
    65 b.css(e(b.iframe.html),{"overflow-y":"hidden"});b.css(e(b.iframe.body),{"overflow-y":"hidden"});"contentWindow"in this?b.bind(this.contentWindow,"scroll",b.onscroll):b.bind(c,"scroll",b.onscroll);b.opt.enablemousewheel&&b.bind(c,"mousewheel",b.onmousewheel);b.opt.enablekeyboard&&b.bind(c,f.isopera?"keypress":"keydown",b.onkeypress);if(f.cantouch||b.opt.touchbehavior)b.bind(c,"mousedown",b.onmousedown),b.bind(c,"mousemove",function(d){b.onmousemove(d,!0)}),b.opt.grabcursorenabled&&f.cursorgrabvalue&&
    66 b.css(e(c.body),{cursor:f.cursorgrabvalue});b.bind(c,"mouseup",b.onmouseup);b.zoom&&(b.opt.dblclickzoom&&b.bind(c,"dblclick",b.doZoom),b.ongesturezoom&&b.bind(c,"gestureend",b.ongesturezoom))};this.doc[0].readyState&&"complete"==this.doc[0].readyState&&setTimeout(function(){I.call(b.doc[0],!1)},500);b.bind(this.doc,"load",I)}};this.showCursor=function(d,c){b.cursortimeout&&(clearTimeout(b.cursortimeout),b.cursortimeout=0);if(b.rail){b.autohidedom&&(b.autohidedom.stop().css({opacity:b.opt.cursoropacitymax}),
    67 b.cursoractive=!0);if(!b.rail.drag||1!=b.rail.drag.pt)"undefined"!=typeof d&&!1!==d&&(b.scroll.y=Math.round(1*d/b.scrollratio.y)),"undefined"!=typeof c&&(b.scroll.x=Math.round(1*c/b.scrollratio.x));b.cursor.css({height:b.cursorheight,top:b.scroll.y});b.cursorh&&(!b.rail.align&&b.rail.visibility?b.cursorh.css({width:b.cursorwidth,left:b.scroll.x+b.rail.width}):b.cursorh.css({width:b.cursorwidth,left:b.scroll.x}),b.cursoractive=!0);b.zoom&&b.zoom.stop().css({opacity:b.opt.cursoropacitymax})}};this.hideCursor=
    68 function(d){!b.cursortimeout&&(b.rail&&b.autohidedom)&&(b.cursortimeout=setTimeout(function(){if(!b.rail.active||!b.showonmouseevent)b.autohidedom.stop().animate({opacity:b.opt.cursoropacitymin}),b.zoom&&b.zoom.stop().animate({opacity:b.opt.cursoropacitymin}),b.cursoractive=!1;b.cursortimeout=0},d||b.opt.hidecursordelay))};this.noticeCursor=function(d,c,g){b.showCursor(c,g);b.rail.active||b.hideCursor(d)};this.getContentSize=b.ispage?function(){return{w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
    69 h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)}}:b.haswrapper?function(){return{w:b.doc.outerWidth()+parseInt(b.win.css("paddingLeft"))+parseInt(b.win.css("paddingRight")),h:b.doc.outerHeight()+parseInt(b.win.css("paddingTop"))+parseInt(b.win.css("paddingBottom"))}}:function(){return{w:b.docscroll[0].scrollWidth,h:b.docscroll[0].scrollHeight}};this.onResize=function(d,c){if(!b.win)return!1;if(!b.haswrapper&&!b.ispage){if("none"==b.win.css("display"))return b.visibility&&
    70 b.hideRail().hideRailHr(),!1;!b.hidden&&!b.visibility&&b.showRail().showRailHr()}var g=b.page.maxh,f=b.page.maxw,e=b.view.w;b.view={w:b.ispage?b.win.width():parseInt(b.win[0].clientWidth),h:b.ispage?b.win.height():parseInt(b.win[0].clientHeight)};b.page=c?c:b.getContentSize();b.page.maxh=Math.max(0,b.page.h-b.view.h);b.page.maxw=Math.max(0,b.page.w-b.view.w);if(b.page.maxh==g&&b.page.maxw==f&&b.view.w==e){if(b.ispage)return b;g=b.win.offset();if(b.lastposition&&(f=b.lastposition,f.top==g.top&&f.left==
    71 g.left))return b;b.lastposition=g}0==b.page.maxh?(b.hideRail(),b.scrollvaluemax=0,b.scroll.y=0,b.scrollratio.y=0,b.cursorheight=0,b.setScrollTop(0),b.rail.scrollable=!1):b.rail.scrollable=!0;0==b.page.maxw?(b.hideRailHr(),b.scrollvaluemaxw=0,b.scroll.x=0,b.scrollratio.x=0,b.cursorwidth=0,b.setScrollLeft(0),b.railh.scrollable=!1):b.railh.scrollable=!0;b.locked=0==b.page.maxh&&0==b.page.maxw;if(b.locked)return b.ispage||b.updateScrollBar(b.view),!1;!b.hidden&&!b.visibility?b.showRail().showRailHr():
    72 !b.hidden&&!b.railh.visibility&&b.showRailHr();b.istextarea&&(b.win.css("resize")&&"none"!=b.win.css("resize"))&&(b.view.h-=20);b.cursorheight=Math.min(b.view.h,Math.round(b.view.h*(b.view.h/b.page.h)));b.cursorheight=b.opt.cursorfixedheight?b.opt.cursorfixedheight:Math.max(b.opt.cursorminheight,b.cursorheight);b.cursorwidth=Math.min(b.view.w,Math.round(b.view.w*(b.view.w/b.page.w)));b.cursorwidth=b.opt.cursorfixedheight?b.opt.cursorfixedheight:Math.max(b.opt.cursorminheight,b.cursorwidth);b.scrollvaluemax=
    73 b.view.h-b.cursorheight-b.cursor.hborder;b.railh&&(b.railh.width=0<b.page.maxh?b.view.w-b.rail.width:b.view.w,b.scrollvaluemaxw=b.railh.width-b.cursorwidth-b.cursorh.wborder);b.checkrtlmode&&b.railh&&(b.checkrtlmode=!1,b.opt.rtlmode&&0==b.scroll.x&&b.setScrollLeft(b.page.maxw));b.ispage||b.updateScrollBar(b.view);b.scrollratio={x:b.page.maxw/b.scrollvaluemaxw,y:b.page.maxh/b.scrollvaluemax};b.getScrollTop()>b.page.maxh?b.doScrollTop(b.page.maxh):(b.scroll.y=Math.round(b.getScrollTop()*(1/b.scrollratio.y)),
    74 b.scroll.x=Math.round(b.getScrollLeft()*(1/b.scrollratio.x)),b.cursoractive&&b.noticeCursor());b.scroll.y&&0==b.getScrollTop()&&b.doScrollTo(Math.floor(b.scroll.y*b.scrollratio.y));return b};this.resize=b.onResize;this.lazyResize=function(d){d=isNaN(d)?30:d;b.delayed("resize",b.resize,d);return b};this._bind=function(d,c,g,f){b.events.push({e:d,n:c,f:g,b:f,q:!1});d.addEventListener?d.addEventListener(c,g,f||!1):d.attachEvent?d.attachEvent("on"+c,g):d["on"+c]=g};this.jqbind=function(d,c,g){b.events.push({e:d,
    75 n:c,f:g,q:!0});e(d).bind(c,g)};this.bind=function(d,c,g,e){var h="jquery"in d?d[0]:d;"mousewheel"==c?"onwheel"in b.win?b._bind(h,"wheel",g,e||!1):(d="undefined"!=typeof document.onmousewheel?"mousewheel":"DOMMouseScroll",n(h,d,g,e||!1),"DOMMouseScroll"==d&&n(h,"MozMousePixelScroll",g,e||!1)):h.addEventListener?(f.cantouch&&/mouseup|mousedown|mousemove/.test(c)&&b._bind(h,"mousedown"==c?"touchstart":"mouseup"==c?"touchend":"touchmove",function(b){if(b.touches){if(2>b.touches.length){var d=b.touches.length?
    76 b.touches[0]:b;d.original=b;g.call(this,d)}}else b.changedTouches&&(d=b.changedTouches[0],d.original=b,g.call(this,d))},e||!1),b._bind(h,c,g,e||!1),f.cantouch&&"mouseup"==c&&b._bind(h,"touchcancel",g,e||!1)):b._bind(h,c,function(d){if((d=d||window.event||!1)&&d.srcElement)d.target=d.srcElement;"pageY"in d||(d.pageX=d.clientX+document.documentElement.scrollLeft,d.pageY=d.clientY+document.documentElement.scrollTop);return!1===g.call(h,d)||!1===e?b.cancelEvent(d):!0})};this._unbind=function(b,c,g,f){b.removeEventListener?
    77 b.removeEventListener(c,g,f):b.detachEvent?b.detachEvent("on"+c,g):b["on"+c]=!1};this.unbindAll=function(){for(var d=0;d<b.events.length;d++){var c=b.events[d];c.q?c.e.unbind(c.n,c.f):b._unbind(c.e,c.n,c.f,c.b)}};this.cancelEvent=function(b){b=b.original?b.original:b?b:window.event||!1;if(!b)return!1;b.preventDefault&&b.preventDefault();b.stopPropagation&&b.stopPropagation();b.preventManipulation&&b.preventManipulation();b.cancelBubble=!0;b.cancel=!0;return b.returnValue=!1};this.stopPropagation=
    78 function(b){b=b.original?b.original:b?b:window.event||!1;if(!b)return!1;if(b.stopPropagation)return b.stopPropagation();b.cancelBubble&&(b.cancelBubble=!0);return!1};this.showRail=function(){if(0!=b.page.maxh&&(b.ispage||"none"!=b.win.css("display")))b.visibility=!0,b.rail.visibility=!0,b.rail.css("display","block");return b};this.showRailHr=function(){if(!b.railh)return b;if(0!=b.page.maxw&&(b.ispage||"none"!=b.win.css("display")))b.railh.visibility=!0,b.railh.css("display","block");return b};this.hideRail=
    79 function(){b.visibility=!1;b.rail.visibility=!1;b.rail.css("display","none");return b};this.hideRailHr=function(){if(!b.railh)return b;b.railh.visibility=!1;b.railh.css("display","none");return b};this.show=function(){b.hidden=!1;b.locked=!1;return b.showRail().showRailHr()};this.hide=function(){b.hidden=!0;b.locked=!0;return b.hideRail().hideRailHr()};this.toggle=function(){return b.hidden?b.show():b.hide()};this.remove=function(){b.stop();b.cursortimeout&&clearTimeout(b.cursortimeout);b.doZoomOut();
    80 b.unbindAll();!1!==b.observer&&b.observer.disconnect();!1!==b.observerremover&&b.observerremover.disconnect();b.events=[];b.cursor&&(b.cursor.remove(),b.cursor=null);b.cursorh&&(b.cursorh.remove(),b.cursorh=null);b.rail&&(b.rail.remove(),b.rail=null);b.railh&&(b.railh.remove(),b.railh=null);b.zoom&&(b.zoom.remove(),b.zoom=null);for(var d=0;d<b.saved.css.length;d++){var c=b.saved.css[d];c[0].css(c[1],"undefined"==typeof c[2]?"":c[2])}b.saved=!1;b.me.data("__nicescroll","");b.me=null;b.doc=null;b.docscroll=
    81 null;b.win=null;return b};this.scrollstart=function(d){this.onscrollstart=d;return b};this.scrollend=function(d){this.onscrollend=d;return b};this.scrollcancel=function(d){this.onscrollcancel=d;return b};this.zoomin=function(d){this.onzoomin=d;return b};this.zoomout=function(d){this.onzoomout=d;return b};this.isScrollable=function(b){b=b.target?b.target:b;if("OPTION"==b.nodeName)return!0;for(;b&&1==b.nodeType&&!/BODY|HTML/.test(b.nodeName);){var c=e(b),c=c.css("overflowY")||c.css("overflowX")||c.css("overflow")||
    82 "";if(/scroll|auto/.test(c))return b.clientHeight!=b.scrollHeight;b=b.parentNode?b.parentNode:!1}return!1};this.getViewport=function(b){for(b=b&&b.parentNode?b.parentNode:!1;b&&1==b.nodeType&&!/BODY|HTML/.test(b.nodeName);){var c=e(b),g=c.css("overflowY")||c.css("overflowX")||c.css("overflow")||"";if(/scroll|auto/.test(g)&&b.clientHeight!=b.scrollHeight||0<c.getNiceScroll().length)return c;b=b.parentNode?b.parentNode:!1}return!1};this.onmousewheel=function(d){if(b.locked)return!0;if(b.rail.drag)return b.cancelEvent(d);
    83 if(!b.rail.scrollable)return b.railh&&b.railh.scrollable?b.onmousewheelhr(d):!0;var c=+new Date,g=!1;b.opt.preservenativescrolling&&b.checkarea+600<c&&(b.nativescrollingarea=b.isScrollable(d),g=!0);b.checkarea=c;if(b.nativescrollingarea)return!0;if(d=t(d,!1,g))b.checkarea=0;return d};this.onmousewheelhr=function(d){if(b.locked||!b.railh.scrollable)return!0;if(b.rail.drag)return b.cancelEvent(d);var c=+new Date,g=!1;b.opt.preservenativescrolling&&b.checkarea+600<c&&(b.nativescrollingarea=b.isScrollable(d),
    84 g=!0);b.checkarea=c;return b.nativescrollingarea?!0:b.locked?b.cancelEvent(d):t(d,!0,g)};this.stop=function(){b.cancelScroll();b.scrollmon&&b.scrollmon.stop();b.cursorfreezed=!1;b.scroll.y=Math.round(b.getScrollTop()*(1/b.scrollratio.y));b.noticeCursor();return b};this.getTransitionSpeed=function(c){var f=Math.round(10*b.opt.scrollspeed);c=Math.min(f,Math.round(c/20*b.opt.scrollspeed));return 20<c?c:0};b.opt.smoothscroll?b.ishwscroll&&f.hastransition&&b.opt.usetransition?(this.prepareTransition=function(c,
    85 e){var g=e?20<c?c:0:b.getTransitionSpeed(c),h=g?f.prefixstyle+"transform "+g+"ms ease-out":"";if(!b.lasttransitionstyle||b.lasttransitionstyle!=h)b.lasttransitionstyle=h,b.doc.css(f.transitionstyle,h);return g},this.doScrollLeft=function(c,f){var g=b.scrollrunning?b.newscrolly:b.getScrollTop();b.doScrollPos(c,g,f)},this.doScrollTop=function(c,f){var g=b.scrollrunning?b.newscrollx:b.getScrollLeft();b.doScrollPos(g,c,f)},this.doScrollPos=function(c,e,g){var h=b.getScrollTop(),l=b.getScrollLeft();(0>
    86 (b.newscrolly-h)*(e-h)||0>(b.newscrollx-l)*(c-l))&&b.cancelScroll();!1==b.opt.bouncescroll&&(0>e?e=0:e>b.page.maxh&&(e=b.page.maxh),0>c?c=0:c>b.page.maxw&&(c=b.page.maxw));if(b.scrollrunning&&c==b.newscrollx&&e==b.newscrolly)return!1;b.newscrolly=e;b.newscrollx=c;b.newscrollspeed=g||!1;if(b.timer)return!1;b.timer=setTimeout(function(){var g=b.getScrollTop(),h=b.getScrollLeft(),l,k;l=c-h;k=e-g;l=Math.round(Math.sqrt(Math.pow(l,2)+Math.pow(k,2)));l=b.newscrollspeed&&1<b.newscrollspeed?b.newscrollspeed:
    87 b.getTransitionSpeed(l);b.newscrollspeed&&1>=b.newscrollspeed&&(l*=b.newscrollspeed);b.prepareTransition(l,!0);b.timerscroll&&b.timerscroll.tm&&clearInterval(b.timerscroll.tm);0<l&&(!b.scrollrunning&&b.onscrollstart&&b.onscrollstart.call(b,{type:"scrollstart",current:{x:h,y:g},request:{x:c,y:e},end:{x:b.newscrollx,y:b.newscrolly},speed:l}),f.transitionend?b.scrollendtrapped||(b.scrollendtrapped=!0,b.bind(b.doc,f.transitionend,b.onScrollEnd,!1)):(b.scrollendtrapped&&clearTimeout(b.scrollendtrapped),
    88 b.scrollendtrapped=setTimeout(b.onScrollEnd,l)),b.timerscroll={bz:new BezierClass(g,b.newscrolly,l,0,0,0.58,1),bh:new BezierClass(h,b.newscrollx,l,0,0,0.58,1)},b.cursorfreezed||(b.timerscroll.tm=setInterval(function(){b.showCursor(b.getScrollTop(),b.getScrollLeft())},60)));b.synched("doScroll-set",function(){b.timer=0;b.scrollendtrapped&&(b.scrollrunning=!0);b.setScrollTop(b.newscrolly);b.setScrollLeft(b.newscrollx);if(!b.scrollendtrapped)b.onScrollEnd()})},50)},this.cancelScroll=function(){if(!b.scrollendtrapped)return!0;
    89 var c=b.getScrollTop(),e=b.getScrollLeft();b.scrollrunning=!1;f.transitionend||clearTimeout(f.transitionend);b.scrollendtrapped=!1;b._unbind(b.doc,f.transitionend,b.onScrollEnd);b.prepareTransition(0);b.setScrollTop(c);b.railh&&b.setScrollLeft(e);b.timerscroll&&b.timerscroll.tm&&clearInterval(b.timerscroll.tm);b.timerscroll=!1;b.cursorfreezed=!1;b.showCursor(c,e);return b},this.onScrollEnd=function(){b.scrollendtrapped&&b._unbind(b.doc,f.transitionend,b.onScrollEnd);b.scrollendtrapped=!1;b.prepareTransition(0);
    90 b.timerscroll&&b.timerscroll.tm&&clearInterval(b.timerscroll.tm);b.timerscroll=!1;var c=b.getScrollTop(),e=b.getScrollLeft();b.setScrollTop(c);b.railh&&b.setScrollLeft(e);b.noticeCursor(!1,c,e);b.cursorfreezed=!1;0>c?c=0:c>b.page.maxh&&(c=b.page.maxh);0>e?e=0:e>b.page.maxw&&(e=b.page.maxw);if(c!=b.newscrolly||e!=b.newscrollx)return b.doScrollPos(e,c,b.opt.snapbackspeed);b.onscrollend&&b.scrollrunning&&b.onscrollend.call(b,{type:"scrollend",current:{x:e,y:c},end:{x:b.newscrollx,y:b.newscrolly}});b.scrollrunning=
    91 !1}):(this.doScrollLeft=function(c,f){var g=b.scrollrunning?b.newscrolly:b.getScrollTop();b.doScrollPos(c,g,f)},this.doScrollTop=function(c,f){var g=b.scrollrunning?b.newscrollx:b.getScrollLeft();b.doScrollPos(g,c,f)},this.doScrollPos=function(c,f,g){function e(){if(b.cancelAnimationFrame)return!0;b.scrollrunning=!0;if(r=1-r)return b.timer=v(e)||1;var c=0,d=sy=b.getScrollTop();if(b.dst.ay){var d=b.bzscroll?b.dst.py+b.bzscroll.getNow()*b.dst.ay:b.newscrolly,g=d-sy;if(0>g&&d<b.newscrolly||0<g&&d>b.newscrolly)d=
    92 b.newscrolly;b.setScrollTop(d);d==b.newscrolly&&(c=1)}else c=1;var f=sx=b.getScrollLeft();if(b.dst.ax){f=b.bzscroll?b.dst.px+b.bzscroll.getNow()*b.dst.ax:b.newscrollx;g=f-sx;if(0>g&&f<b.newscrollx||0<g&&f>b.newscrollx)f=b.newscrollx;b.setScrollLeft(f);f==b.newscrollx&&(c+=1)}else c+=1;2==c?(b.timer=0,b.cursorfreezed=!1,b.bzscroll=!1,b.scrollrunning=!1,0>d?d=0:d>b.page.maxh&&(d=b.page.maxh),0>f?f=0:f>b.page.maxw&&(f=b.page.maxw),f!=b.newscrollx||d!=b.newscrolly?b.doScrollPos(f,d):b.onscrollend&&b.onscrollend.call(b,
    93 {type:"scrollend",current:{x:sx,y:sy},end:{x:b.newscrollx,y:b.newscrolly}})):b.timer=v(e)||1}f="undefined"==typeof f||!1===f?b.getScrollTop(!0):f;if(b.timer&&b.newscrolly==f&&b.newscrollx==c)return!0;b.timer&&w(b.timer);b.timer=0;var h=b.getScrollTop(),l=b.getScrollLeft();(0>(b.newscrolly-h)*(f-h)||0>(b.newscrollx-l)*(c-l))&&b.cancelScroll();b.newscrolly=f;b.newscrollx=c;if(!b.bouncescroll||!b.rail.visibility)0>b.newscrolly?b.newscrolly=0:b.newscrolly>b.page.maxh&&(b.newscrolly=b.page.maxh);if(!b.bouncescroll||
    94 !b.railh.visibility)0>b.newscrollx?b.newscrollx=0:b.newscrollx>b.page.maxw&&(b.newscrollx=b.page.maxw);b.dst={};b.dst.x=c-l;b.dst.y=f-h;b.dst.px=l;b.dst.py=h;var k=Math.round(Math.sqrt(Math.pow(b.dst.x,2)+Math.pow(b.dst.y,2)));b.dst.ax=b.dst.x/k;b.dst.ay=b.dst.y/k;var n=0,q=k;0==b.dst.x?(n=h,q=f,b.dst.ay=1,b.dst.py=0):0==b.dst.y&&(n=l,q=c,b.dst.ax=1,b.dst.px=0);k=b.getTransitionSpeed(k);g&&1>=g&&(k*=g);b.bzscroll=0<k?b.bzscroll?b.bzscroll.update(q,k):new BezierClass(n,q,k,0,1,0,1):!1;if(!b.timer){(h==
    95 b.page.maxh&&f>=b.page.maxh||l==b.page.maxw&&c>=b.page.maxw)&&b.checkContentSize();var r=1;b.cancelAnimationFrame=!1;b.timer=1;b.onscrollstart&&!b.scrollrunning&&b.onscrollstart.call(b,{type:"scrollstart",current:{x:l,y:h},request:{x:c,y:f},end:{x:b.newscrollx,y:b.newscrolly},speed:k});e();(h==b.page.maxh&&f>=h||l==b.page.maxw&&c>=l)&&b.checkContentSize();b.noticeCursor()}},this.cancelScroll=function(){b.timer&&w(b.timer);b.timer=0;b.bzscroll=!1;b.scrollrunning=!1;return b}):(this.doScrollLeft=function(c,
    96 f){var g=b.getScrollTop();b.doScrollPos(c,g,f)},this.doScrollTop=function(c,f){var g=b.getScrollLeft();b.doScrollPos(g,c,f)},this.doScrollPos=function(c,f,g){var e=c>b.page.maxw?b.page.maxw:c;0>e&&(e=0);var h=f>b.page.maxh?b.page.maxh:f;0>h&&(h=0);b.synched("scroll",function(){b.setScrollTop(h);b.setScrollLeft(e)})},this.cancelScroll=function(){});this.doScrollBy=function(c,f){var g=0,g=f?Math.floor((b.scroll.y-c)*b.scrollratio.y):(b.timer?b.newscrolly:b.getScrollTop(!0))-c;if(b.bouncescroll){var e=
    97 Math.round(b.view.h/2);g<-e?g=-e:g>b.page.maxh+e&&(g=b.page.maxh+e)}b.cursorfreezed=!1;py=b.getScrollTop(!0);if(0>g&&0>=py)return b.noticeCursor();if(g>b.page.maxh&&py>=b.page.maxh)return b.checkContentSize(),b.noticeCursor();b.doScrollTop(g)};this.doScrollLeftBy=function(c,f){var g=0,g=f?Math.floor((b.scroll.x-c)*b.scrollratio.x):(b.timer?b.newscrollx:b.getScrollLeft(!0))-c;if(b.bouncescroll){var e=Math.round(b.view.w/2);g<-e?g=-e:g>b.page.maxw+e&&(g=b.page.maxw+e)}b.cursorfreezed=!1;px=b.getScrollLeft(!0);
    98 if(0>g&&0>=px||g>b.page.maxw&&px>=b.page.maxw)return b.noticeCursor();b.doScrollLeft(g)};this.doScrollTo=function(c,f){f&&Math.round(c*b.scrollratio.y);b.cursorfreezed=!1;b.doScrollTop(c)};this.checkContentSize=function(){var c=b.getContentSize();(c.h!=b.page.h||c.w!=b.page.w)&&b.resize(!1,c)};b.onscroll=function(c){b.rail.drag||b.cursorfreezed||b.synched("scroll",function(){b.scroll.y=Math.round(b.getScrollTop()*(1/b.scrollratio.y));b.railh&&(b.scroll.x=Math.round(b.getScrollLeft()*(1/b.scrollratio.x)));
    99 b.noticeCursor()})};b.bind(b.docscroll,"scroll",b.onscroll);this.doZoomIn=function(c){if(!b.zoomactive){b.zoomactive=!0;b.zoomrestore={style:{}};var h="position top left zIndex backgroundColor marginTop marginBottom marginLeft marginRight".split(" "),g=b.win[0].style,l;for(l in h){var k=h[l];b.zoomrestore.style[k]="undefined"!=typeof g[k]?g[k]:""}b.zoomrestore.style.width=b.win.css("width");b.zoomrestore.style.height=b.win.css("height");b.zoomrestore.padding={w:b.win.outerWidth()-b.win.width(),h:b.win.outerHeight()-
    100 b.win.height()};f.isios4&&(b.zoomrestore.scrollTop=e(window).scrollTop(),e(window).scrollTop(0));b.win.css({position:f.isios4?"absolute":"fixed",top:0,left:0,"z-index":x+100,margin:"0px"});h=b.win.css("backgroundColor");(""==h||/transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(h))&&b.win.css("backgroundColor","#fff");b.rail.css({"z-index":x+101});b.zoom.css({"z-index":x+102});b.zoom.css("backgroundPosition","0px -18px");b.resizeZoom();b.onzoomin&&b.onzoomin.call(b);return b.cancelEvent(c)}};this.doZoomOut=
    101 function(c){if(b.zoomactive)return b.zoomactive=!1,b.win.css("margin",""),b.win.css(b.zoomrestore.style),f.isios4&&e(window).scrollTop(b.zoomrestore.scrollTop),b.rail.css({"z-index":b.zindex}),b.zoom.css({"z-index":b.zindex}),b.zoomrestore=!1,b.zoom.css("backgroundPosition","0px 0px"),b.onResize(),b.onzoomout&&b.onzoomout.call(b),b.cancelEvent(c)};this.doZoom=function(c){return b.zoomactive?b.doZoomOut(c):b.doZoomIn(c)};this.resizeZoom=function(){if(b.zoomactive){var c=b.getScrollTop();b.win.css({width:e(window).width()-
    102 b.zoomrestore.padding.w+"px",height:e(window).height()-b.zoomrestore.padding.h+"px"});b.onResize();b.setScrollTop(Math.min(b.page.maxh,c))}};this.init();e.nicescroll.push(this)},H=function(e){var c=this;this.nc=e;this.steptime=this.lasttime=this.speedy=this.speedx=this.lasty=this.lastx=0;this.snapy=this.snapx=!1;this.demuly=this.demulx=0;this.lastscrolly=this.lastscrollx=-1;this.timer=this.chky=this.chkx=0;this.time=function(){return+new Date};this.reset=function(e,l){c.stop();var k=c.time();c.steptime=
    103 0;c.lasttime=k;c.speedx=0;c.speedy=0;c.lastx=e;c.lasty=l;c.lastscrollx=-1;c.lastscrolly=-1};this.update=function(e,l){var k=c.time();c.steptime=k-c.lasttime;c.lasttime=k;var k=l-c.lasty,t=e-c.lastx,b=c.nc.getScrollTop(),q=c.nc.getScrollLeft(),b=b+k,q=q+t;c.snapx=0>q||q>c.nc.page.maxw;c.snapy=0>b||b>c.nc.page.maxh;c.speedx=t;c.speedy=k;c.lastx=e;c.lasty=l};this.stop=function(){c.nc.unsynched("domomentum2d");c.timer&&clearTimeout(c.timer);c.timer=0;c.lastscrollx=-1;c.lastscrolly=-1};this.doSnapy=function(e,
    104 l){var k=!1;0>l?(l=0,k=!0):l>c.nc.page.maxh&&(l=c.nc.page.maxh,k=!0);0>e?(e=0,k=!0):e>c.nc.page.maxw&&(e=c.nc.page.maxw,k=!0);k&&c.nc.doScrollPos(e,l,c.nc.opt.snapbackspeed)};this.doMomentum=function(e){var l=c.time(),k=e?l+e:c.lasttime;e=c.nc.getScrollLeft();var t=c.nc.getScrollTop(),b=c.nc.page.maxh,q=c.nc.page.maxw;c.speedx=0<q?Math.min(60,c.speedx):0;c.speedy=0<b?Math.min(60,c.speedy):0;k=k&&50>=l-k;if(0>t||t>b||0>e||e>q)k=!1;e=c.speedx&&k?c.speedx:!1;if(c.speedy&&k&&c.speedy||e){var f=Math.max(16,
    105 c.steptime);50<f&&(e=f/50,c.speedx*=e,c.speedy*=e,f=50);c.demulxy=0;c.lastscrollx=c.nc.getScrollLeft();c.chkx=c.lastscrollx;c.lastscrolly=c.nc.getScrollTop();c.chky=c.lastscrolly;var r=c.lastscrollx,u=c.lastscrolly,d=function(){var e=600<c.time()-l?0.04:0.02;if(c.speedx&&(r=Math.floor(c.lastscrollx-c.speedx*(1-c.demulxy)),c.lastscrollx=r,0>r||r>q))e=0.1;if(c.speedy&&(u=Math.floor(c.lastscrolly-c.speedy*(1-c.demulxy)),c.lastscrolly=u,0>u||u>b))e=0.1;c.demulxy=Math.min(1,c.demulxy+e);c.nc.synched("domomentum2d",
    106 function(){c.speedx&&(c.nc.getScrollLeft()!=c.chkx&&c.stop(),c.chkx=r,c.nc.setScrollLeft(r));c.speedy&&(c.nc.getScrollTop()!=c.chky&&c.stop(),c.chky=u,c.nc.setScrollTop(u));c.timer||(c.nc.hideCursor(),c.doSnapy(r,u))});1>c.demulxy?c.timer=setTimeout(d,f):(c.stop(),c.nc.hideCursor(),c.doSnapy(r,u))};d()}else c.doSnapy(c.nc.getScrollLeft(),c.nc.getScrollTop())}},A=e.fn.scrollTop;e.cssHooks.pageYOffset={get:function(k,c,h){return(c=e.data(k,"__nicescroll")||!1)&&c.ishwscroll?c.getScrollTop():A.call(k)},
    107 set:function(k,c){var h=e.data(k,"__nicescroll")||!1;h&&h.ishwscroll?h.setScrollTop(parseInt(c)):A.call(k,c);return this}};e.fn.scrollTop=function(k){if("undefined"==typeof k){var c=this[0]?e.data(this[0],"__nicescroll")||!1:!1;return c&&c.ishwscroll?c.getScrollTop():A.call(this)}return this.each(function(){var c=e.data(this,"__nicescroll")||!1;c&&c.ishwscroll?c.setScrollTop(parseInt(k)):A.call(e(this),k)})};var B=e.fn.scrollLeft;e.cssHooks.pageXOffset={get:function(k,c,h){return(c=e.data(k,"__nicescroll")||
    108 !1)&&c.ishwscroll?c.getScrollLeft():B.call(k)},set:function(k,c){var h=e.data(k,"__nicescroll")||!1;h&&h.ishwscroll?h.setScrollLeft(parseInt(c)):B.call(k,c);return this}};e.fn.scrollLeft=function(k){if("undefined"==typeof k){var c=this[0]?e.data(this[0],"__nicescroll")||!1:!1;return c&&c.ishwscroll?c.getScrollLeft():B.call(this)}return this.each(function(){var c=e.data(this,"__nicescroll")||!1;c&&c.ishwscroll?c.setScrollLeft(parseInt(k)):B.call(e(this),k)})};var C=function(k){var c=this;this.length=
    109 0;this.name="nicescrollarray";this.each=function(e){for(var h=0;h<c.length;h++)e.call(c[h]);return c};this.push=function(e){c[c.length]=e;c.length++};this.eq=function(e){return c[e]};if(k)for(a=0;a<k.length;a++){var h=e.data(k[a],"__nicescroll")||!1;h&&(this[this.length]=h,this.length++)}return this};(function(e,c,h){for(var l=0;l<c.length;l++)h(e,c[l])})(C.prototype,"show hide toggle onResize resize remove stop doScrollPos".split(" "),function(e,c){e[c]=function(){var e=arguments;return this.each(function(){this[c].apply(this,
    110 e)})}});e.fn.getNiceScroll=function(k){return"undefined"==typeof k?new C(this):e.data(this[k],"__nicescroll")||!1};e.extend(e.expr[":"],{nicescroll:function(k){return e.data(k,"__nicescroll")?!0:!1}});e.fn.niceScroll=function(k,c){"undefined"==typeof c&&("object"==typeof k&&!("jquery"in k))&&(c=k,k=!1);var h=new C;"undefined"==typeof c&&(c={});k&&(c.doc=e(k),c.win=e(this));var l=!("doc"in c);!l&&!("win"in c)&&(c.win=e(this));this.each(function(){var k=e(this).data("__nicescroll")||!1;k||(c.doc=l?
    111 e(this):c.doc,k=new N(c,e(this)),e(this).data("__nicescroll",k));h.push(k)});return 1==h.length?h[0]:h};window.NiceScroll={getjQuery:function(){return e}};e.nicescroll||(e.nicescroll=new C,e.nicescroll.options=F)})(jQuery);
     1/* jquery.nicescroll v3.7.6 InuYaksa - MIT - https://nicescroll.areaaperta.com */
     2!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e(require("jquery")):e(jQuery)}(function(e){"use strict";var o=!1,t=!1,r=0,i=2e3,s=0,n=e,l=document,a=window,c=n(a),d=[],u=a.requestAnimationFrame||a.webkitRequestAnimationFrame||a.mozRequestAnimationFrame||!1,h=a.cancelAnimationFrame||a.webkitCancelAnimationFrame||a.mozCancelAnimationFrame||!1;if(u)a.cancelAnimationFrame||(h=function(e){});else{var p=0;u=function(e,o){var t=(new Date).getTime(),r=Math.max(0,16-(t-p)),i=a.setTimeout(function(){e(t+r)},r);return p=t+r,i},h=function(e){a.clearTimeout(e)}}var m=a.MutationObserver||a.WebKitMutationObserver||!1,f=Date.now||function(){return(new Date).getTime()},g={zindex:"auto",cursoropacitymin:0,cursoropacitymax:1,cursorcolor:"#424242",cursorwidth:"6px",cursorborder:"1px solid #fff",cursorborderradius:"5px",scrollspeed:40,mousescrollstep:27,touchbehavior:!1,emulatetouch:!1,hwacceleration:!0,usetransition:!0,boxzoom:!1,dblclickzoom:!0,gesturezoom:!0,grabcursorenabled:!0,autohidemode:!0,background:"",iframeautoresize:!0,cursorminheight:32,preservenativescrolling:!0,railoffset:!1,railhoffset:!1,bouncescroll:!0,spacebarenabled:!0,railpadding:{top:0,right:0,left:0,bottom:0},disableoutline:!0,horizrailenabled:!0,railalign:"right",railvalign:"bottom",enabletranslate3d:!0,enablemousewheel:!0,enablekeyboard:!0,smoothscroll:!0,sensitiverail:!0,enablemouselockapi:!0,cursorfixedheight:!1,directionlockdeadzone:6,hidecursordelay:400,nativeparentscrolling:!0,enablescrollonselection:!0,overflowx:!0,overflowy:!0,cursordragspeed:.3,rtlmode:"auto",cursordragontouch:!1,oneaxismousemode:"auto",scriptpath:function(){var e=l.currentScript||function(){var e=l.getElementsByTagName("script");return!!e.length&&e[e.length-1]}(),o=e?e.src.split("?")[0]:"";return o.split("/").length>0?o.split("/").slice(0,-1).join("/")+"/":""}(),preventmultitouchscrolling:!0,disablemutationobserver:!1,enableobserver:!0,scrollbarid:!1},v=!1,w=function(){if(v)return v;var e=l.createElement("DIV"),o=e.style,t=navigator.userAgent,r=navigator.platform,i={};return i.haspointerlock="pointerLockElement"in l||"webkitPointerLockElement"in l||"mozPointerLockElement"in l,i.isopera="opera"in a,i.isopera12=i.isopera&&"getUserMedia"in navigator,i.isoperamini="[object OperaMini]"===Object.prototype.toString.call(a.operamini),i.isie="all"in l&&"attachEvent"in e&&!i.isopera,i.isieold=i.isie&&!("msInterpolationMode"in o),i.isie7=i.isie&&!i.isieold&&(!("documentMode"in l)||7===l.documentMode),i.isie8=i.isie&&"documentMode"in l&&8===l.documentMode,i.isie9=i.isie&&"performance"in a&&9===l.documentMode,i.isie10=i.isie&&"performance"in a&&10===l.documentMode,i.isie11="msRequestFullscreen"in e&&l.documentMode>=11,i.ismsedge="msCredentials"in a,i.ismozilla="MozAppearance"in o,i.iswebkit=!i.ismsedge&&"WebkitAppearance"in o,i.ischrome=i.iswebkit&&"chrome"in a,i.ischrome38=i.ischrome&&"touchAction"in o,i.ischrome22=!i.ischrome38&&i.ischrome&&i.haspointerlock,i.ischrome26=!i.ischrome38&&i.ischrome&&"transition"in o,i.cantouch="ontouchstart"in l.documentElement||"ontouchstart"in a,i.hasw3ctouch=(a.PointerEvent||!1)&&(navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0),i.hasmstouch=!i.hasw3ctouch&&(a.MSPointerEvent||!1),i.ismac=/^mac$/i.test(r),i.isios=i.cantouch&&/iphone|ipad|ipod/i.test(r),i.isios4=i.isios&&!("seal"in Object),i.isios7=i.isios&&"webkitHidden"in l,i.isios8=i.isios&&"hidden"in l,i.isios10=i.isios&&a.Proxy,i.isandroid=/android/i.test(t),i.haseventlistener="addEventListener"in e,i.trstyle=!1,i.hastransform=!1,i.hastranslate3d=!1,i.transitionstyle=!1,i.hastransition=!1,i.transitionend=!1,i.trstyle="transform",i.hastransform="transform"in o||function(){for(var e=["msTransform","webkitTransform","MozTransform","OTransform"],t=0,r=e.length;t<r;t++)if(void 0!==o[e[t]]){i.trstyle=e[t];break}i.hastransform=!!i.trstyle}(),i.hastransform&&(o[i.trstyle]="translate3d(1px,2px,3px)",i.hastranslate3d=/translate3d/.test(o[i.trstyle])),i.transitionstyle="transition",i.prefixstyle="",i.transitionend="transitionend",i.hastransition="transition"in o||function(){i.transitionend=!1;for(var e=["webkitTransition","msTransition","MozTransition","OTransition","OTransition","KhtmlTransition"],t=["-webkit-","-ms-","-moz-","-o-","-o","-khtml-"],r=["webkitTransitionEnd","msTransitionEnd","transitionend","otransitionend","oTransitionEnd","KhtmlTransitionEnd"],s=0,n=e.length;s<n;s++)if(e[s]in o){i.transitionstyle=e[s],i.prefixstyle=t[s],i.transitionend=r[s];break}i.ischrome26&&(i.prefixstyle=t[1]),i.hastransition=i.transitionstyle}(),i.cursorgrabvalue=function(){var e=["grab","-webkit-grab","-moz-grab"];(i.ischrome&&!i.ischrome38||i.isie)&&(e=[]);for(var t=0,r=e.length;t<r;t++){var s=e[t];if(o.cursor=s,o.cursor==s)return s}return"url(https://cdnjs.cloudflare.com/ajax/libs/slider-pro/1.3.0/css/images/openhand.cur),n-resize"}(),i.hasmousecapture="setCapture"in e,i.hasMutationObserver=!1!==m,e=null,v=i,i},b=function(e,p){function v(){var e=T.doc.css(P.trstyle);return!(!e||"matrix"!=e.substr(0,6))&&e.replace(/^.*\((.*)\)$/g,"$1").replace(/px/g,"").split(/, +/)}function b(){var e=T.win;if("zIndex"in e)return e.zIndex();for(;e.length>0;){if(9==e[0].nodeType)return!1;var o=e.css("zIndex");if(!isNaN(o)&&0!==o)return parseInt(o);e=e.parent()}return!1}function x(e,o,t){var r=e.css(o),i=parseFloat(r);if(isNaN(i)){var s=3==(i=I[r]||0)?t?T.win.outerHeight()-T.win.innerHeight():T.win.outerWidth()-T.win.innerWidth():1;return T.isie8&&i&&(i+=1),s?i:0}return i}function S(e,o,t,r){T._bind(e,o,function(r){var i={original:r=r||a.event,target:r.target||r.srcElement,type:"wheel",deltaMode:"MozMousePixelScroll"==r.type?0:1,deltaX:0,deltaZ:0,preventDefault:function(){return r.preventDefault?r.preventDefault():r.returnValue=!1,!1},stopImmediatePropagation:function(){r.stopImmediatePropagation?r.stopImmediatePropagation():r.cancelBubble=!0}};return"mousewheel"==o?(r.wheelDeltaX&&(i.deltaX=-.025*r.wheelDeltaX),r.wheelDeltaY&&(i.deltaY=-.025*r.wheelDeltaY),!i.deltaY&&!i.deltaX&&(i.deltaY=-.025*r.wheelDelta)):i.deltaY=r.detail,t.call(e,i)},r)}function z(e,o,t,r){T.scrollrunning||(T.newscrolly=T.getScrollTop(),T.newscrollx=T.getScrollLeft(),D=f());var i=f()-D;if(D=f(),i>350?A=1:A+=(2-A)/10,e=e*A|0,o=o*A|0,e){if(r)if(e<0){if(T.getScrollLeft()>=T.page.maxw)return!0}else if(T.getScrollLeft()<=0)return!0;var s=e>0?1:-1;X!==s&&(T.scrollmom&&T.scrollmom.stop(),T.newscrollx=T.getScrollLeft(),X=s),T.lastdeltax-=e}if(o){if(function(){var e=T.getScrollTop();if(o<0){if(e>=T.page.maxh)return!0}else if(e<=0)return!0}()){if(M.nativeparentscrolling&&t&&!T.ispage&&!T.zoomactive)return!0;var n=T.view.h>>1;T.newscrolly<-n?(T.newscrolly=-n,o=-1):T.newscrolly>T.page.maxh+n?(T.newscrolly=T.page.maxh+n,o=1):o=0}var l=o>0?1:-1;B!==l&&(T.scrollmom&&T.scrollmom.stop(),T.newscrolly=T.getScrollTop(),B=l),T.lastdeltay-=o}(o||e)&&T.synched("relativexy",function(){var e=T.lastdeltay+T.newscrolly;T.lastdeltay=0;var o=T.lastdeltax+T.newscrollx;T.lastdeltax=0,T.rail.drag||T.doScrollPos(o,e)})}function k(e,o,t){var r,i;return!(t||!q)||(0===e.deltaMode?(r=-e.deltaX*(M.mousescrollstep/54)|0,i=-e.deltaY*(M.mousescrollstep/54)|0):1===e.deltaMode&&(r=-e.deltaX*M.mousescrollstep*50/80|0,i=-e.deltaY*M.mousescrollstep*50/80|0),o&&M.oneaxismousemode&&0===r&&i&&(r=i,i=0,t&&(r<0?T.getScrollLeft()>=T.page.maxw:T.getScrollLeft()<=0)&&(i=r,r=0)),T.isrtlmode&&(r=-r),z(r,i,t,!0)?void(t&&(q=!0)):(q=!1,e.stopImmediatePropagation()))}var T=this;this.version="3.7.6",this.name="nicescroll",this.me=p;var E=n("body"),M=this.opt={doc:E,win:!1};if(n.extend(M,g),M.snapbackspeed=80,e)for(var L in M)void 0!==e[L]&&(M[L]=e[L]);if(M.disablemutationobserver&&(m=!1),this.doc=M.doc,this.iddoc=this.doc&&this.doc[0]?this.doc[0].id||"":"",this.ispage=/^BODY|HTML/.test(M.win?M.win[0].nodeName:this.doc[0].nodeName),this.haswrapper=!1!==M.win,this.win=M.win||(this.ispage?c:this.doc),this.docscroll=this.ispage&&!this.haswrapper?c:this.win,this.body=E,this.viewport=!1,this.isfixed=!1,this.iframe=!1,this.isiframe="IFRAME"==this.doc[0].nodeName&&"IFRAME"==this.win[0].nodeName,this.istextarea="TEXTAREA"==this.win[0].nodeName,this.forcescreen=!1,this.canshowonmouseevent="scroll"!=M.autohidemode,this.onmousedown=!1,this.onmouseup=!1,this.onmousemove=!1,this.onmousewheel=!1,this.onkeypress=!1,this.ongesturezoom=!1,this.onclick=!1,this.onscrollstart=!1,this.onscrollend=!1,this.onscrollcancel=!1,this.onzoomin=!1,this.onzoomout=!1,this.view=!1,this.page=!1,this.scroll={x:0,y:0},this.scrollratio={x:0,y:0},this.cursorheight=20,this.scrollvaluemax=0,"auto"==M.rtlmode){var C=this.win[0]==a?this.body:this.win,N=C.css("writing-mode")||C.css("-webkit-writing-mode")||C.css("-ms-writing-mode")||C.css("-moz-writing-mode");"horizontal-tb"==N||"lr-tb"==N||""===N?(this.isrtlmode="rtl"==C.css("direction"),this.isvertical=!1):(this.isrtlmode="vertical-rl"==N||"tb"==N||"tb-rl"==N||"rl-tb"==N,this.isvertical="vertical-rl"==N||"tb"==N||"tb-rl"==N)}else this.isrtlmode=!0===M.rtlmode,this.isvertical=!1;if(this.scrollrunning=!1,this.scrollmom=!1,this.observer=!1,this.observerremover=!1,this.observerbody=!1,!1!==M.scrollbarid)this.id=M.scrollbarid;else do{this.id="ascrail"+i++}while(l.getElementById(this.id));this.rail=!1,this.cursor=!1,this.cursorfreezed=!1,this.selectiondrag=!1,this.zoom=!1,this.zoomactive=!1,this.hasfocus=!1,this.hasmousefocus=!1,this.railslocked=!1,this.locked=!1,this.hidden=!1,this.cursoractive=!0,this.wheelprevented=!1,this.overflowx=M.overflowx,this.overflowy=M.overflowy,this.nativescrollingarea=!1,this.checkarea=0,this.events=[],this.saved={},this.delaylist={},this.synclist={},this.lastdeltax=0,this.lastdeltay=0,this.detected=w();var P=n.extend({},this.detected);this.canhwscroll=P.hastransform&&M.hwacceleration,this.ishwscroll=this.canhwscroll&&T.haswrapper,this.isrtlmode?this.isvertical?this.hasreversehr=!(P.iswebkit||P.isie||P.isie11):this.hasreversehr=!(P.iswebkit||P.isie&&!P.isie10&&!P.isie11):this.hasreversehr=!1,this.istouchcapable=!1,P.cantouch||!P.hasw3ctouch&&!P.hasmstouch?!P.cantouch||P.isios||P.isandroid||!P.iswebkit&&!P.ismozilla||(this.istouchcapable=!0):this.istouchcapable=!0,M.enablemouselockapi||(P.hasmousecapture=!1,P.haspointerlock=!1),this.debounced=function(e,o,t){T&&(T.delaylist[e]||!1||(T.delaylist[e]={h:u(function(){T.delaylist[e].fn.call(T),T.delaylist[e]=!1},t)},o.call(T)),T.delaylist[e].fn=o)},this.synched=function(e,o){T.synclist[e]?T.synclist[e]=o:(T.synclist[e]=o,u(function(){T&&(T.synclist[e]&&T.synclist[e].call(T),T.synclist[e]=null)}))},this.unsynched=function(e){T.synclist[e]&&(T.synclist[e]=!1)},this.css=function(e,o){for(var t in o)T.saved.css.push([e,t,e.css(t)]),e.css(t,o[t])},this.scrollTop=function(e){return void 0===e?T.getScrollTop():T.setScrollTop(e)},this.scrollLeft=function(e){return void 0===e?T.getScrollLeft():T.setScrollLeft(e)};var R=function(e,o,t,r,i,s,n){this.st=e,this.ed=o,this.spd=t,this.p1=r||0,this.p2=i||1,this.p3=s||0,this.p4=n||1,this.ts=f(),this.df=o-e};if(R.prototype={B2:function(e){return 3*(1-e)*(1-e)*e},B3:function(e){return 3*(1-e)*e*e},B4:function(e){return e*e*e},getPos:function(){return(f()-this.ts)/this.spd},getNow:function(){var e=(f()-this.ts)/this.spd,o=this.B2(e)+this.B3(e)+this.B4(e);return e>=1?this.ed:this.st+this.df*o|0},update:function(e,o){return this.st=this.getNow(),this.ed=e,this.spd=o,this.ts=f(),this.df=this.ed-this.st,this}},this.ishwscroll){this.doc.translate={x:0,y:0,tx:"0px",ty:"0px"},P.hastranslate3d&&P.isios&&this.doc.css("-webkit-backface-visibility","hidden"),this.getScrollTop=function(e){if(!e){var o=v();if(o)return 16==o.length?-o[13]:-o[5];if(T.timerscroll&&T.timerscroll.bz)return T.timerscroll.bz.getNow()}return T.doc.translate.y},this.getScrollLeft=function(e){if(!e){var o=v();if(o)return 16==o.length?-o[12]:-o[4];if(T.timerscroll&&T.timerscroll.bh)return T.timerscroll.bh.getNow()}return T.doc.translate.x},this.notifyScrollEvent=function(e){var o=l.createEvent("UIEvents");o.initUIEvent("scroll",!1,!1,a,1),o.niceevent=!0,e.dispatchEvent(o)};var _=this.isrtlmode?1:-1;P.hastranslate3d&&M.enabletranslate3d?(this.setScrollTop=function(e,o){T.doc.translate.y=e,T.doc.translate.ty=-1*e+"px",T.doc.css(P.trstyle,"translate3d("+T.doc.translate.tx+","+T.doc.translate.ty+",0)"),o||T.notifyScrollEvent(T.win[0])},this.setScrollLeft=function(e,o){T.doc.translate.x=e,T.doc.translate.tx=e*_+"px",T.doc.css(P.trstyle,"translate3d("+T.doc.translate.tx+","+T.doc.translate.ty+",0)"),o||T.notifyScrollEvent(T.win[0])}):(this.setScrollTop=function(e,o){T.doc.translate.y=e,T.doc.translate.ty=-1*e+"px",T.doc.css(P.trstyle,"translate("+T.doc.translate.tx+","+T.doc.translate.ty+")"),o||T.notifyScrollEvent(T.win[0])},this.setScrollLeft=function(e,o){T.doc.translate.x=e,T.doc.translate.tx=e*_+"px",T.doc.css(P.trstyle,"translate("+T.doc.translate.tx+","+T.doc.translate.ty+")"),o||T.notifyScrollEvent(T.win[0])})}else this.getScrollTop=function(){return T.docscroll.scrollTop()},this.setScrollTop=function(e){T.docscroll.scrollTop(e)},this.getScrollLeft=function(){return T.hasreversehr?T.detected.ismozilla?T.page.maxw-Math.abs(T.docscroll.scrollLeft()):T.page.maxw-T.docscroll.scrollLeft():T.docscroll.scrollLeft()},this.setScrollLeft=function(e){return setTimeout(function(){if(T)return T.hasreversehr&&(e=T.detected.ismozilla?-(T.page.maxw-e):T.page.maxw-e),T.docscroll.scrollLeft(e)},1)};this.getTarget=function(e){return!!e&&(e.target?e.target:!!e.srcElement&&e.srcElement)},this.hasParent=function(e,o){if(!e)return!1;for(var t=e.target||e.srcElement||e||!1;t&&t.id!=o;)t=t.parentNode||!1;return!1!==t};var I={thin:1,medium:3,thick:5};this.getDocumentScrollOffset=function(){return{top:a.pageYOffset||l.documentElement.scrollTop,left:a.pageXOffset||l.documentElement.scrollLeft}},this.getOffset=function(){if(T.isfixed){var e=T.win.offset(),o=T.getDocumentScrollOffset();return e.top-=o.top,e.left-=o.left,e}var t=T.win.offset();if(!T.viewport)return t;var r=T.viewport.offset();return{top:t.top-r.top,left:t.left-r.left}},this.updateScrollBar=function(e){var o,t;if(T.ishwscroll)T.rail.css({height:T.win.innerHeight()-(M.railpadding.top+M.railpadding.bottom)}),T.railh&&T.railh.css({width:T.win.innerWidth()-(M.railpadding.left+M.railpadding.right)});else{var r=T.getOffset();if(o={top:r.top,left:r.left-(M.railpadding.left+M.railpadding.right)},o.top+=x(T.win,"border-top-width",!0),o.left+=T.rail.align?T.win.outerWidth()-x(T.win,"border-right-width")-T.rail.width:x(T.win,"border-left-width"),(t=M.railoffset)&&(t.top&&(o.top+=t.top),t.left&&(o.left+=t.left)),T.railslocked||T.rail.css({top:o.top,left:o.left,height:(e?e.h:T.win.innerHeight())-(M.railpadding.top+M.railpadding.bottom)}),T.zoom&&T.zoom.css({top:o.top+1,left:1==T.rail.align?o.left-20:o.left+T.rail.width+4}),T.railh&&!T.railslocked){o={top:r.top,left:r.left},(t=M.railhoffset)&&(t.top&&(o.top+=t.top),t.left&&(o.left+=t.left));var i=T.railh.align?o.top+x(T.win,"border-top-width",!0)+T.win.innerHeight()-T.railh.height:o.top+x(T.win,"border-top-width",!0),s=o.left+x(T.win,"border-left-width");T.railh.css({top:i-(M.railpadding.top+M.railpadding.bottom),left:s,width:T.railh.width})}}},this.doRailClick=function(e,o,t){var r,i,s,n;T.railslocked||(T.cancelEvent(e),"pageY"in e||(e.pageX=e.clientX+l.documentElement.scrollLeft,e.pageY=e.clientY+l.documentElement.scrollTop),o?(r=t?T.doScrollLeft:T.doScrollTop,s=t?(e.pageX-T.railh.offset().left-T.cursorwidth/2)*T.scrollratio.x:(e.pageY-T.rail.offset().top-T.cursorheight/2)*T.scrollratio.y,T.unsynched("relativexy"),r(0|s)):(r=t?T.doScrollLeftBy:T.doScrollBy,s=t?T.scroll.x:T.scroll.y,n=t?e.pageX-T.railh.offset().left:e.pageY-T.rail.offset().top,i=t?T.view.w:T.view.h,r(s>=n?i:-i)))},T.newscrolly=T.newscrollx=0,T.hasanimationframe="requestAnimationFrame"in a,T.hascancelanimationframe="cancelAnimationFrame"in a,T.hasborderbox=!1,this.init=function(){if(T.saved.css=[],P.isoperamini)return!0;if(P.isandroid&&!("hidden"in l))return!0;M.emulatetouch=M.emulatetouch||M.touchbehavior,T.hasborderbox=a.getComputedStyle&&"border-box"===a.getComputedStyle(l.body)["box-sizing"];var e={"overflow-y":"hidden"};if((P.isie11||P.isie10)&&(e["-ms-overflow-style"]="none"),T.ishwscroll&&(this.doc.css(P.transitionstyle,P.prefixstyle+"transform 0ms ease-out"),P.transitionend&&T.bind(T.doc,P.transitionend,T.onScrollTransitionEnd,!1)),T.zindex="auto",T.ispage||"auto"!=M.zindex?T.zindex=M.zindex:T.zindex=b()||"auto",!T.ispage&&"auto"!=T.zindex&&T.zindex>s&&(s=T.zindex),T.isie&&0===T.zindex&&"auto"==M.zindex&&(T.zindex="auto"),!T.ispage||!P.isieold){var i=T.docscroll;T.ispage&&(i=T.haswrapper?T.win:T.doc),T.css(i,e),T.ispage&&(P.isie11||P.isie)&&T.css(n("html"),e),!P.isios||T.ispage||T.haswrapper||T.css(E,{"-webkit-overflow-scrolling":"touch"});var d=n(l.createElement("div"));d.css({position:"relative",top:0,float:"right",width:M.cursorwidth,height:0,"background-color":M.cursorcolor,border:M.cursorborder,"background-clip":"padding-box","-webkit-border-radius":M.cursorborderradius,"-moz-border-radius":M.cursorborderradius,"border-radius":M.cursorborderradius}),d.addClass("nicescroll-cursors"),T.cursor=d;var u=n(l.createElement("div"));u.attr("id",T.id),u.addClass("nicescroll-rails nicescroll-rails-vr");var h,p,f=["left","right","top","bottom"];for(var g in f)p=f[g],(h=M.railpadding[p]||0)&&u.css("padding-"+p,h+"px");u.append(d),u.width=Math.max(parseFloat(M.cursorwidth),d.outerWidth()),u.css({width:u.width+"px",zIndex:T.zindex,background:M.background,cursor:"default"}),u.visibility=!0,u.scrollable=!0,u.align="left"==M.railalign?0:1,T.rail=u,T.rail.drag=!1;var v=!1;!M.boxzoom||T.ispage||P.isieold||(v=l.createElement("div"),T.bind(v,"click",T.doZoom),T.bind(v,"mouseenter",function(){T.zoom.css("opacity",M.cursoropacitymax)}),T.bind(v,"mouseleave",function(){T.zoom.css("opacity",M.cursoropacitymin)}),T.zoom=n(v),T.zoom.css({cursor:"pointer",zIndex:T.zindex,backgroundImage:"url("+M.scriptpath+"zoomico.png)",height:18,width:18,backgroundPosition:"0 0"}),M.dblclickzoom&&T.bind(T.win,"dblclick",T.doZoom),P.cantouch&&M.gesturezoom&&(T.ongesturezoom=function(e){return e.scale>1.5&&T.doZoomIn(e),e.scale<.8&&T.doZoomOut(e),T.cancelEvent(e)},T.bind(T.win,"gestureend",T.ongesturezoom))),T.railh=!1;var w;if(M.horizrailenabled&&(T.css(i,{overflowX:"hidden"}),(d=n(l.createElement("div"))).css({position:"absolute",top:0,height:M.cursorwidth,width:0,backgroundColor:M.cursorcolor,border:M.cursorborder,backgroundClip:"padding-box","-webkit-border-radius":M.cursorborderradius,"-moz-border-radius":M.cursorborderradius,"border-radius":M.cursorborderradius}),P.isieold&&d.css("overflow","hidden"),d.addClass("nicescroll-cursors"),T.cursorh=d,(w=n(l.createElement("div"))).attr("id",T.id+"-hr"),w.addClass("nicescroll-rails nicescroll-rails-hr"),w.height=Math.max(parseFloat(M.cursorwidth),d.outerHeight()),w.css({height:w.height+"px",zIndex:T.zindex,background:M.background}),w.append(d),w.visibility=!0,w.scrollable=!0,w.align="top"==M.railvalign?0:1,T.railh=w,T.railh.drag=!1),T.ispage)u.css({position:"fixed",top:0,height:"100%"}),u.css(u.align?{right:0}:{left:0}),T.body.append(u),T.railh&&(w.css({position:"fixed",left:0,width:"100%"}),w.css(w.align?{bottom:0}:{top:0}),T.body.append(w));else{if(T.ishwscroll){"static"==T.win.css("position")&&T.css(T.win,{position:"relative"});var x="HTML"==T.win[0].nodeName?T.body:T.win;n(x).scrollTop(0).scrollLeft(0),T.zoom&&(T.zoom.css({position:"absolute",top:1,right:0,"margin-right":u.width+4}),x.append(T.zoom)),u.css({position:"absolute",top:0}),u.css(u.align?{right:0}:{left:0}),x.append(u),w&&(w.css({position:"absolute",left:0,bottom:0}),w.css(w.align?{bottom:0}:{top:0}),x.append(w))}else{T.isfixed="fixed"==T.win.css("position");var S=T.isfixed?"fixed":"absolute";T.isfixed||(T.viewport=T.getViewport(T.win[0])),T.viewport&&(T.body=T.viewport,/fixed|absolute/.test(T.viewport.css("position"))||T.css(T.viewport,{position:"relative"})),u.css({position:S}),T.zoom&&T.zoom.css({position:S}),T.updateScrollBar(),T.body.append(u),T.zoom&&T.body.append(T.zoom),T.railh&&(w.css({position:S}),T.body.append(w))}P.isios&&T.css(T.win,{"-webkit-tap-highlight-color":"rgba(0,0,0,0)","-webkit-touch-callout":"none"}),M.disableoutline&&(P.isie&&T.win.attr("hideFocus","true"),P.iswebkit&&T.win.css("outline","none"))}if(!1===M.autohidemode?(T.autohidedom=!1,T.rail.css({opacity:M.cursoropacitymax}),T.railh&&T.railh.css({opacity:M.cursoropacitymax})):!0===M.autohidemode||"leave"===M.autohidemode?(T.autohidedom=n().add(T.rail),P.isie8&&(T.autohidedom=T.autohidedom.add(T.cursor)),T.railh&&(T.autohidedom=T.autohidedom.add(T.railh)),T.railh&&P.isie8&&(T.autohidedom=T.autohidedom.add(T.cursorh))):"scroll"==M.autohidemode?(T.autohidedom=n().add(T.rail),T.railh&&(T.autohidedom=T.autohidedom.add(T.railh))):"cursor"==M.autohidemode?(T.autohidedom=n().add(T.cursor),T.railh&&(T.autohidedom=T.autohidedom.add(T.cursorh))):"hidden"==M.autohidemode&&(T.autohidedom=!1,T.hide(),T.railslocked=!1),P.cantouch||T.istouchcapable||M.emulatetouch||P.hasmstouch){T.scrollmom=new y(T);T.ontouchstart=function(e){if(T.locked)return!1;if(e.pointerType&&("mouse"===e.pointerType||e.pointerType===e.MSPOINTER_TYPE_MOUSE))return!1;if(T.hasmoving=!1,T.scrollmom.timer&&(T.triggerScrollEnd(),T.scrollmom.stop()),!T.railslocked){var o=T.getTarget(e);if(o&&/INPUT/i.test(o.nodeName)&&/range/i.test(o.type))return T.stopPropagation(e);var t="mousedown"===e.type;if(!("clientX"in e)&&"changedTouches"in e&&(e.clientX=e.changedTouches[0].clientX,e.clientY=e.changedTouches[0].clientY),T.forcescreen){var r=e;(e={original:e.original?e.original:e}).clientX=r.screenX,e.clientY=r.screenY}if(T.rail.drag={x:e.clientX,y:e.clientY,sx:T.scroll.x,sy:T.scroll.y,st:T.getScrollTop(),sl:T.getScrollLeft(),pt:2,dl:!1,tg:o},T.ispage||!M.directionlockdeadzone)T.rail.drag.dl="f";else{var i={w:c.width(),h:c.height()},s=T.getContentSize(),l=s.h-i.h,a=s.w-i.w;T.rail.scrollable&&!T.railh.scrollable?T.rail.drag.ck=l>0&&"v":!T.rail.scrollable&&T.railh.scrollable?T.rail.drag.ck=a>0&&"h":T.rail.drag.ck=!1}if(M.emulatetouch&&T.isiframe&&P.isie){var d=T.win.position();T.rail.drag.x+=d.left,T.rail.drag.y+=d.top}if(T.hasmoving=!1,T.lastmouseup=!1,T.scrollmom.reset(e.clientX,e.clientY),o&&t){if(!/INPUT|SELECT|BUTTON|TEXTAREA/i.test(o.nodeName))return P.hasmousecapture&&o.setCapture(),M.emulatetouch?(o.onclick&&!o._onclick&&(o._onclick=o.onclick,o.onclick=function(e){if(T.hasmoving)return!1;o._onclick.call(this,e)}),T.cancelEvent(e)):T.stopPropagation(e);/SUBMIT|CANCEL|BUTTON/i.test(n(o).attr("type"))&&(T.preventclick={tg:o,click:!1})}}},T.ontouchend=function(e){if(!T.rail.drag)return!0;if(2==T.rail.drag.pt){if(e.pointerType&&("mouse"===e.pointerType||e.pointerType===e.MSPOINTER_TYPE_MOUSE))return!1;T.rail.drag=!1;var o="mouseup"===e.type;if(T.hasmoving&&(T.scrollmom.doMomentum(),T.lastmouseup=!0,T.hideCursor(),P.hasmousecapture&&l.releaseCapture(),o))return T.cancelEvent(e)}else if(1==T.rail.drag.pt)return T.onmouseup(e)};var z=M.emulatetouch&&T.isiframe&&!P.hasmousecapture,k=.3*M.directionlockdeadzone|0;T.ontouchmove=function(e,o){if(!T.rail.drag)return!0;if(e.targetTouches&&M.preventmultitouchscrolling&&e.targetTouches.length>1)return!0;if(e.pointerType&&("mouse"===e.pointerType||e.pointerType===e.MSPOINTER_TYPE_MOUSE))return!0;if(2==T.rail.drag.pt){"changedTouches"in e&&(e.clientX=e.changedTouches[0].clientX,e.clientY=e.changedTouches[0].clientY);var t,r;if(r=t=0,z&&!o){var i=T.win.position();r=-i.left,t=-i.top}var s=e.clientY+t,n=s-T.rail.drag.y,a=e.clientX+r,c=a-T.rail.drag.x,d=T.rail.drag.st-n;if(T.ishwscroll&&M.bouncescroll)d<0?d=Math.round(d/2):d>T.page.maxh&&(d=T.page.maxh+Math.round((d-T.page.maxh)/2));else if(d<0?(d=0,s=0):d>T.page.maxh&&(d=T.page.maxh,s=0),0===s&&!T.hasmoving)return T.ispage||(T.rail.drag=!1),!0;var u=T.getScrollLeft();if(T.railh&&T.railh.scrollable&&(u=T.isrtlmode?c-T.rail.drag.sl:T.rail.drag.sl-c,T.ishwscroll&&M.bouncescroll?u<0?u=Math.round(u/2):u>T.page.maxw&&(u=T.page.maxw+Math.round((u-T.page.maxw)/2)):(u<0&&(u=0,a=0),u>T.page.maxw&&(u=T.page.maxw,a=0))),!T.hasmoving){if(T.rail.drag.y===e.clientY&&T.rail.drag.x===e.clientX)return T.cancelEvent(e);var h=Math.abs(n),p=Math.abs(c),m=M.directionlockdeadzone;if(T.rail.drag.ck?"v"==T.rail.drag.ck?p>m&&h<=k?T.rail.drag=!1:h>m&&(T.rail.drag.dl="v"):"h"==T.rail.drag.ck&&(h>m&&p<=k?T.rail.drag=!1:p>m&&(T.rail.drag.dl="h")):h>m&&p>m?T.rail.drag.dl="f":h>m?T.rail.drag.dl=p>k?"f":"v":p>m&&(T.rail.drag.dl=h>k?"f":"h"),!T.rail.drag.dl)return T.cancelEvent(e);T.triggerScrollStart(e.clientX,e.clientY,0,0,0),T.hasmoving=!0}return T.preventclick&&!T.preventclick.click&&(T.preventclick.click=T.preventclick.tg.onclick||!1,T.preventclick.tg.onclick=T.onpreventclick),T.rail.drag.dl&&("v"==T.rail.drag.dl?u=T.rail.drag.sl:"h"==T.rail.drag.dl&&(d=T.rail.drag.st)),T.synched("touchmove",function(){T.rail.drag&&2==T.rail.drag.pt&&(T.prepareTransition&&T.resetTransition(),T.rail.scrollable&&T.setScrollTop(d),T.scrollmom.update(a,s),T.railh&&T.railh.scrollable?(T.setScrollLeft(u),T.showCursor(d,u)):T.showCursor(d),P.isie10&&l.selection.clear())}),T.cancelEvent(e)}return 1==T.rail.drag.pt?T.onmousemove(e):void 0},T.ontouchstartCursor=function(e,o){if(!T.rail.drag||3==T.rail.drag.pt){if(T.locked)return T.cancelEvent(e);T.cancelScroll(),T.rail.drag={x:e.touches[0].clientX,y:e.touches[0].clientY,sx:T.scroll.x,sy:T.scroll.y,pt:3,hr:!!o};var t=T.getTarget(e);return!T.ispage&&P.hasmousecapture&&t.setCapture(),T.isiframe&&!P.hasmousecapture&&(T.saved.csspointerevents=T.doc.css("pointer-events"),T.css(T.doc,{"pointer-events":"none"})),T.cancelEvent(e)}},T.ontouchendCursor=function(e){if(T.rail.drag){if(P.hasmousecapture&&l.releaseCapture(),T.isiframe&&!P.hasmousecapture&&T.doc.css("pointer-events",T.saved.csspointerevents),3!=T.rail.drag.pt)return;return T.rail.drag=!1,T.cancelEvent(e)}},T.ontouchmoveCursor=function(e){if(T.rail.drag){if(3!=T.rail.drag.pt)return;if(T.cursorfreezed=!0,T.rail.drag.hr){T.scroll.x=T.rail.drag.sx+(e.touches[0].clientX-T.rail.drag.x),T.scroll.x<0&&(T.scroll.x=0);var o=T.scrollvaluemaxw;T.scroll.x>o&&(T.scroll.x=o)}else{T.scroll.y=T.rail.drag.sy+(e.touches[0].clientY-T.rail.drag.y),T.scroll.y<0&&(T.scroll.y=0);var t=T.scrollvaluemax;T.scroll.y>t&&(T.scroll.y=t)}return T.synched("touchmove",function(){T.rail.drag&&3==T.rail.drag.pt&&(T.showCursor(),T.rail.drag.hr?T.doScrollLeft(Math.round(T.scroll.x*T.scrollratio.x),M.cursordragspeed):T.doScrollTop(Math.round(T.scroll.y*T.scrollratio.y),M.cursordragspeed))}),T.cancelEvent(e)}}}if(T.onmousedown=function(e,o){if(!T.rail.drag||1==T.rail.drag.pt){if(T.railslocked)return T.cancelEvent(e);T.cancelScroll(),T.rail.drag={x:e.clientX,y:e.clientY,sx:T.scroll.x,sy:T.scroll.y,pt:1,hr:o||!1};var t=T.getTarget(e);return P.hasmousecapture&&t.setCapture(),T.isiframe&&!P.hasmousecapture&&(T.saved.csspointerevents=T.doc.css("pointer-events"),T.css(T.doc,{"pointer-events":"none"})),T.hasmoving=!1,T.cancelEvent(e)}},T.onmouseup=function(e){if(T.rail.drag)return 1!=T.rail.drag.pt||(P.hasmousecapture&&l.releaseCapture(),T.isiframe&&!P.hasmousecapture&&T.doc.css("pointer-events",T.saved.csspointerevents),T.rail.drag=!1,T.cursorfreezed=!1,T.hasmoving&&T.triggerScrollEnd(),T.cancelEvent(e))},T.onmousemove=function(e){if(T.rail.drag){if(1!==T.rail.drag.pt)return;if(P.ischrome&&0===e.which)return T.onmouseup(e);if(T.cursorfreezed=!0,T.hasmoving||T.triggerScrollStart(e.clientX,e.clientY,0,0,0),T.hasmoving=!0,T.rail.drag.hr){T.scroll.x=T.rail.drag.sx+(e.clientX-T.rail.drag.x),T.scroll.x<0&&(T.scroll.x=0);var o=T.scrollvaluemaxw;T.scroll.x>o&&(T.scroll.x=o)}else{T.scroll.y=T.rail.drag.sy+(e.clientY-T.rail.drag.y),T.scroll.y<0&&(T.scroll.y=0);var t=T.scrollvaluemax;T.scroll.y>t&&(T.scroll.y=t)}return T.synched("mousemove",function(){T.cursorfreezed&&(T.showCursor(),T.rail.drag.hr?T.scrollLeft(Math.round(T.scroll.x*T.scrollratio.x)):T.scrollTop(Math.round(T.scroll.y*T.scrollratio.y)))}),T.cancelEvent(e)}T.checkarea=0},P.cantouch||M.emulatetouch)T.onpreventclick=function(e){if(T.preventclick)return T.preventclick.tg.onclick=T.preventclick.click,T.preventclick=!1,T.cancelEvent(e)},T.onclick=!P.isios&&function(e){return!T.lastmouseup||(T.lastmouseup=!1,T.cancelEvent(e))},M.grabcursorenabled&&P.cursorgrabvalue&&(T.css(T.ispage?T.doc:T.win,{cursor:P.cursorgrabvalue}),T.css(T.rail,{cursor:P.cursorgrabvalue}));else{var L=function(e){if(T.selectiondrag){if(e){var o=T.win.outerHeight(),t=e.pageY-T.selectiondrag.top;t>0&&t<o&&(t=0),t>=o&&(t-=o),T.selectiondrag.df=t}if(0!==T.selectiondrag.df){var r=-2*T.selectiondrag.df/6|0;T.doScrollBy(r),T.debounced("doselectionscroll",function(){L()},50)}}};T.hasTextSelected="getSelection"in l?function(){return l.getSelection().rangeCount>0}:"selection"in l?function(){return"None"!=l.selection.type}:function(){return!1},T.onselectionstart=function(e){T.ispage||(T.selectiondrag=T.win.offset())},T.onselectionend=function(e){T.selectiondrag=!1},T.onselectiondrag=function(e){T.selectiondrag&&T.hasTextSelected()&&T.debounced("selectionscroll",function(){L(e)},250)}}if(P.hasw3ctouch?(T.css(T.ispage?n("html"):T.win,{"touch-action":"none"}),T.css(T.rail,{"touch-action":"none"}),T.css(T.cursor,{"touch-action":"none"}),T.bind(T.win,"pointerdown",T.ontouchstart),T.bind(l,"pointerup",T.ontouchend),T.delegate(l,"pointermove",T.ontouchmove)):P.hasmstouch?(T.css(T.ispage?n("html"):T.win,{"-ms-touch-action":"none"}),T.css(T.rail,{"-ms-touch-action":"none"}),T.css(T.cursor,{"-ms-touch-action":"none"}),T.bind(T.win,"MSPointerDown",T.ontouchstart),T.bind(l,"MSPointerUp",T.ontouchend),T.delegate(l,"MSPointerMove",T.ontouchmove),T.bind(T.cursor,"MSGestureHold",function(e){e.preventDefault()}),T.bind(T.cursor,"contextmenu",function(e){e.preventDefault()})):P.cantouch&&(T.bind(T.win,"touchstart",T.ontouchstart,!1,!0),T.bind(l,"touchend",T.ontouchend,!1,!0),T.bind(l,"touchcancel",T.ontouchend,!1,!0),T.delegate(l,"touchmove",T.ontouchmove,!1,!0)),M.emulatetouch&&(T.bind(T.win,"mousedown",T.ontouchstart,!1,!0),T.bind(l,"mouseup",T.ontouchend,!1,!0),T.bind(l,"mousemove",T.ontouchmove,!1,!0)),(M.cursordragontouch||!P.cantouch&&!M.emulatetouch)&&(T.rail.css({cursor:"default"}),T.railh&&T.railh.css({cursor:"default"}),T.jqbind(T.rail,"mouseenter",function(){if(!T.ispage&&!T.win.is(":visible"))return!1;T.canshowonmouseevent&&T.showCursor(),T.rail.active=!0}),T.jqbind(T.rail,"mouseleave",function(){T.rail.active=!1,T.rail.drag||T.hideCursor()}),M.sensitiverail&&(T.bind(T.rail,"click",function(e){T.doRailClick(e,!1,!1)}),T.bind(T.rail,"dblclick",function(e){T.doRailClick(e,!0,!1)}),T.bind(T.cursor,"click",function(e){T.cancelEvent(e)}),T.bind(T.cursor,"dblclick",function(e){T.cancelEvent(e)})),T.railh&&(T.jqbind(T.railh,"mouseenter",function(){if(!T.ispage&&!T.win.is(":visible"))return!1;T.canshowonmouseevent&&T.showCursor(),T.rail.active=!0}),T.jqbind(T.railh,"mouseleave",function(){T.rail.active=!1,T.rail.drag||T.hideCursor()}),M.sensitiverail&&(T.bind(T.railh,"click",function(e){T.doRailClick(e,!1,!0)}),T.bind(T.railh,"dblclick",function(e){T.doRailClick(e,!0,!0)}),T.bind(T.cursorh,"click",function(e){T.cancelEvent(e)}),T.bind(T.cursorh,"dblclick",function(e){T.cancelEvent(e)})))),M.cursordragontouch&&(this.istouchcapable||P.cantouch)&&(T.bind(T.cursor,"touchstart",T.ontouchstartCursor),T.bind(T.cursor,"touchmove",T.ontouchmoveCursor),T.bind(T.cursor,"touchend",T.ontouchendCursor),T.cursorh&&T.bind(T.cursorh,"touchstart",function(e){T.ontouchstartCursor(e,!0)}),T.cursorh&&T.bind(T.cursorh,"touchmove",T.ontouchmoveCursor),T.cursorh&&T.bind(T.cursorh,"touchend",T.ontouchendCursor)),M.emulatetouch||P.isandroid||P.isios?(T.bind(P.hasmousecapture?T.win:l,"mouseup",T.ontouchend),T.onclick&&T.bind(l,"click",T.onclick),M.cursordragontouch?(T.bind(T.cursor,"mousedown",T.onmousedown),T.bind(T.cursor,"mouseup",T.onmouseup),T.cursorh&&T.bind(T.cursorh,"mousedown",function(e){T.onmousedown(e,!0)}),T.cursorh&&T.bind(T.cursorh,"mouseup",T.onmouseup)):(T.bind(T.rail,"mousedown",function(e){e.preventDefault()}),T.railh&&T.bind(T.railh,"mousedown",function(e){e.preventDefault()}))):(T.bind(P.hasmousecapture?T.win:l,"mouseup",T.onmouseup),T.bind(l,"mousemove",T.onmousemove),T.onclick&&T.bind(l,"click",T.onclick),T.bind(T.cursor,"mousedown",T.onmousedown),T.bind(T.cursor,"mouseup",T.onmouseup),T.railh&&(T.bind(T.cursorh,"mousedown",function(e){T.onmousedown(e,!0)}),T.bind(T.cursorh,"mouseup",T.onmouseup)),!T.ispage&&M.enablescrollonselection&&(T.bind(T.win[0],"mousedown",T.onselectionstart),T.bind(l,"mouseup",T.onselectionend),T.bind(T.cursor,"mouseup",T.onselectionend),T.cursorh&&T.bind(T.cursorh,"mouseup",T.onselectionend),T.bind(l,"mousemove",T.onselectiondrag)),T.zoom&&(T.jqbind(T.zoom,"mouseenter",function(){T.canshowonmouseevent&&T.showCursor(),T.rail.active=!0}),T.jqbind(T.zoom,"mouseleave",function(){T.rail.active=!1,T.rail.drag||T.hideCursor()}))),M.enablemousewheel&&(T.isiframe||T.mousewheel(P.isie&&T.ispage?l:T.win,T.onmousewheel),T.mousewheel(T.rail,T.onmousewheel),T.railh&&T.mousewheel(T.railh,T.onmousewheelhr)),T.ispage||P.cantouch||/HTML|^BODY/.test(T.win[0].nodeName)||(T.win.attr("tabindex")||T.win.attr({tabindex:++r}),T.bind(T.win,"focus",function(e){o=T.getTarget(e).id||T.getTarget(e)||!1,T.hasfocus=!0,T.canshowonmouseevent&&T.noticeCursor()}),T.bind(T.win,"blur",function(e){o=!1,T.hasfocus=!1}),T.bind(T.win,"mouseenter",function(e){t=T.getTarget(e).id||T.getTarget(e)||!1,T.hasmousefocus=!0,T.canshowonmouseevent&&T.noticeCursor()}),T.bind(T.win,"mouseleave",function(e){t=!1,T.hasmousefocus=!1,T.rail.drag||T.hideCursor()})),T.onkeypress=function(e){if(T.railslocked&&0===T.page.maxh)return!0;e=e||a.event;var r=T.getTarget(e);if(r&&/INPUT|TEXTAREA|SELECT|OPTION/.test(r.nodeName)&&(!(r.getAttribute("type")||r.type||!1)||!/submit|button|cancel/i.tp))return!0;if(n(r).attr("contenteditable"))return!0;if(T.hasfocus||T.hasmousefocus&&!o||T.ispage&&!o&&!t){var i=e.keyCode;if(T.railslocked&&27!=i)return T.cancelEvent(e);var s=e.ctrlKey||!1,l=e.shiftKey||!1,c=!1;switch(i){case 38:case 63233:T.doScrollBy(72),c=!0;break;case 40:case 63235:T.doScrollBy(-72),c=!0;break;case 37:case 63232:T.railh&&(s?T.doScrollLeft(0):T.doScrollLeftBy(72),c=!0);break;case 39:case 63234:T.railh&&(s?T.doScrollLeft(T.page.maxw):T.doScrollLeftBy(-72),c=!0);break;case 33:case 63276:T.doScrollBy(T.view.h),c=!0;break;case 34:case 63277:T.doScrollBy(-T.view.h),c=!0;break;case 36:case 63273:T.railh&&s?T.doScrollPos(0,0):T.doScrollTo(0),c=!0;break;case 35:case 63275:T.railh&&s?T.doScrollPos(T.page.maxw,T.page.maxh):T.doScrollTo(T.page.maxh),c=!0;break;case 32:M.spacebarenabled&&(l?T.doScrollBy(T.view.h):T.doScrollBy(-T.view.h),c=!0);break;case 27:T.zoomactive&&(T.doZoom(),c=!0)}if(c)return T.cancelEvent(e)}},M.enablekeyboard&&T.bind(l,P.isopera&&!P.isopera12?"keypress":"keydown",T.onkeypress),T.bind(l,"keydown",function(e){(e.ctrlKey||!1)&&(T.wheelprevented=!0)}),T.bind(l,"keyup",function(e){e.ctrlKey||!1||(T.wheelprevented=!1)}),T.bind(a,"blur",function(e){T.wheelprevented=!1}),T.bind(a,"resize",T.onscreenresize),T.bind(a,"orientationchange",T.onscreenresize),T.bind(a,"load",T.lazyResize),P.ischrome&&!T.ispage&&!T.haswrapper){var C=T.win.attr("style"),N=parseFloat(T.win.css("width"))+1;T.win.css("width",N),T.synched("chromefix",function(){T.win.attr("style",C)})}if(T.onAttributeChange=function(e){T.lazyResize(T.isieold?250:30)},M.enableobserver&&(T.isie11||!1===m||(T.observerbody=new m(function(e){if(e.forEach(function(e){if("attributes"==e.type)return E.hasClass("modal-open")&&E.hasClass("modal-dialog")&&!n.contains(n(".modal-dialog")[0],T.doc[0])?T.hide():T.show()}),T.me.clientWidth!=T.page.width||T.me.clientHeight!=T.page.height)return T.lazyResize(30)}),T.observerbody.observe(l.body,{childList:!0,subtree:!0,characterData:!1,attributes:!0,attributeFilter:["class"]})),!T.ispage&&!T.haswrapper)){var R=T.win[0];!1!==m?(T.observer=new m(function(e){e.forEach(T.onAttributeChange)}),T.observer.observe(R,{childList:!0,characterData:!1,attributes:!0,subtree:!1}),T.observerremover=new m(function(e){e.forEach(function(e){if(e.removedNodes.length>0)for(var o in e.removedNodes)if(T&&e.removedNodes[o]===R)return T.remove()})}),T.observerremover.observe(R.parentNode,{childList:!0,characterData:!1,attributes:!1,subtree:!1})):(T.bind(R,P.isie&&!P.isie9?"propertychange":"DOMAttrModified",T.onAttributeChange),P.isie9&&R.attachEvent("onpropertychange",T.onAttributeChange),T.bind(R,"DOMNodeRemoved",function(e){e.target===R&&T.remove()}))}!T.ispage&&M.boxzoom&&T.bind(a,"resize",T.resizeZoom),T.istextarea&&(T.bind(T.win,"keydown",T.lazyResize),T.bind(T.win,"mouseup",T.lazyResize)),T.lazyResize(30)}if("IFRAME"==this.doc[0].nodeName){var _=function(){T.iframexd=!1;var o;try{(o="contentDocument"in this?this.contentDocument:this.contentWindow._doc).domain}catch(e){T.iframexd=!0,o=!1}if(T.iframexd)return"console"in a&&console.log("NiceScroll error: policy restriced iframe"),!0;if(T.forcescreen=!0,T.isiframe&&(T.iframe={doc:n(o),html:T.doc.contents().find("html")[0],body:T.doc.contents().find("body")[0]},T.getContentSize=function(){return{w:Math.max(T.iframe.html.scrollWidth,T.iframe.body.scrollWidth),h:Math.max(T.iframe.html.scrollHeight,T.iframe.body.scrollHeight)}},T.docscroll=n(T.iframe.body)),!P.isios&&M.iframeautoresize&&!T.isiframe){T.win.scrollTop(0),T.doc.height("");var t=Math.max(o.getElementsByTagName("html")[0].scrollHeight,o.body.scrollHeight);T.doc.height(t)}T.lazyResize(30),T.css(n(T.iframe.body),e),P.isios&&T.haswrapper&&T.css(n(o.body),{"-webkit-transform":"translate3d(0,0,0)"}),"contentWindow"in this?T.bind(this.contentWindow,"scroll",T.onscroll):T.bind(o,"scroll",T.onscroll),M.enablemousewheel&&T.mousewheel(o,T.onmousewheel),M.enablekeyboard&&T.bind(o,P.isopera?"keypress":"keydown",T.onkeypress),P.cantouch?(T.bind(o,"touchstart",T.ontouchstart),T.bind(o,"touchmove",T.ontouchmove)):M.emulatetouch&&(T.bind(o,"mousedown",T.ontouchstart),T.bind(o,"mousemove",function(e){return T.ontouchmove(e,!0)}),M.grabcursorenabled&&P.cursorgrabvalue&&T.css(n(o.body),{cursor:P.cursorgrabvalue})),T.bind(o,"mouseup",T.ontouchend),T.zoom&&(M.dblclickzoom&&T.bind(o,"dblclick",T.doZoom),T.ongesturezoom&&T.bind(o,"gestureend",T.ongesturezoom))};this.doc[0].readyState&&"complete"===this.doc[0].readyState&&setTimeout(function(){_.call(T.doc[0],!1)},500),T.bind(this.doc,"load",_)}},this.showCursor=function(e,o){if(T.cursortimeout&&(clearTimeout(T.cursortimeout),T.cursortimeout=0),T.rail){if(T.autohidedom&&(T.autohidedom.stop().css({opacity:M.cursoropacitymax}),T.cursoractive=!0),T.rail.drag&&1==T.rail.drag.pt||(void 0!==e&&!1!==e&&(T.scroll.y=e/T.scrollratio.y|0),void 0!==o&&(T.scroll.x=o/T.scrollratio.x|0)),T.cursor.css({height:T.cursorheight,top:T.scroll.y}),T.cursorh){var t=T.hasreversehr?T.scrollvaluemaxw-T.scroll.x:T.scroll.x;T.cursorh.css({width:T.cursorwidth,left:!T.rail.align&&T.rail.visibility?t+T.rail.width:t}),T.cursoractive=!0}T.zoom&&T.zoom.stop().css({opacity:M.cursoropacitymax})}},this.hideCursor=function(e){T.cursortimeout||T.rail&&T.autohidedom&&(T.hasmousefocus&&"leave"===M.autohidemode||(T.cursortimeout=setTimeout(function(){T.rail.active&&T.showonmouseevent||(T.autohidedom.stop().animate({opacity:M.cursoropacitymin}),T.zoom&&T.zoom.stop().animate({opacity:M.cursoropacitymin}),T.cursoractive=!1),T.cursortimeout=0},e||M.hidecursordelay)))},this.noticeCursor=function(e,o,t){T.showCursor(o,t),T.rail.active||T.hideCursor(e)},this.getContentSize=T.ispage?function(){return{w:Math.max(l.body.scrollWidth,l.documentElement.scrollWidth),h:Math.max(l.body.scrollHeight,l.documentElement.scrollHeight)}}:T.haswrapper?function(){return{w:T.doc[0].offsetWidth,h:T.doc[0].offsetHeight}}:function(){return{w:T.docscroll[0].scrollWidth,h:T.docscroll[0].scrollHeight}},this.onResize=function(e,o){if(!T||!T.win)return!1;var t=T.page.maxh,r=T.page.maxw,i=T.view.h,s=T.view.w;if(T.view={w:T.ispage?T.win.width():T.win[0].clientWidth,h:T.ispage?T.win.height():T.win[0].clientHeight},T.page=o||T.getContentSize(),T.page.maxh=Math.max(0,T.page.h-T.view.h),T.page.maxw=Math.max(0,T.page.w-T.view.w),T.page.maxh==t&&T.page.maxw==r&&T.view.w==s&&T.view.h==i){if(T.ispage)return T;var n=T.win.offset();if(T.lastposition){var l=T.lastposition;if(l.top==n.top&&l.left==n.left)return T}T.lastposition=n}return 0===T.page.maxh?(T.hideRail(),T.scrollvaluemax=0,T.scroll.y=0,T.scrollratio.y=0,T.cursorheight=0,T.setScrollTop(0),T.rail&&(T.rail.scrollable=!1)):(T.page.maxh-=M.railpadding.top+M.railpadding.bottom,T.rail.scrollable=!0),0===T.page.maxw?(T.hideRailHr(),T.scrollvaluemaxw=0,T.scroll.x=0,T.scrollratio.x=0,T.cursorwidth=0,T.setScrollLeft(0),T.railh&&(T.railh.scrollable=!1)):(T.page.maxw-=M.railpadding.left+M.railpadding.right,T.railh&&(T.railh.scrollable=M.horizrailenabled)),T.railslocked=T.locked||0===T.page.maxh&&0===T.page.maxw,T.railslocked?(T.ispage||T.updateScrollBar(T.view),!1):(T.hidden||(T.rail.visibility||T.showRail(),T.railh&&!T.railh.visibility&&T.showRailHr()),T.istextarea&&T.win.css("resize")&&"none"!=T.win.css("resize")&&(T.view.h-=20),T.cursorheight=Math.min(T.view.h,Math.round(T.view.h*(T.view.h/T.page.h))),T.cursorheight=M.cursorfixedheight?M.cursorfixedheight:Math.max(M.cursorminheight,T.cursorheight),T.cursorwidth=Math.min(T.view.w,Math.round(T.view.w*(T.view.w/T.page.w))),T.cursorwidth=M.cursorfixedheight?M.cursorfixedheight:Math.max(M.cursorminheight,T.cursorwidth),T.scrollvaluemax=T.view.h-T.cursorheight-(M.railpadding.top+M.railpadding.bottom),T.hasborderbox||(T.scrollvaluemax-=T.cursor[0].offsetHeight-T.cursor[0].clientHeight),T.railh&&(T.railh.width=T.page.maxh>0?T.view.w-T.rail.width:T.view.w,T.scrollvaluemaxw=T.railh.width-T.cursorwidth-(M.railpadding.left+M.railpadding.right)),T.ispage||T.updateScrollBar(T.view),T.scrollratio={x:T.page.maxw/T.scrollvaluemaxw,y:T.page.maxh/T.scrollvaluemax},T.getScrollTop()>T.page.maxh?T.doScrollTop(T.page.maxh):(T.scroll.y=T.getScrollTop()/T.scrollratio.y|0,T.scroll.x=T.getScrollLeft()/T.scrollratio.x|0,T.cursoractive&&T.noticeCursor()),T.scroll.y&&0===T.getScrollTop()&&T.doScrollTo(T.scroll.y*T.scrollratio.y|0),T)},this.resize=T.onResize;var O=0;this.onscreenresize=function(e){clearTimeout(O);var o=!T.ispage&&!T.haswrapper;o&&T.hideRails(),O=setTimeout(function(){T&&(o&&T.showRails(),T.resize()),O=0},120)},this.lazyResize=function(e){return clearTimeout(O),e=isNaN(e)?240:e,O=setTimeout(function(){T&&T.resize(),O=0},e),T},this.jqbind=function(e,o,t){T.events.push({e:e,n:o,f:t,q:!0}),n(e).on(o,t)},this.mousewheel=function(e,o,t){var r="jquery"in e?e[0]:e;if("onwheel"in l.createElement("div"))T._bind(r,"wheel",o,t||!1);else{var i=void 0!==l.onmousewheel?"mousewheel":"DOMMouseScroll";S(r,i,o,t||!1),"DOMMouseScroll"==i&&S(r,"MozMousePixelScroll",o,t||!1)}};var Y=!1;if(P.haseventlistener){try{var H=Object.defineProperty({},"passive",{get:function(){Y=!0}});a.addEventListener("test",null,H)}catch(e){}this.stopPropagation=function(e){return!!e&&((e=e.original?e.original:e).stopPropagation(),!1)},this.cancelEvent=function(e){return e.cancelable&&e.preventDefault(),e.stopImmediatePropagation(),e.preventManipulation&&e.preventManipulation(),!1}}else Event.prototype.preventDefault=function(){this.returnValue=!1},Event.prototype.stopPropagation=function(){this.cancelBubble=!0},a.constructor.prototype.addEventListener=l.constructor.prototype.addEventListener=Element.prototype.addEventListener=function(e,o,t){this.attachEvent("on"+e,o)},a.constructor.prototype.removeEventListener=l.constructor.prototype.removeEventListener=Element.prototype.removeEventListener=function(e,o,t){this.detachEvent("on"+e,o)},this.cancelEvent=function(e){return(e=e||a.event)&&(e.cancelBubble=!0,e.cancel=!0,e.returnValue=!1),!1},this.stopPropagation=function(e){return(e=e||a.event)&&(e.cancelBubble=!0),!1};this.delegate=function(e,o,t,r,i){var s=d[o]||!1;s||(s={a:[],l:[],f:function(e){for(var o=s.l,t=!1,r=o.length-1;r>=0;r--)if(!1===(t=o[r].call(e.target,e)))return!1;return t}},T.bind(e,o,s.f,r,i),d[o]=s),T.ispage?(s.a=[T.id].concat(s.a),s.l=[t].concat(s.l)):(s.a.push(T.id),s.l.push(t))},this.undelegate=function(e,o,t,r,i){var s=d[o]||!1;if(s&&s.l)for(var n=0,l=s.l.length;n<l;n++)s.a[n]===T.id&&(s.a.splice(n),s.l.splice(n),0===s.a.length&&(T._unbind(e,o,s.l.f),d[o]=null))},this.bind=function(e,o,t,r,i){var s="jquery"in e?e[0]:e;T._bind(s,o,t,r||!1,i||!1)},this._bind=function(e,o,t,r,i){T.events.push({e:e,n:o,f:t,b:r,q:!1}),Y&&i?e.addEventListener(o,t,{passive:!1,capture:r}):e.addEventListener(o,t,r||!1)},this._unbind=function(e,o,t,r){d[o]?T.undelegate(e,o,t,r):e.removeEventListener(o,t,r)},this.unbindAll=function(){for(var e=0;e<T.events.length;e++){var o=T.events[e];o.q?o.e.unbind(o.n,o.f):T._unbind(o.e,o.n,o.f,o.b)}},this.showRails=function(){return T.showRail().showRailHr()},this.showRail=function(){return 0===T.page.maxh||!T.ispage&&"none"==T.win.css("display")||(T.rail.visibility=!0,T.rail.css("display","block")),T},this.showRailHr=function(){return T.railh&&(0===T.page.maxw||!T.ispage&&"none"==T.win.css("display")||(T.railh.visibility=!0,T.railh.css("display","block"))),T},this.hideRails=function(){return T.hideRail().hideRailHr()},this.hideRail=function(){return T.rail.visibility=!1,T.rail.css("display","none"),T},this.hideRailHr=function(){return T.railh&&(T.railh.visibility=!1,T.railh.css("display","none")),T},this.show=function(){return T.hidden=!1,T.railslocked=!1,T.showRails()},this.hide=function(){return T.hidden=!0,T.railslocked=!0,T.hideRails()},this.toggle=function(){return T.hidden?T.show():T.hide()},this.remove=function(){T.stop(),T.cursortimeout&&clearTimeout(T.cursortimeout);for(var e in T.delaylist)T.delaylist[e]&&h(T.delaylist[e].h);T.doZoomOut(),T.unbindAll(),P.isie9&&T.win[0].detachEvent("onpropertychange",T.onAttributeChange),!1!==T.observer&&T.observer.disconnect(),!1!==T.observerremover&&T.observerremover.disconnect(),!1!==T.observerbody&&T.observerbody.disconnect(),T.events=null,T.cursor&&T.cursor.remove(),T.cursorh&&T.cursorh.remove(),T.rail&&T.rail.remove(),T.railh&&T.railh.remove(),T.zoom&&T.zoom.remove();for(var o=0;o<T.saved.css.length;o++){var t=T.saved.css[o];t[0].css(t[1],void 0===t[2]?"":t[2])}T.saved=!1,T.me.data("__nicescroll","");var r=n.nicescroll;r.each(function(e){if(this&&this.id===T.id){delete r[e];for(var o=++e;o<r.length;o++,e++)r[e]=r[o];--r.length&&delete r[r.length]}});for(var i in T)T[i]=null,delete T[i];T=null},this.scrollstart=function(e){return this.onscrollstart=e,T},this.scrollend=function(e){return this.onscrollend=e,T},this.scrollcancel=function(e){return this.onscrollcancel=e,T},this.zoomin=function(e){return this.onzoomin=e,T},this.zoomout=function(e){return this.onzoomout=e,T},this.isScrollable=function(e){var o=e.target?e.target:e;if("OPTION"==o.nodeName)return!0;for(;o&&1==o.nodeType&&o!==this.me[0]&&!/^BODY|HTML/.test(o.nodeName);){var t=n(o),r=t.css("overflowY")||t.css("overflowX")||t.css("overflow")||"";if(/scroll|auto/.test(r))return o.clientHeight!=o.scrollHeight;o=!!o.parentNode&&o.parentNode}return!1},this.getViewport=function(e){for(var o=!(!e||!e.parentNode)&&e.parentNode;o&&1==o.nodeType&&!/^BODY|HTML/.test(o.nodeName);){var t=n(o);if(/fixed|absolute/.test(t.css("position")))return t;var r=t.css("overflowY")||t.css("overflowX")||t.css("overflow")||"";if(/scroll|auto/.test(r)&&o.clientHeight!=o.scrollHeight)return t;if(t.getNiceScroll().length>0)return t;o=!!o.parentNode&&o.parentNode}return!1},this.triggerScrollStart=function(e,o,t,r,i){if(T.onscrollstart){var s={type:"scrollstart",current:{x:e,y:o},request:{x:t,y:r},end:{x:T.newscrollx,y:T.newscrolly},speed:i};T.onscrollstart.call(T,s)}},this.triggerScrollEnd=function(){if(T.onscrollend){var e=T.getScrollLeft(),o=T.getScrollTop(),t={type:"scrollend",current:{x:e,y:o},end:{x:e,y:o}};T.onscrollend.call(T,t)}};var B=0,X=0,D=0,A=1,q=!1;if(this.onmousewheel=function(e){if(T.wheelprevented||T.locked)return!1;if(T.railslocked)return T.debounced("checkunlock",T.resize,250),!1;if(T.rail.drag)return T.cancelEvent(e);if("auto"===M.oneaxismousemode&&0!==e.deltaX&&(M.oneaxismousemode=!1),M.oneaxismousemode&&0===e.deltaX&&!T.rail.scrollable)return!T.railh||!T.railh.scrollable||T.onmousewheelhr(e);var o=f(),t=!1;if(M.preservenativescrolling&&T.checkarea+600<o&&(T.nativescrollingarea=T.isScrollable(e),t=!0),T.checkarea=o,T.nativescrollingarea)return!0;var r=k(e,!1,t);return r&&(T.checkarea=0),r},this.onmousewheelhr=function(e){if(!T.wheelprevented){if(T.railslocked||!T.railh.scrollable)return!0;if(T.rail.drag)return T.cancelEvent(e);var o=f(),t=!1;return M.preservenativescrolling&&T.checkarea+600<o&&(T.nativescrollingarea=T.isScrollable(e),t=!0),T.checkarea=o,!!T.nativescrollingarea||(T.railslocked?T.cancelEvent(e):k(e,!0,t))}},this.stop=function(){return T.cancelScroll(),T.scrollmon&&T.scrollmon.stop(),T.cursorfreezed=!1,T.scroll.y=Math.round(T.getScrollTop()*(1/T.scrollratio.y)),T.noticeCursor(),T},this.getTransitionSpeed=function(e){return 80+e/72*M.scrollspeed|0},M.smoothscroll)if(T.ishwscroll&&P.hastransition&&M.usetransition&&M.smoothscroll){var j="";this.resetTransition=function(){j="",T.doc.css(P.prefixstyle+"transition-duration","0ms")},this.prepareTransition=function(e,o){var t=o?e:T.getTransitionSpeed(e),r=t+"ms";return j!==r&&(j=r,T.doc.css(P.prefixstyle+"transition-duration",r)),t},this.doScrollLeft=function(e,o){var t=T.scrollrunning?T.newscrolly:T.getScrollTop();T.doScrollPos(e,t,o)},this.doScrollTop=function(e,o){var t=T.scrollrunning?T.newscrollx:T.getScrollLeft();T.doScrollPos(t,e,o)},this.cursorupdate={running:!1,start:function(){var e=this;if(!e.running){e.running=!0;var o=function(){e.running&&u(o),T.showCursor(T.getScrollTop(),T.getScrollLeft()),T.notifyScrollEvent(T.win[0])};u(o)}},stop:function(){this.running=!1}},this.doScrollPos=function(e,o,t){var r=T.getScrollTop(),i=T.getScrollLeft();if(((T.newscrolly-r)*(o-r)<0||(T.newscrollx-i)*(e-i)<0)&&T.cancelScroll(),M.bouncescroll?(o<0?o=o/2|0:o>T.page.maxh&&(o=T.page.maxh+(o-T.page.maxh)/2|0),e<0?e=e/2|0:e>T.page.maxw&&(e=T.page.maxw+(e-T.page.maxw)/2|0)):(o<0?o=0:o>T.page.maxh&&(o=T.page.maxh),e<0?e=0:e>T.page.maxw&&(e=T.page.maxw)),T.scrollrunning&&e==T.newscrollx&&o==T.newscrolly)return!1;T.newscrolly=o,T.newscrollx=e;var s=T.getScrollTop(),n=T.getScrollLeft(),l={};l.x=e-n,l.y=o-s;var a=0|Math.sqrt(l.x*l.x+l.y*l.y),c=T.prepareTransition(a);T.scrollrunning||(T.scrollrunning=!0,T.triggerScrollStart(n,s,e,o,c),T.cursorupdate.start()),T.scrollendtrapped=!0,P.transitionend||(T.scrollendtrapped&&clearTimeout(T.scrollendtrapped),T.scrollendtrapped=setTimeout(T.onScrollTransitionEnd,c)),T.setScrollTop(T.newscrolly),T.setScrollLeft(T.newscrollx)},this.cancelScroll=function(){if(!T.scrollendtrapped)return!0;var e=T.getScrollTop(),o=T.getScrollLeft();return T.scrollrunning=!1,P.transitionend||clearTimeout(P.transitionend),T.scrollendtrapped=!1,T.resetTransition(),T.setScrollTop(e),T.railh&&T.setScrollLeft(o),T.timerscroll&&T.timerscroll.tm&&clearInterval(T.timerscroll.tm),T.timerscroll=!1,T.cursorfreezed=!1,T.cursorupdate.stop(),T.showCursor(e,o),T},this.onScrollTransitionEnd=function(){if(T.scrollendtrapped){var e=T.getScrollTop(),o=T.getScrollLeft();if(e<0?e=0:e>T.page.maxh&&(e=T.page.maxh),o<0?o=0:o>T.page.maxw&&(o=T.page.maxw),e!=T.newscrolly||o!=T.newscrollx)return T.doScrollPos(o,e,M.snapbackspeed);T.scrollrunning&&T.triggerScrollEnd(),T.scrollrunning=!1,T.scrollendtrapped=!1,T.resetTransition(),T.timerscroll=!1,T.setScrollTop(e),T.railh&&T.setScrollLeft(o),T.cursorupdate.stop(),T.noticeCursor(!1,e,o),T.cursorfreezed=!1}}}else this.doScrollLeft=function(e,o){var t=T.scrollrunning?T.newscrolly:T.getScrollTop();T.doScrollPos(e,t,o)},this.doScrollTop=function(e,o){var t=T.scrollrunning?T.newscrollx:T.getScrollLeft();T.doScrollPos(t,e,o)},this.doScrollPos=function(e,o,t){var r=T.getScrollTop(),i=T.getScrollLeft();((T.newscrolly-r)*(o-r)<0||(T.newscrollx-i)*(e-i)<0)&&T.cancelScroll();var s=!1;if(T.bouncescroll&&T.rail.visibility||(o<0?(o=0,s=!0):o>T.page.maxh&&(o=T.page.maxh,s=!0)),T.bouncescroll&&T.railh.visibility||(e<0?(e=0,s=!0):e>T.page.maxw&&(e=T.page.maxw,s=!0)),T.scrollrunning&&T.newscrolly===o&&T.newscrollx===e)return!0;T.newscrolly=o,T.newscrollx=e,T.dst={},T.dst.x=e-i,T.dst.y=o-r,T.dst.px=i,T.dst.py=r;var n=0|Math.sqrt(T.dst.x*T.dst.x+T.dst.y*T.dst.y),l=T.getTransitionSpeed(n);T.bzscroll={};var a=s?1:.58;T.bzscroll.x=new R(i,T.newscrollx,l,0,0,a,1),T.bzscroll.y=new R(r,T.newscrolly,l,0,0,a,1);f();var c=function(){if(T.scrollrunning){var e=T.bzscroll.y.getPos();T.setScrollLeft(T.bzscroll.x.getNow()),T.setScrollTop(T.bzscroll.y.getNow()),e<=1?T.timer=u(c):(T.scrollrunning=!1,T.timer=0,T.triggerScrollEnd())}};T.scrollrunning||(T.triggerScrollStart(i,r,e,o,l),T.scrollrunning=!0,T.timer=u(c))},this.cancelScroll=function(){return T.timer&&h(T.timer),T.timer=0,T.bzscroll=!1,T.scrollrunning=!1,T};else this.doScrollLeft=function(e,o){var t=T.getScrollTop();T.doScrollPos(e,t,o)},this.doScrollTop=function(e,o){var t=T.getScrollLeft();T.doScrollPos(t,e,o)},this.doScrollPos=function(e,o,t){var r=e>T.page.maxw?T.page.maxw:e;r<0&&(r=0);var i=o>T.page.maxh?T.page.maxh:o;i<0&&(i=0),T.synched("scroll",function(){T.setScrollTop(i),T.setScrollLeft(r)})},this.cancelScroll=function(){};this.doScrollBy=function(e,o){z(0,e)},this.doScrollLeftBy=function(e,o){z(e,0)},this.doScrollTo=function(e,o){var t=o?Math.round(e*T.scrollratio.y):e;t<0?t=0:t>T.page.maxh&&(t=T.page.maxh),T.cursorfreezed=!1,T.doScrollTop(e)},this.checkContentSize=function(){var e=T.getContentSize();e.h==T.page.h&&e.w==T.page.w||T.resize(!1,e)},T.onscroll=function(e){T.rail.drag||T.cursorfreezed||T.synched("scroll",function(){T.scroll.y=Math.round(T.getScrollTop()/T.scrollratio.y),T.railh&&(T.scroll.x=Math.round(T.getScrollLeft()/T.scrollratio.x)),T.noticeCursor()})},T.bind(T.docscroll,"scroll",T.onscroll),this.doZoomIn=function(e){if(!T.zoomactive){T.zoomactive=!0,T.zoomrestore={style:{}};var o=["position","top","left","zIndex","backgroundColor","marginTop","marginBottom","marginLeft","marginRight"],t=T.win[0].style;for(var r in o){var i=o[r];T.zoomrestore.style[i]=void 0!==t[i]?t[i]:""}T.zoomrestore.style.width=T.win.css("width"),T.zoomrestore.style.height=T.win.css("height"),T.zoomrestore.padding={w:T.win.outerWidth()-T.win.width(),h:T.win.outerHeight()-T.win.height()},P.isios4&&(T.zoomrestore.scrollTop=c.scrollTop(),c.scrollTop(0)),T.win.css({position:P.isios4?"absolute":"fixed",top:0,left:0,zIndex:s+100,margin:0});var n=T.win.css("backgroundColor");return(""===n||/transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(n))&&T.win.css("backgroundColor","#fff"),T.rail.css({zIndex:s+101}),T.zoom.css({zIndex:s+102}),T.zoom.css("backgroundPosition","0 -18px"),T.resizeZoom(),T.onzoomin&&T.onzoomin.call(T),T.cancelEvent(e)}},this.doZoomOut=function(e){if(T.zoomactive)return T.zoomactive=!1,T.win.css("margin",""),T.win.css(T.zoomrestore.style),P.isios4&&c.scrollTop(T.zoomrestore.scrollTop),T.rail.css({"z-index":T.zindex}),T.zoom.css({"z-index":T.zindex}),T.zoomrestore=!1,T.zoom.css("backgroundPosition","0 0"),T.onResize(),T.onzoomout&&T.onzoomout.call(T),T.cancelEvent(e)},this.doZoom=function(e){return T.zoomactive?T.doZoomOut(e):T.doZoomIn(e)},this.resizeZoom=function(){if(T.zoomactive){var e=T.getScrollTop();T.win.css({width:c.width()-T.zoomrestore.padding.w+"px",height:c.height()-T.zoomrestore.padding.h+"px"}),T.onResize(),T.setScrollTop(Math.min(T.page.maxh,e))}},this.init(),n.nicescroll.push(this)},y=function(e){var o=this;this.nc=e,this.lastx=0,this.lasty=0,this.speedx=0,this.speedy=0,this.lasttime=0,this.steptime=0,this.snapx=!1,this.snapy=!1,this.demulx=0,this.demuly=0,this.lastscrollx=-1,this.lastscrolly=-1,this.chkx=0,this.chky=0,this.timer=0,this.reset=function(e,t){o.stop(),o.steptime=0,o.lasttime=f(),o.speedx=0,o.speedy=0,o.lastx=e,o.lasty=t,o.lastscrollx=-1,o.lastscrolly=-1},this.update=function(e,t){var r=f();o.steptime=r-o.lasttime,o.lasttime=r;var i=t-o.lasty,s=e-o.lastx,n=o.nc.getScrollTop()+i,l=o.nc.getScrollLeft()+s;o.snapx=l<0||l>o.nc.page.maxw,o.snapy=n<0||n>o.nc.page.maxh,o.speedx=s,o.speedy=i,o.lastx=e,o.lasty=t},this.stop=function(){o.nc.unsynched("domomentum2d"),o.timer&&clearTimeout(o.timer),o.timer=0,o.lastscrollx=-1,o.lastscrolly=-1},this.doSnapy=function(e,t){var r=!1;t<0?(t=0,r=!0):t>o.nc.page.maxh&&(t=o.nc.page.maxh,r=!0),e<0?(e=0,r=!0):e>o.nc.page.maxw&&(e=o.nc.page.maxw,r=!0),r?o.nc.doScrollPos(e,t,o.nc.opt.snapbackspeed):o.nc.triggerScrollEnd()},this.doMomentum=function(e){var t=f(),r=e?t+e:o.lasttime,i=o.nc.getScrollLeft(),s=o.nc.getScrollTop(),n=o.nc.page.maxh,l=o.nc.page.maxw;o.speedx=l>0?Math.min(60,o.speedx):0,o.speedy=n>0?Math.min(60,o.speedy):0;var a=r&&t-r<=60;(s<0||s>n||i<0||i>l)&&(a=!1);var c=!(!o.speedy||!a)&&o.speedy,d=!(!o.speedx||!a)&&o.speedx;if(c||d){var u=Math.max(16,o.steptime);if(u>50){var h=u/50;o.speedx*=h,o.speedy*=h,u=50}o.demulxy=0,o.lastscrollx=o.nc.getScrollLeft(),o.chkx=o.lastscrollx,o.lastscrolly=o.nc.getScrollTop(),o.chky=o.lastscrolly;var p=o.lastscrollx,m=o.lastscrolly,g=function(){var e=f()-t>600?.04:.02;o.speedx&&(p=Math.floor(o.lastscrollx-o.speedx*(1-o.demulxy)),o.lastscrollx=p,(p<0||p>l)&&(e=.1)),o.speedy&&(m=Math.floor(o.lastscrolly-o.speedy*(1-o.demulxy)),o.lastscrolly=m,(m<0||m>n)&&(e=.1)),o.demulxy=Math.min(1,o.demulxy+e),o.nc.synched("domomentum2d",function(){if(o.speedx){o.nc.getScrollLeft();o.chkx=p,o.nc.setScrollLeft(p)}if(o.speedy){o.nc.getScrollTop();o.chky=m,o.nc.setScrollTop(m)}o.timer||(o.nc.hideCursor(),o.doSnapy(p,m))}),o.demulxy<1?o.timer=setTimeout(g,u):(o.stop(),o.nc.hideCursor(),o.doSnapy(p,m))};g()}else o.doSnapy(o.nc.getScrollLeft(),o.nc.getScrollTop())}},x=e.fn.scrollTop;e.cssHooks.pageYOffset={get:function(e,o,t){var r=n.data(e,"__nicescroll")||!1;return r&&r.ishwscroll?r.getScrollTop():x.call(e)},set:function(e,o){var t=n.data(e,"__nicescroll")||!1;return t&&t.ishwscroll?t.setScrollTop(parseInt(o)):x.call(e,o),this}},e.fn.scrollTop=function(e){if(void 0===e){var o=!!this[0]&&(n.data(this[0],"__nicescroll")||!1);return o&&o.ishwscroll?o.getScrollTop():x.call(this)}return this.each(function(){var o=n.data(this,"__nicescroll")||!1;o&&o.ishwscroll?o.setScrollTop(parseInt(e)):x.call(n(this),e)})};var S=e.fn.scrollLeft;n.cssHooks.pageXOffset={get:function(e,o,t){var r=n.data(e,"__nicescroll")||!1;return r&&r.ishwscroll?r.getScrollLeft():S.call(e)},set:function(e,o){var t=n.data(e,"__nicescroll")||!1;return t&&t.ishwscroll?t.setScrollLeft(parseInt(o)):S.call(e,o),this}},e.fn.scrollLeft=function(e){if(void 0===e){var o=!!this[0]&&(n.data(this[0],"__nicescroll")||!1);return o&&o.ishwscroll?o.getScrollLeft():S.call(this)}return this.each(function(){var o=n.data(this,"__nicescroll")||!1;o&&o.ishwscroll?o.setScrollLeft(parseInt(e)):S.call(n(this),e)})};var z=function(e){var o=this;if(this.length=0,this.name="nicescrollarray",this.each=function(e){return n.each(o,e),o},this.push=function(e){o[o.length]=e,o.length++},this.eq=function(e){return o[e]},e)for(var t=0;t<e.length;t++){var r=n.data(e[t],"__nicescroll")||!1;r&&(this[this.length]=r,this.length++)}return this};!function(e,o,t){for(var r=0,i=o.length;r<i;r++)t(e,o[r])}(z.prototype,["show","hide","toggle","onResize","resize","remove","stop","doScrollPos"],function(e,o){e[o]=function(){var e=arguments;return this.each(function(){this[o].apply(this,e)})}}),e.fn.getNiceScroll=function(e){return void 0===e?new z(this):this[e]&&n.data(this[e],"__nicescroll")||!1},(e.expr.pseudos||e.expr[":"]).nicescroll=function(e){return void 0!==n.data(e,"__nicescroll")},n.fn.niceScroll=function(e,o){void 0!==o||"object"!=typeof e||"jquery"in e||(o=e,e=!1);var t=new z;return this.each(function(){var r=n(this),i=n.extend({},o);if(e){var s=n(e);i.doc=s.length>1?n(e,r):s,i.win=r}!("doc"in i)||"win"in i||(i.win=r);var l=r.data("__nicescroll")||!1;l||(i.doc=i.doc||r,l=new b(i,r),r.data("__nicescroll",l)),t.push(l)}),1===t.length?t[0]:t},a.NiceScroll={getjQuery:function(){return e}},n.nicescroll||(n.nicescroll=new z,n.nicescroll.options=g)});
  • ws-custom-scrollbar/trunk/js/scripts.js

    r1271098 r3126870  
    1 jQuery(document).ready(function(){
     1jQuery(document).ready(function($){
    22   jQuery('#ws_custom_scrollbar_bgcolor,#ws_custom_scrollbar_border_color').wpColorPicker();
    33});
  • ws-custom-scrollbar/trunk/readme.txt

    r1668559 r3126870  
    22Contributors: webshouters
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XBSYRZVSV3JLJ
    4 Tags:  custom scrollbar,scrollbar, scrollbar,appearance, custom scroll, custom scroll bar, custom scroll bars, custom scrollbar, Custom Scrollbars, scroll, Scroll bar, scroll bars,admin,login, page, pages,plugin,shortcode,sidebar, widget, widgets, woocommerce, wordpress,youtube
     4Tags:  custom scrollbar,scrollbar, scrollbar,appearance, custom scroll, custom scroll bar, custom scroll bars, custom scrollbar, Custom Scrollbars, scroll, Scroll bar, scroll bars,admin,login, page, pages,plugin,shortcode,sidebar, widget, widgets, woocommerce, wordpress,youtube,nicescroll
    55Requires at least: 3.0
    6 Tested up to: 4.7
    7 Stable tag: 1.1
     6Tested up to: 6.6.1
     7Stable tag: 1.2
     8PHP version: 5.4.2 or higher
    89License: GPLv2 or later
    910License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5253
    53541. Go to your wp-admin > Settings > WS Custom Scrollbar Page  and change the options.
     552. ScrollTop settings
    5456
    5557== Changelog ==
     58
     59= 1.2 =
     60* Fixed deprecated jquery issue
    5661
    5762= 1.1 =
  • ws-custom-scrollbar/trunk/ws-custom-scrollbar.php

    r1668527 r3126870  
    66Author: WebShouters
    77Author URI: http://www.webshouters.com/
    8 Version: 1.1
     8Version: 1.2
    99Text Domain: webshouters
    1010License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.