PageSourceSearch

https://www.ferveurlyonnaise.fr/wp-content/themes/the-league/js/scripts.js?ver=7.1.2

js ferveurlyonnaise.fr collected 2026-10-04 02:40:41 UTC 110,116 bytes, 3,247 lines download raw bytes

1jQuery(document).ready(function($) {
2"use strict";
3
4  	// Fly-Out Navigation
5	$(".mvp-fly-but-click").on('click', function(){
6		$("#mvp-fly-wrap").toggleClass("mvp-fly-menu");
7  		$(".mvp-fly-but-wrap").toggleClass("mvp-fly-open");
8  		$(".mvp-fly-fade").toggleClass("mvp-fly-fade-trans");
9	});
10
11	// Back to Top Button
12    	var duration = 500;
13    	$('.back-to-top').on('click', function(event) {
14          event.preventDefault();
15          $('html, body').animate({scrollTop: 0}, duration);
16          return false;
17    	});
18
19 	// Search Toggle
20 	$(".mvp-search-click").on('click', function(){
21 	  $("#mvp-search-wrap").toggleClass("mvp-search-toggle");
22  	});
23
24 	// Mobile Social Toggle
25 	$(".mvp-mob-soc-click").on('click', function(){
26 	  $(".mvp-mob-soc-list").toggleClass("mvp-mob-soc-tog");
27  	});
28
29 	// Trending Toggle
30 	$(".mvp-post-trend-but-click").on('click', function(){
31 	  $("#mvp-post-trend-wrap").toggleClass("mvp-post-trend-tog");
32  	});
33
34   	// Comments Toggle
35   	$(".mvp-com-click").on('click', function(){
36	  $("#comments").show();
37  	  $("#disqus_thread").show();
38  	  $("#mvp-comments-button").hide();
39  	});
40
41   	// Continue Reading Toggle
42   	$(".mvp-ad-rel-click").on('click', function(){
43	  $("#mvp-content-main").css('max-height','none');
44  	  $('#mvp-ad-rel-wrap').css('margin-top','20px');
45  	  $("#mvp-ad-rel-top").hide();
46  	});
47
48	// Columns Toggle
49	$('.mvp-side-tab-wrap').each(function() {
50		$(this).find(".mvp-tab-col-cont").hide(); //Hide all content
51		$(this).find("ul.mvp-col-tabs li.mvp-feat-col-tab").addClass("active").show(); //Activate first tab
52		$(this).find(".mvp-tab-col-cont:first").show(); //Show first tab content
53	});
54
55	$("ul.mvp-col-tabs li").on('click', function(e) {
56		$(this).parents('.mvp-side-tab-wrap').find("ul.mvp-col-tabs li").removeClass("active"); //Remove any "active" class
57		$(this).addClass("active"); //Add "active" class to selected tab
58		$(this).parents('.mvp-side-tab-wrap').find(".mvp-tab-col-cont").hide(); //Hide all tab content
59
60		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
61		$(this).parents('.mvp-side-tab-wrap').find(activeTab).fadeIn(); //Fade in the active ID content
62
63		e.preventDefault();
64	});
65
66	$("ul.mvp-col-tabs li a").on('click', function(e) {
67		e.preventDefault();
68	});
69
70});
71
72
73	// Nicescroll
74
75(function(jQuery){
76
77  // globals
78  var domfocus = false;
79  var mousefocus = false;
80  var zoomactive = false;
81  var tabindexcounter = 5000;
82  var ascrailcounter = 2000;
83  var globalmaxzindex = 0;
84
85  var $ = jQuery;  // sandbox
86
87  // http://stackoverflow.com/questions/2161159/get-script-path
88  function getScriptPath() {
89    var scripts=document.getElementsByTagName('script');
90    var path=scripts[scripts.length-1].src.split('?')[0];
91    return (path.split('/').length>0) ? path.split('/').slice(0,-1).join('/')+'/' : '';
92  }
93  var scriptpath = getScriptPath();
94
95  var vendors = ['ms','moz','webkit','o'];
96
97  var setAnimationFrame = window.requestAnimationFrame||false;
98  var clearAnimationFrame = window.cancelAnimationFrame||false;
99
100  if (!setAnimationFrame) {
101    for(var vx in vendors) {
102      var v = vendors[vx];
103      if (!setAnimationFrame) setAnimationFrame = window[v+'RequestAnimationFrame'];
104      if (!clearAnimationFrame) clearAnimationFrame = window[v+'CancelAnimationFrame']||window[v+'CancelRequestAnimationFrame'];
105    }
106  }
107
108  var clsMutationObserver = window.MutationObserver || window.WebKitMutationObserver || false;
109
110  var _globaloptions = {
111      zindex:"auto",
112      cursoropacitymin:0,
113      cursoropacitymax:1,
114      cursorcolor:"#424242",
115      cursorwidth:"5px",
116      cursorborder:"1px solid #fff",
117      cursorborderradius:"5px",
118      scrollspeed:60,
119      mousescrollstep:8*3,
120      touchbehavior:false,
121      hwacceleration:true,
122      usetransition:true,
123      boxzoom:false,
124      dblclickzoom:true,
125      gesturezoom:true,
126      grabcursorenabled:true,
127      autohidemode:true,
128      background:"",
129      iframeautoresize:true,
130      cursorminheight:32,
131      preservenativescrolling:true,
132      railoffset:false,
133      bouncescroll:true,
134      spacebarenabled:true,
135      railpadding:{top:0,right:0,left:0,bottom:0},
136      disableoutline:true,
137      horizrailenabled:true,
138      railalign:"right",
139      railvalign:"bottom",
140      enabletranslate3d:true,
141      enablemousewheel:true,
142      enablekeyboard:true,
143      smoothscroll:true,
144      sensitiverail:true,
145      enablemouselockapi:true,
146//      cursormaxheight:false,
147      cursorfixedheight:false,
148      directionlockdeadzone:6,
149      hidecursordelay:400,
150      nativeparentscrolling:true,
151      enablescrollonselection:true,
152      overflowx:true,
153      overflowy:true,
154      cursordragspeed:0.3,
155      rtlmode:false,
156      cursordragontouch:false,
157      oneaxismousemode:"auto"
158  }
159
160  var browserdetected = false;
161
162  var getBrowserDetection = function() {
163
164    if (browserdetected) return browserdetected;
165
166    var domtest = document.createElement('DIV');
167
168    var d = {};
169
170		d.haspointerlock = "pointerLockElement" in document || "mozPointerLockElement" in document || "webkitPointerLockElement" in document;
171
172    d.isopera = ("opera" in window);
173    d.isopera12 = (d.isopera&&("getUserMedia" in navigator));
174    d.isoperamini = (Object.prototype.toString.call(window.operamini) === "[object OperaMini]");
175
176    d.isie = (("all" in document) && ("attachEvent" in domtest) && !d.isopera);
177    d.isieold = (d.isie && !("msInterpolationMode" in domtest.style));  // IE6 and older
178    d.isie7 = d.isie&&!d.isieold&&(!("documentMode" in document)||(document.documentMode==7));
179    d.isie8 = d.isie&&("documentMode" in document)&&(document.documentMode==8);
180    d.isie9 = d.isie&&("performance" in window)&&(document.documentMode>=9);
181    d.isie10 = d.isie&&("performance" in window)&&(document.documentMode>=10);
182
183    d.isie9mobile = /iemobile.9/i.test(navigator.userAgent);  //wp 7.1 mango
184    if (d.isie9mobile) d.isie9 = false;
185    d.isie7mobile = (!d.isie9mobile&&d.isie7) && /iemobile/i.test(navigator.userAgent);  //wp 7.0
186
187    d.ismozilla = ("MozAppearance" in domtest.style);
188
189    d.iswebkit = ("WebkitAppearance" in domtest.style);
190
191    d.ischrome = ("chrome" in window);
192		d.ischrome22 = (d.ischrome&&d.haspointerlock);
193    d.ischrome26 = (d.ischrome&&("transition" in domtest.style));  // issue with transform detection (maintain prefix)
194
195    d.cantouch = ("ontouchstart" in document.documentElement)||("ontouchstart" in window);  // detection for Chrome Touch Emulation
196    d.hasmstouch = (window.navigator.msPointerEnabled||false);  // IE10+ pointer events
197
198    d.ismac = /^mac$/i.test(navigator.platform);
199
200    d.isios = (d.cantouch && /iphone|ipad|ipod/i.test(navigator.platform));
201    d.isios4 = ((d.isios)&&!("seal" in Object));
202
203    d.isandroid = (/android/i.test(navigator.userAgent));
204
205    d.trstyle = false;
206    d.hastransform = false;
207    d.hastranslate3d = false;
208    d.transitionstyle = false;
209    d.hastransition = false;
210    d.transitionend = false;
211
212    var check = ['transform','msTransform','webkitTransform','MozTransform','OTransform'];
213    for(var a=0;a<check.length;a++){
214      if (typeof domtest.style[check[a]] != "undefined") {
215        d.trstyle = check[a];
216        break;
217      }
218    }
219    d.hastransform = (d.trstyle != false);
220    if (d.hastransform) {
221      domtest.style[d.trstyle] = "translate3d(1px,2px,3px)";
222      d.hastranslate3d = /translate3d/.test(domtest.style[d.trstyle]);
223    }
224
225    d.transitionstyle = false;
226    d.prefixstyle = '';
227    d.transitionend = false;
228    var check = ['transition','webkitTransition','MozTransition','OTransition','OTransition','msTransition','KhtmlTransition'];
229    var prefix = ['','-webkit-','-moz-','-o-','-o','-ms-','-khtml-'];
230    var evs = ['transitionend','webkitTransitionEnd','transitionend','otransitionend','oTransitionEnd','msTransitionEnd','KhtmlTransitionEnd'];
231    for(var a=0;a<check.length;a++) {
232      if (check[a] in domtest.style) {
233        d.transitionstyle = check[a];
234        d.prefixstyle = prefix[a];
235        d.transitionend = evs[a];
236        break;
237      }
238    }
239    if (d.ischrome26) {  // use always prefix
240      d.prefixstyle = prefix[1];
241    }
242
243    d.hastransition = (d.transitionstyle);
244
245    function detectCursorGrab() {
246      var lst = ['-moz-grab','-webkit-grab','grab'];
247      if ((d.ischrome&&!d.ischrome22)||d.isie) lst=[];  // force setting for IE returns false positive and chrome cursor bug
248      for(var a=0;a<lst.length;a++) {
249        var p = lst[a];
250        domtest.style['cursor']=p;
251        if (domtest.style['cursor']==p) return p;
252      }
253      return 'url(http://www.google.com/intl/en_ALL/mapfiles/openhand.cur),n-resize';  // thank you google for custom cursor!
254    }
255    d.cursorgrabvalue = detectCursorGrab();
256
257    d.hasmousecapture = ("setCapture" in domtest);
258
259    d.hasMutationObserver = (clsMutationObserver !== false);
260
261    domtest = null;  //memory released
262
263    browserdetected = d;
264
265    return d;
266  }
267
268  var NiceScrollClass = function(myopt,me) {
269
270    var self = this;
271
272    this.version = '3.5.0 BETA5';
273    this.name = 'nicescroll';
274
275    this.me = me;
276
277    this.opt = {
278      doc:$("body"),
279      win:false
280    };
281
282    $.extend(this.opt,_globaloptions);
283
284// Options for internal use
285    this.opt.snapbackspeed = 80;
286
287    if (myopt||false) {
288      for(var a in self.opt) {
289        if (typeof myopt[a] != "undefined") self.opt[a] = myopt[a];
290      }
291    }
292
293    this.doc = self.opt.doc;
294    this.iddoc = (this.doc&&this.doc[0])?this.doc[0].id||'':'';
295    this.ispage = /BODY|HTML/.test((self.opt.win)?self.opt.win[0].nodeName:this.doc[0].nodeName);
296    this.haswrapper = (self.opt.win!==false);
297    this.win = self.opt.win||(this.ispage?$(window):this.doc);
298    this.docscroll = (this.ispage&&!this.haswrapper)?$(window):this.win;
299    this.body = $("body");
300    this.viewport = false;
301
302    this.isfixed = false;
303
304    this.iframe = false;
305    this.isiframe = ((this.doc[0].nodeName == 'IFRAME') && (this.win[0].nodeName == 'IFRAME'));
306
307    this.istextarea = (this.win[0].nodeName == 'TEXTAREA');
308
309    this.forcescreen = false; //force to use screen position on events
310
311    this.canshowonmouseevent = (self.opt.autohidemode!="scroll");
312
313// Events jump table
314    this.onmousedown = false;
315    this.onmouseup = false;
316    this.onmousemove = false;
317    this.onmousewheel = false;
318    this.onkeypress = false;
319    this.ongesturezoom = false;
320    this.onclick = false;
321
322// Nicescroll custom events
323    this.onscrollstart = false;
324    this.onscrollend = false;
325    this.onscrollcancel = false;
326
327    this.onzoomin = false;
328    this.onzoomout = false;
329
330// Let's start!
331    this.view = false;
332    this.page = false;
333
334    this.scroll = {x:0,y:0};
335    this.scrollratio = {x:0,y:0};
336    this.cursorheight = 20;
337    this.scrollvaluemax = 0;
338
339    this.checkrtlmode = false;
340
341    this.scrollrunning = false;
342
343    this.scrollmom = false;
344
345    this.observer = false;
346    this.observerremover = false;  // observer on parent for remove detection
347
348    do {
349      this.id = "ascrail"+(ascrailcounter++);
350    } while (document.getElementById(this.id));
351
352    this.rail = false;
353    this.cursor = false;
354    this.cursorfreezed = false;
355    this.selectiondrag = false;
356
357    this.zoom = false;
358    this.zoomactive = false;
359
360    this.hasfocus = false;
361    this.hasmousefocus = false;
362
363    this.visibility = true;
364    this.locked = false;
365    this.hidden = false; // rails always hidden
366    this.cursoractive = true; // user can interact with cursors
367
368    this.overflowx = self.opt.overflowx;
369    this.overflowy = self.opt.overflowy;
370
371    this.nativescrollingarea = false;
372    this.checkarea = 0;
373
374    this.events = [];  // event list for unbind
375
376    this.saved = {};
377
378    this.delaylist = {};
379    this.synclist = {};
380
381    this.lastdeltax = 0;
382    this.lastdeltay = 0;
383
384    this.detected = getBrowserDetection();
385
386    var cap = $.extend({},this.detected);
387
388    this.canhwscroll = (cap.hastransform&&self.opt.hwacceleration);
389    this.ishwscroll = (this.canhwscroll&&self.haswrapper);
390
391    this.istouchcapable = false;  // desktop devices with touch screen support
392
393//## Check Chrome desktop with touch support
394    if (cap.cantouch&&cap.ischrome&&!cap.isios&&!cap.isandroid) {
395      this.istouchcapable = true;
396      cap.cantouch = false;  // parse normal desktop events
397    }
398
399//## Firefox 18 nightly build (desktop) false positive (or desktop with touch support)
400    if (cap.cantouch&&cap.ismozilla&&!cap.isios&&!cap.isandroid) {
401      this.istouchcapable = true;
402      cap.cantouch = false;  // parse normal desktop events
403    }
404
405//## disable MouseLock API on user request
406
407    if (!self.opt.enablemouselockapi) {
408      cap.hasmousecapture = false;
409      cap.haspointerlock = false;
410    }
411
412    this.delayed = function(name,fn,tm,lazy) {
413      var dd = self.delaylist[name];
414      var nw = (new Date()).getTime();
415      if (!lazy&&dd&&dd.tt) return false;
416      if (dd&&dd.tt) clearTimeout(dd.tt);
417      if (dd&&dd.last+tm>nw&&!dd.tt) {
418        self.delaylist[name] = {
419          last:nw+tm,
420          tt:setTimeout(function(){self.delaylist[name].tt=0;fn.call();},tm)
421        }
422      }
423      else if (!dd||!dd.tt) {
424        self.delaylist[name] = {
425          last:nw,
426          tt:0
427        }
428        setTimeout(function(){fn.call();},0);
429      }
430    };
431
432    this.debounced = function(name,fn,tm) {
433      var dd = self.delaylist[name];
434      var nw = (new Date()).getTime();
435      self.delaylist[name] = fn;
436      if (!dd) {
437        setTimeout(function(){var fn=self.delaylist[name];self.delaylist[name]=false;fn.call();},tm);
438      }
439    }
440
441    this.synched = function(name,fn) {
442
443      function requestSync() {
444        if (self.onsync) return;
445        setAnimationFrame(function(){
446          self.onsync = false;
447          for(name in self.synclist){
448            var fn = self.synclist[name];
449            if (fn) fn.call(self);
450            self.synclist[name] = false;
451          }
452        });
453        self.onsync = true;
454      };
455
456      self.synclist[name] = fn;
457      requestSync();
458      return name;
459    };
460
461    this.unsynched = function(name) {
462      if (self.synclist[name]) self.synclist[name] = false;
463    }
464
465    this.css = function(el,pars) {  // save & set
466      for(var n in pars) {
467        self.saved.css.push([el,n,el.css(n)]);
468        el.css(n,pars[n]);
469      }
470    };
471
472    this.scrollTop = function(val) {
473      return (typeof val == "undefined") ? self.getScrollTop() : self.setScrollTop(val);
474    };
475
476    this.scrollLeft = function(val) {
477      return (typeof val == "undefined") ? self.getScrollLeft() : self.setScrollLeft(val);
478    };
479
480// derived by by Dan Pupius www.pupius.net
481    BezierClass = function(st,ed,spd,p1,p2,p3,p4) {
482      this.st = st;
483      this.ed = ed;
484      this.spd = spd;
485
486      this.p1 = p1||0;
487      this.p2 = p2||1;
488      this.p3 = p3||0;
489      this.p4 = p4||1;
490
491      this.ts = (new Date()).getTime();
492      this.df = this.ed-this.st;
493    };
494    BezierClass.prototype = {
495      B2:function(t){ return 3*t*t*(1-t) },
496      B3:function(t){ return 3*t*(1-t)*(1-t) },
497      B4:function(t){ return (1-t)*(1-t)*(1-t) },
498      getNow:function(){
499        var nw = (new Date()).getTime();
500        var pc = 1-((nw-this.ts)/this.spd);
501        var bz = this.B2(pc) + this.B3(pc) + this.B4(pc);
502        return (pc<0) ? this.ed : this.st+Math.round(this.df*bz);
503      },
504      update:function(ed,spd){
505        this.st = this.getNow();
506        this.ed = ed;
507        this.spd = spd;
508        this.ts = (new Date()).getTime();
509        this.df = this.ed-this.st;
510        return this;
511      }
512    };
513
514    if (this.ishwscroll) {
515    // hw accelerated scroll
516      this.doc.translate = {x:0,y:0,tx:"0px",ty:"0px"};
517
518      //this one can help to enable hw accel on ios6 http://indiegamr.com/ios6-html-hardware-acceleration-changes-and-how-to-fix-them/
519      if (cap.hastranslate3d&&cap.isios) this.doc.css("-webkit-backface-visibility","hidden");  // prevent flickering http://stackoverflow.com/questions/3461441/
520
521      //derived from http://stackoverflow.com/questions/11236090/
522      function getMatrixValues() {
523        var tr = self.doc.css(cap.trstyle);
524        if (tr&&(tr.substr(0,6)=="matrix")) {
525          return tr.replace(/^.*\((.*)\)$/g, "$1").replace(/px/g,'').split(/, +/);
526        }
527        return false;
528      }
529
530      this.getScrollTop = function(last) {
531        if (!last) {
532          var mtx = getMatrixValues();
533          if (mtx) return (mtx.length==16) ? -mtx[13] : -mtx[5];  //matrix3d 16 on IE10
534          if (self.timerscroll&&self.timerscroll.bz) return self.timerscroll.bz.getNow();
535        }
536        return self.doc.translate.y;
537      };
538
539      this.getScrollLeft = function(last) {
540        if (!last) {
541          var mtx = getMatrixValues();
542          if (mtx) return (mtx.length==16) ? -mtx[12] : -mtx[4];  //matrix3d 16 on IE10
543          if (self.timerscroll&&self.timerscroll.bh) return self.timerscroll.bh.getNow();
544        }
545        return self.doc.translate.x;
546      };
547
548      if (document.createEvent) {
549        this.notifyScrollEvent = function(el) {
550          var e = document.createEvent("UIEvents");
551          e.initUIEvent("scroll", false, true, window, 1);
552          el.dispatchEvent(e);
553        };
554      }
555      else if (document.fireEvent) {
556        this.notifyScrollEvent = function(el) {
557          var e = document.createEventObject();
558          el.fireEvent("onscroll");
559          e.cancelBubble = true;
560        };
561      }
562      else {
563        this.notifyScrollEvent = function(el,add) {}; //NOPE
564      }
565
566      if (cap.hastranslate3d&&self.opt.enabletranslate3d) {
567        this.setScrollTop = function(val,silent) {
568          self.doc.translate.y = val;
569          self.doc.translate.ty = (val*-1)+"px";
570          self.doc.css(cap.trstyle,"translate3d("+self.doc.translate.tx+","+self.doc.translate.ty+",0px)");
571          if (!silent) self.notifyScrollEvent(self.win[0]);
572        };
573        this.setScrollLeft = function(val,silent) {
574          self.doc.translate.x = val;
575          self.doc.translate.tx = (val*-1)+"px";
576          self.doc.css(cap.trstyle,"translate3d("+self.doc.translate.tx+","+self.doc.translate.ty+",0px)");
577          if (!silent) self.notifyScrollEvent(self.win[0]);
578        };
579      } else {
580        this.setScrollTop = function(val,silent) {
581          self.doc.translate.y = val;
582          self.doc.translate.ty = (val*-1)+"px";
583          self.doc.css(cap.trstyle,"translate("+self.doc.translate.tx+","+self.doc.translate.ty+")");
584          if (!silent) self.notifyScrollEvent(self.win[0]);
585        };
586        this.setScrollLeft = function(val,silent) {
587          self.doc.translate.x = val;
588          self.doc.translate.tx = (val*-1)+"px";
589          self.doc.css(cap.trstyle,"translate("+self.doc.translate.tx+","+self.doc.translate.ty+")");
590          if (!silent) self.notifyScrollEvent(self.win[0]);
591        };
592      }
593    } else {
594    // native scroll
595      this.getScrollTop = function() {
596        return self.docscroll.scrollTop();
597      };
598      this.setScrollTop = function(val) {
599        return self.docscroll.scrollTop(val);
600      };
601      this.getScrollLeft = function() {
602        return self.docscroll.scrollLeft();
603      };
604      this.setScrollLeft = function(val) {
605        return self.docscroll.scrollLeft(val);
606      };
607    }
608
609    this.getTarget = function(e) {
610      if (!e) return false;
611      if (e.target) return e.target;
612      if (e.srcElement) return e.srcElement;
613      return false;
614    };
615
616    this.hasParent = function(e,id) {
617      if (!e) return false;
618      var el = e.target||e.srcElement||e||false;
619      while (el && el.id != id) {
620        el = el.parentNode||false;
621      }
622      return (el!==false);
623    };
624
625    function getZIndex() {
626      var dom = self.win;
627      if ("zIndex" in dom) return dom.zIndex();  // use jQuery UI method when available
628      while (dom.length>0) {
629        if (dom[0].nodeType==9) return false;
630        var zi = dom.css('zIndex');
631        if (!isNaN(zi)&&zi!=0) return parseInt(zi);
632        dom = dom.parent();
633      }
634      return false;
635    };
636
637//inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie
638    var _convertBorderWidth = {"thin":1,"medium":3,"thick":5};
639    function getWidthToPixel(dom,prop,chkheight) {
640      var wd = dom.css(prop);
641      var px = parseFloat(wd);
642      if (isNaN(px)) {
643        px = _convertBorderWidth[wd]||0;
644        var brd = (px==3) ? ((chkheight)?(self.win.outerHeight() - self.win.innerHeight()):(self.win.outerWidth() - self.win.innerWidth())) : 1; //DON'T TRUST CSS
645        if (self.isie8&&px) px+=1;
646        return (brd) ? px : 0;
647      }
648      return px;
649    };
650
651    this.getOffset = function() {
652      if (self.isfixed) return {top:parseFloat(self.win.css('top')),left:parseFloat(self.win.css('left'))};
653      if (!self.viewport) return self.win.offset();
654      var ww = self.win.offset();
655      var vp = self.viewport.offset();
656      return {top:ww.top-vp.top+self.viewport.scrollTop(),left:ww.left-vp.left+self.viewport.scrollLeft()};
657    };
658
659    this.updateScrollBar = function(len) {
660      if (self.ishwscroll) {
661        self.rail.css({height:self.win.innerHeight()});
662        if (self.railh) self.railh.css({width:self.win.innerWidth()});
663      } else {
664        var wpos = self.getOffset();
665        var pos = {top:wpos.top,left:wpos.left};
666        pos.top+= getWidthToPixel(self.win,'border-top-width',true);
667        var brd = (self.win.outerWidth() - self.win.innerWidth())/2;
668        pos.left+= (self.rail.align) ? self.win.outerWidth() - getWidthToPixel(self.win,'border-right-width') - self.rail.width : getWidthToPixel(self.win,'border-left-width');
669
670        var off = self.opt.railoffset;
671        if (off) {
672          if (off.top) pos.top+=off.top;
673          if (self.rail.align&&off.left) pos.left+=off.left;
674        }
675
676				if (!self.locked) self.rail.css({top:pos.top,left:pos.left,height:(len)?len.h:self.win.innerHeight()});
677
678				if (self.zoom) {
679				  self.zoom.css({top:pos.top+1,left:(self.rail.align==1) ? pos.left-20 : pos.left+self.rail.width+4});
680			  }
681
682				if (self.railh&&!self.locked) {
683					var pos = {top:wpos.top,left:wpos.left};
684					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);
685					var x = pos.left + getWidthToPixel(self.win,'border-left-width');
686					self.railh.css({top:y,left:x,width:self.railh.width});
687				}
688
689
690      }
691    };
692
693    this.doRailClick = function(e,dbl,hr) {
694
695      var fn,pg,cur,pos;
696
697//      if (self.rail.drag&&self.rail.drag.pt!=1) return;
698      if (self.locked) return;
699//      if (self.rail.drag) return;
700
701//      self.cancelScroll();
702
703      self.cancelEvent(e);
704
705      if (dbl) {
706        fn = (hr) ? self.doScrollLeft : self.doScrollTop;
707        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);
708        fn(cur);
709      } else {
710//        console.log(e.pageY);
711        fn = (hr) ? self.doScrollLeftBy : self.doScrollBy;
712        cur = (hr) ? self.scroll.x : self.scroll.y;
713        pos = (hr) ? e.pageX - self.railh.offset().left : e.pageY - self.rail.offset().top;
714        pg = (hr) ? self.view.w : self.view.h;
715        (cur>=pos) ? fn(pg) : fn(-pg);
716      }
717
718    }
719
720    self.hasanimationframe = (setAnimationFrame);
721    self.hascancelanimationframe = (clearAnimationFrame);
722
723    if (!self.hasanimationframe) {
724      setAnimationFrame=function(fn){return setTimeout(fn,15-Math.floor((+new Date)/1000)%16)}; // 1000/60)};
725      clearAnimationFrame=clearInterval;
726    }
727    else if (!self.hascancelanimationframe) clearAnimationFrame=function(){self.cancelAnimationFrame=true};
728
729    this.init = function() {
730
731      self.saved.css = [];
732
733      if (cap.isie7mobile) return true; // SORRY, DO NOT WORK!
734      if (cap.isoperamini) return true; // SORRY, DO NOT WORK!
735
736      if (cap.hasmstouch) self.css((self.ispage)?$("html"):self.win,{'-ms-touch-action':'none'});
737
738      self.zindex = "auto";
739      if (!self.ispage&&self.opt.zindex=="auto") {
740        self.zindex = getZIndex()||"auto";
741      } else {
742        self.zindex = self.opt.zindex;
743      }
744
745      if (!self.ispage&&self.zindex!="auto") {
746        if (self.zindex>globalmaxzindex) globalmaxzindex=self.zindex;
747      }
748
749      if (self.isie&&self.zindex==0&&self.opt.zindex=="auto") {  // fix IE auto == 0
750        self.zindex="auto";
751      }
752
753/*
754      self.ispage = true;
755      self.haswrapper = true;
756//      self.win = $(window);
757      self.docscroll = $("body");
758//      self.doc = $("body");
759*/
760
761      if (!self.ispage || (!cap.cantouch && !cap.isieold && !cap.isie9mobile)) {
762
763        var cont = self.docscroll;
764        if (self.ispage) cont = (self.haswrapper)?self.win:self.doc;
765
766        if (!cap.isie9mobile) self.css(cont,{'overflow-y':'hidden'});
767
768        if (self.ispage&&cap.isie7) {
769          if (self.doc[0].nodeName=='BODY') self.css($("html"),{'overflow-y':'hidden'});  //IE7 double scrollbar issue
770          else if (self.doc[0].nodeName=='HTML') self.css($("body"),{'overflow-y':'hidden'});  //IE7 double scrollbar issue
771        }
772
773        if (cap.isios&&!self.ispage&&!self.haswrapper) self.css($("body"),{"-webkit-overflow-scrolling":"touch"});  //force hw acceleration
774
775        var cursor = $(document.createElement('div'));
776        cursor.css({
777          position:"relative",top:0,"float":"right",width:self.opt.cursorwidth,height:"0px",
778          'background-color':self.opt.cursorcolor,
779          border:self.opt.cursorborder,
780          'background-clip':'padding-box',
781          '-webkit-border-radius':self.opt.cursorborderradius,
782          '-moz-border-radius':self.opt.cursorborderradius,
783          'border-radius':self.opt.cursorborderradius
784        });
785
786        cursor.hborder = parseFloat(cursor.outerHeight() - cursor.innerHeight());
787        self.cursor = cursor;
788
789        var rail = $(document.createElement('div'));
790        rail.attr('id',self.id);
791        rail.addClass('nicescroll-rails');
792
793        var v,a,kp = ["left","right"];  //"top","bottom"
794        for(var n in kp) {
795          a=kp[n];
796          v = self.opt.railpadding[a];
797          (v) ? rail.css("padding-"+a,v+"px") : self.opt.railpadding[a] = 0;
798        }
799
800        rail.append(cursor);
801
802        rail.width = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerWidth()) + self.opt.railpadding['left'] + self.opt.railpadding['right'];
803        rail.css({width:rail.width+"px",'zIndex':self.zindex,"background":self.opt.background,cursor:"default"});
804
805        rail.visibility = true;
806        rail.scrollable = true;
807
808        rail.align = (self.opt.railalign=="left") ? 0 : 1;
809
810        self.rail = rail;
811
812        self.rail.drag = false;
813
814        var zoom = false;
815        if (self.opt.boxzoom&&!self.ispage&&!cap.isieold) {
816          zoom = document.createElement('div');
817          self.bind(zoom,"click",self.doZoom);
818          self.zoom = $(zoom);
819          self.zoom.css({"cursor":"pointer",'z-index':self.zindex,'backgroundImage':'url('+scriptpath+'zoomico.png)','height':18,'width':18,'backgroundPosition':'0px 0px'});
820          if (self.opt.dblclickzoom) self.bind(self.win,"dblclick",self.doZoom);
821          if (cap.cantouch&&self.opt.gesturezoom) {
822            self.ongesturezoom = function(e) {
823              if (e.scale>1.5) self.doZoomIn(e);
824              if (e.scale<0.8) self.doZoomOut(e);
825              return self.cancelEvent(e);
826            };
827            self.bind(self.win,"gestureend",self.ongesturezoom);
828          }
829        }
830
831// init HORIZ
832
833        self.railh = false;
834
835        if (self.opt.horizrailenabled) {
836
837          self.css(cont,{'overflow-x':'hidden'});
838
839          var cursor = $(document.createElement('div'));
840          cursor.css({
841            position:"relative",top:0,height:self.opt.cursorwidth,width:"0px",
842            'background-color':self.opt.cursorcolor,
843            border:self.opt.cursorborder,
844            'background-clip':'padding-box',
845            '-webkit-border-radius':self.opt.cursorborderradius,
846            '-moz-border-radius':self.opt.cursorborderradius,
847            'border-radius':self.opt.cursorborderradius
848          });
849
850          cursor.wborder = parseFloat(cursor.outerWidth() - cursor.innerWidth());
851          self.cursorh = cursor;
852
853          var railh = $(document.createElement('div'));
854          railh.attr('id',self.id+'-hr');
855          railh.addClass('nicescroll-rails');
856          railh.height = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerHeight());
857          railh.css({height:railh.height+"px",'zIndex':self.zindex,"background":self.opt.background});
858
859          railh.append(cursor);
860
861          railh.visibility = true;
862          railh.scrollable = true;
863
864          railh.align = (self.opt.railvalign=="top") ? 0 : 1;
865
866          self.railh = railh;
867
868          self.railh.drag = false;
869
870        }
871
872//
873
874        if (self.ispage) {
875          rail.css({position:"fixed",top:"0px",height:"100%"});
876          (rail.align) ? rail.css({right:"0px"}) : rail.css({left:"0px"});
877          self.body.append(rail);
878          if (self.railh) {
879            railh.css({position:"fixed",left:"0px",width:"100%"});
880            (railh.align) ? railh.css({bottom:"0px"}) : railh.css({top:"0px"});
881            self.body.append(railh);
882          }
883        } else {
884          if (self.ishwscroll) {
885            if (self.win.css('position')=='static') self.css(self.win,{'position':'relative'});
886            var bd = (self.win[0].nodeName == 'HTML') ? self.body : self.win;
887            if (self.zoom) {
888              self.zoom.css({position:"absolute",top:1,right:0,"margin-right":rail.width+4});
889              bd.append(self.zoom);
890            }
891            rail.css({position:"absolute",top:0});
892            (rail.align) ? rail.css({right:0}) : rail.css({left:0});
893            bd.append(rail);
894            if (railh) {
895              railh.css({position:"absolute",left:0,bottom:0});
896              (railh.align) ? railh.css({bottom:0}) : railh.css({top:0});
897              bd.append(railh);
898            }
899          } else {
900            self.isfixed = (self.win.css("position")=="fixed");
901            var rlpos = (self.isfixed) ? "fixed" : "absolute";
902
903            if (!self.isfixed) self.viewport = self.getViewport(self.win[0]);
904            if (self.viewport) {
905              self.body = self.viewport;
906              if ((/relative|absolute/.test(self.viewport.css("position")))==false) self.css(self.viewport,{"position":"relative"});
907            }
908
909            rail.css({position:rlpos});
910            if (self.zoom) self.zoom.css({position:rlpos});
911            self.updateScrollBar();
912            self.body.append(rail);
913            if (self.zoom) self.body.append(self.zoom);
914            if (self.railh) {
915              railh.css({position:rlpos});
916              self.body.append(railh);
917            }
918          }
919
920          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
921
922					if (cap.isie&&self.opt.disableoutline) self.win.attr("hideFocus","true");  // IE, prevent dotted rectangle on focused div
923					if (cap.iswebkit&&self.opt.disableoutline) self.win.css({"outline":"none"});
924//          if (cap.isopera&&self.opt.disableoutline) self.win.css({"outline":"0"});  // Opera to test [TODO]
925
926        }
927
928        if (self.opt.autohidemode===false) {
929          self.autohidedom = false;
930          self.rail.css({opacity:self.opt.cursoropacitymax});
931          if (self.railh) self.railh.css({opacity:self.opt.cursoropacitymax});
932        }
933        else if (self.opt.autohidemode===true) {
934          self.autohidedom = $().add(self.rail);
935          if (cap.isie8) self.autohidedom=self.autohidedom.add(self.cursor);
936          if (self.railh) self.autohidedom=self.autohidedom.add(self.railh);
937          if (self.railh&&cap.isie8) self.autohidedom=self.autohidedom.add(self.cursorh);
938        }
939        else if (self.opt.autohidemode=="scroll") {
940          self.autohidedom = $().add(self.rail);
941          if (self.railh) self.autohidedom=self.autohidedom.add(self.railh);
942        }
943        else if (self.opt.autohidemode=="cursor") {
944          self.autohidedom = $().add(self.cursor);
945          if (self.railh) self.autohidedom=self.autohidedom.add(self.cursorh);
946        }
947        else if (self.opt.autohidemode=="hidden") {
948          self.autohidedom = false;
949          self.hide();
950          self.locked = false;
951        }
952
953        if (cap.isie9mobile) {
954
955          self.scrollmom = new ScrollMomentumClass2D(self);
956
957          /*
958          var trace = function(msg) {
959            var db = $("#debug");
960            if (isNaN(msg)&&(typeof msg != "string")) {
961              var x = [];
962              for(var a in msg) {
963                x.push(a+":"+msg[a]);
964              }
965              msg ="{"+x.join(",")+"}";
966            }
967            if (db.children().length>0) {
968              db.children().eq(0).before("<div>"+msg+"</div>");
969            } else {
970              db.append("<div>"+msg+"</div>");
971            }
972          }
973          window.onerror = function(msg,url,ln) {
974            trace("ERR: "+msg+" at "+ln);
975          }
976*/
977
978          self.onmangotouch = function(e) {
979            var py = self.getScrollTop();
980            var px = self.getScrollLeft();
981
982            if ((py == self.scrollmom.lastscrolly)&&(px == self.scrollmom.lastscrollx)) return true;
983//            $("#debug").html('DRAG:'+py);
984
985            var dfy = py-self.mangotouch.sy;
986            var dfx = px-self.mangotouch.sx;
987            var df = Math.round(Math.sqrt(Math.pow(dfx,2)+Math.pow(dfy,2)));
988            if (df==0) return;
989
990            var dry = (dfy<0)?-1:1;
991            var drx = (dfx<0)?-1:1;
992
993            var tm = +new Date();
994            if (self.mangotouch.lazy) clearTimeout(self.mangotouch.lazy);
995
996            if (((tm-self.mangotouch.tm)>80)||(self.mangotouch.dry!=dry)||(self.mangotouch.drx!=drx)) {
997//              trace('RESET+'+(tm-self.mangotouch.tm));
998              self.scrollmom.stop();
999              self.scrollmom.reset(px,py);
1000              self.mangotouch.sy = py;
1001              self.mangotouch.ly = py;
1002              self.mangotouch.sx = px;
1003              self.mangotouch.lx = px;
1004              self.mangotouch.dry = dry;
1005              self.mangotouch.drx = drx;
1006              self.mangotouch.tm = tm;
1007            } else {
1008
1009              self.scrollmom.stop();
1010              self.scrollmom.update(self.mangotouch.sx-dfx,self.mangotouch.sy-dfy);
1011              var gap = tm - self.mangotouch.tm;
1012              self.mangotouch.tm = tm;
1013
1014//              trace('MOVE:'+df+" - "+gap);
1015
1016              var ds = Math.max(Math.abs(self.mangotouch.ly-py),Math.abs(self.mangotouch.lx-px));
1017              self.mangotouch.ly = py;
1018              self.mangotouch.lx = px;
1019
1020              if (ds>2) {
1021                self.mangotouch.lazy = setTimeout(function(){
1022//                  trace('END:'+ds+'+'+gap);
1023                  self.mangotouch.lazy = false;
1024                  self.mangotouch.dry = 0;
1025                  self.mangotouch.drx = 0;
1026                  self.mangotouch.tm = 0;
1027                  self.scrollmom.doMomentum(30);
1028                },100);
1029              }
1030            }
1031          }
1032
1033          var top = self.getScrollTop();
1034          var lef = self.getScrollLeft();
1035          self.mangotouch = {sy:top,ly:top,dry:0,sx:lef,lx:lef,drx:0,lazy:false,tm:0};
1036
1037          self.bind(self.docscroll,"scroll",self.onmangotouch);
1038
1039        } else {
1040
1041          if (cap.cantouch||self.istouchcapable||self.opt.touchbehavior||cap.hasmstouch) {
1042
1043            self.scrollmom = new ScrollMomentumClass2D(self);
1044
1045            self.ontouchstart = function(e) {
1046              if (e.pointerType&&e.pointerType!=2) return false;
1047
1048              if (!self.locked) {
1049
1050                if (cap.hasmstouch) {
1051                  var tg = (e.target) ? e.target : false;
1052                  while (tg) {
1053                    var nc = $(tg).getNiceScroll();
1054                    if ((nc.length>0)&&(nc[0].me == self.me)) break;
1055                    if (nc.length>0) return false;
1056                    if ((tg.nodeName=='DIV')&&(tg.id==self.id)) break;
1057                    tg = (tg.parentNode) ? tg.parentNode : false;
1058                  }
1059                }
1060
1061                self.cancelScroll();
1062
1063                var tg = self.getTarget(e);
1064
1065                if (tg) {
1066                  var skp = (/INPUT/i.test(tg.nodeName))&&(/range/i.test(tg.type));
1067                  if (skp) return self.stopPropagation(e);
1068                }
1069
1070                if (!("clientX" in e) && ("changedTouches" in e)) {
1071                  e.clientX = e.changedTouches[0].clientX;
1072                  e.clientY = e.changedTouches[0].clientY;
1073                }
1074
1075                if (self.forcescreen) {
1076                  var le = e;
1077                  var e = {"original":(e.original)?e.original:e};
1078                  e.clientX = le.screenX;
1079                  e.clientY = le.screenY;
1080                }
1081
1082                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};
1083
1084                if (self.ispage||!self.opt.directionlockdeadzone) {
1085                  self.rail.drag.dl = "f";
1086                } else {
1087
1088                  var view = {
1089                    w:$(window).width(),
1090                    h:$(window).height()
1091                  };
1092
1093                  var page = {
1094                    w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
1095                    h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
1096                  }
1097
1098                  var maxh = Math.max(0,page.h - view.h);
1099                  var maxw = Math.max(0,page.w - view.w);
1100
1101                  if (!self.rail.scrollable&&self.railh.scrollable) self.rail.drag.ck = (maxh>0) ? "v" : false;
1102                  else if (self.rail.scrollable&&!self.railh.scrollable) self.rail.drag.ck = (maxw>0) ? "h" : false;
1103                  else self.rail.drag.ck = false;
1104                  if (!self.rail.drag.ck) self.rail.drag.dl = "f";
1105                }
1106
1107                if (self.opt.touchbehavior&&self.isiframe&&cap.isie) {
1108                  var wp = self.win.position();
1109                  self.rail.drag.x+=wp.left;
1110                  self.rail.drag.y+=wp.top;
1111                }
1112
1113                self.hasmoving = false;
1114                self.lastmouseup = false;
1115                self.scrollmom.reset(e.clientX,e.clientY);
1116                if (!cap.cantouch&&!this.istouchcapable&&!cap.hasmstouch) {
1117
1118                  var ip = (tg)?/INPUT|SELECT|TEXTAREA/i.test(tg.nodeName):false;
1119                  if (!ip) {
1120                    if (!self.ispage&&cap.hasmousecapture) tg.setCapture();
1121//                  return self.cancelEvent(e);
1122                    return (self.opt.touchbehavior) ? self.cancelEvent(e) : self.stopPropagation(e);
1123                  }
1124                  if (/SUBMIT|CANCEL|BUTTON/i.test($(tg).attr('type'))) {
1125                    pc = {"tg":tg,"click":false};
1126                    self.preventclick = pc;
1127                  }
1128
1129                }
1130              }
1131
1132            };
1133
1134            self.ontouchend = function(e) {
1135              if (e.pointerType&&e.pointerType!=2) return false;
1136              if (self.rail.drag&&(self.rail.drag.pt==2)) {
1137                self.scrollmom.doMomentum();
1138                self.rail.drag = false;
1139                if (self.hasmoving) {
1140                  self.hasmoving = false;
1141                  self.lastmouseup = true;
1142                  self.hideCursor();
1143                  if (cap.hasmousecapture) document.releaseCapture();
1144                  if (!cap.cantouch) return self.cancelEvent(e);
1145                }
1146              }
1147
1148            };
1149
1150            var moveneedoffset = (self.opt.touchbehavior&&self.isiframe&&!cap.hasmousecapture);
1151
1152            self.ontouchmove = function(e,byiframe) {
1153
1154              if (e.pointerType&&e.pointerType!=2) return false;
1155
1156              if (self.rail.drag&&(self.rail.drag.pt==2)) {
1157                if (cap.cantouch&&(typeof e.original == "undefined")) return true;  // prevent ios "ghost" events by clickable elements
1158
1159                self.hasmoving = true;
1160
1161                if (self.preventclick&&!self.preventclick.click) {
1162                  self.preventclick.click = self.preventclick.tg.onclick||false;
1163                  self.preventclick.tg.onclick = self.onpreventclick;
1164                }
1165
1166                var ev = $.extend({"original":e},e);
1167                e = ev;
1168
1169                if (("changedTouches" in e)) {
1170                  e.clientX = e.changedTouches[0].clientX;
1171                  e.clientY = e.changedTouches[0].clientY;
1172                }
1173
1174                if (self.forcescreen) {
1175                  var le = e;
1176                  var e = {"original":(e.original)?e.original:e};
1177                  e.clientX = le.screenX;
1178                  e.clientY = le.screenY;
1179                }
1180
1181                var ofx = ofy = 0;
1182
1183                if (moveneedoffset&&!byiframe) {
1184                  var wp = self.win.position();
1185                  ofx=-wp.left;
1186                  ofy=-wp.top;
1187                }
1188
1189                var fy = e.clientY + ofy;
1190                var my = (fy-self.rail.drag.y);
1191                var fx = e.clientX + ofx;
1192                var mx = (fx-self.rail.drag.x);
1193
1194                var ny = self.rail.drag.st-my;
1195
1196                if (self.ishwscroll&&self.opt.bouncescroll) {
1197                  if (ny<0) {
1198                    ny = Math.round(ny/2);
1199//                    fy = 0;
1200                  }
1201                  else if (ny>self.page.maxh) {
1202                    ny = self.page.maxh+Math.round((ny-self.page.maxh)/2);
1203//                    fy = 0;
1204                  }
1205                } else {
1206                  if (ny<0) {ny=0;fy=0}
1207                  if (ny>self.page.maxh) {ny=self.page.maxh;fy=0}
1208                }
1209
1210                if (self.railh&&self.railh.scrollable) {
1211                  var nx = self.rail.drag.sl-mx;
1212
1213                  if (self.ishwscroll&&self.opt.bouncescroll) {
1214                    if (nx<0) {
1215                      nx = Math.round(nx/2);
1216//                      fx = 0;
1217                    }
1218                    else if (nx>self.page.maxw) {
1219                      nx = self.page.maxw+Math.round((nx-self.page.maxw)/2);
1220//                      fx = 0;
1221                    }
1222                  } else {
1223                    if (nx<0) {nx=0;fx=0}
1224                    if (nx>self.page.maxw) {nx=self.page.maxw;fx=0}
1225                  }
1226
1227                }
1228
1229                var grabbed = false;
1230                if (self.rail.drag.dl) {
1231                  grabbed = true;
1232                  if (self.rail.drag.dl=="v") nx = self.rail.drag.sl;
1233                  else if (self.rail.drag.dl=="h") ny = self.rail.drag.st;
1234                } else {
1235                  var ay = Math.abs(my);
1236                  var ax = Math.abs(mx);
1237                  var dz = self.opt.directionlockdeadzone;
1238                  if (self.rail.drag.ck=="v") {
1239                    if (ay>dz&&(ax<=(ay*0.3))) {
1240                      self.rail.drag = false;
1241                      return true;
1242                    }
1243                    else if (ax>dz) {
1244                      self.rail.drag.dl="f";
1245                      $("body").scrollTop($("body").scrollTop());  // stop iOS native scrolling (when active javascript has blocked)
1246                    }
1247                  }
1248                  else if (self.rail.drag.ck=="h") {
1249                    if (ax>dz&&(ay<=(ax*0.3))) {
1250                      self.rail.drag = false;
1251                      return true;
1252                    }
1253                    else if (ay>dz) {
1254                      self.rail.drag.dl="f";
1255                      $("body").scrollLeft($("body").scrollLeft());  // stop iOS native scrolling (when active javascript has blocked)
1256                    }
1257                  }
1258                }
1259
1260                self.synched("touchmove",function(){
1261                  if (self.rail.drag&&(self.rail.drag.pt==2)) {
1262                    if (self.prepareTransition) self.prepareTransition(0);
1263                    if (self.rail.scrollable) self.setScrollTop(ny);
1264                    self.scrollmom.update(fx,fy);
1265                    if (self.railh&&self.railh.scrollable) {
1266                      self.setScrollLeft(nx);
1267                      self.showCursor(ny,nx);
1268                    } else {
1269                      self.showCursor(ny);
1270                    }
1271                    if (cap.isie10) document.selection.clear();
1272                  }
1273                });
1274
1275                if (cap.ischrome&&self.istouchcapable) grabbed=false;  //chrome touch emulation doesn't like!
1276                if (grabbed) return self.cancelEvent(e);
1277              }
1278
1279            };
1280
1281          }
1282
1283          self.onmousedown = function(e,hronly) {
1284            if (self.rail.drag&&self.rail.drag.pt!=1) return;
1285            if (self.locked) return self.cancelEvent(e);
1286            self.cancelScroll();
1287            self.rail.drag = {x:e.clientX,y:e.clientY,sx:self.scroll.x,sy:self.scroll.y,pt:1,hr:(!!hronly)};
1288            var tg = self.getTarget(e);
1289            if (!self.ispage&&cap.hasmousecapture) tg.setCapture();
1290            if (self.isiframe&&!cap.hasmousecapture) {
1291              self.saved["csspointerevents"] = self.doc.css("pointer-events");
1292              self.css(self.doc,{"pointer-events":"none"});
1293            }
1294            return self.cancelEvent(e);
1295          };
1296
1297          self.onmouseup = function(e) {
1298            if (self.rail.drag) {
1299              if (cap.hasmousecapture) document.releaseCapture();
1300              if (self.isiframe&&!cap.hasmousecapture) self.doc.css("pointer-events",self.saved["csspointerevents"]);
1301              if(self.rail.drag.pt!=1)return;
1302              self.rail.drag = false;
1303              //if (!self.rail.active) self.hideCursor();
1304              return self.cancelEvent(e);
1305            }
1306          };
1307
1308          self.onmousemove = function(e) {
1309            if (self.rail.drag) {
1310              if(self.rail.drag.pt!=1)return;
1311
1312              if (cap.ischrome&&e.which==0) return self.onmouseup(e);
1313
1314              self.cursorfreezed = true;
1315
1316              if (self.rail.drag.hr) {
1317                self.scroll.x = self.rail.drag.sx + (e.clientX-self.rail.drag.x);
1318                if (self.scroll.x<0) self.scroll.x=0;
1319                var mw = self.scrollvaluemaxw;
1320                if (self.scroll.x>mw) self.scroll.x=mw;
1321              } else {
1322                self.scroll.y = self.rail.drag.sy + (e.clientY-self.rail.drag.y);
1323                if (self.scroll.y<0) self.scroll.y=0;
1324                var my = self.scrollvaluemax;
1325                if (self.scroll.y>my) self.scroll.y=my;
1326              }
1327
1328              self.synched('mousemove',function(){
1329                if (self.rail.drag&&(self.rail.drag.pt==1)) {
1330                  self.showCursor();
1331                  if (self.rail.drag.hr) self.doScrollLeft(Math.round(self.scroll.x*self.scrollratio.x),self.opt.cursordragspeed);
1332                  else self.doScrollTop(Math.round(self.scroll.y*self.scrollratio.y),self.opt.cursordragspeed);
1333                }
1334              });
1335
1336              return self.cancelEvent(e);
1337            }
1338/*
1339            else {
1340              self.checkarea = true;
1341            }
1342*/
1343          };
1344
1345          if (cap.cantouch||self.opt.touchbehavior) {
1346
1347            self.onpreventclick = function(e) {
1348              if (self.preventclick) {
1349                self.preventclick.tg.onclick = self.preventclick.click;
1350                self.preventclick = false;
1351                return self.cancelEvent(e);
1352              }
1353            }
1354
1355//            self.onmousedown = self.ontouchstart;
1356//            self.onmouseup = self.ontouchend;
1357//            self.onmousemove = self.ontouchmove;
1358
1359            self.bind(self.win,"mousedown",self.ontouchstart);  // control content dragging
1360
1361            self.onclick = (cap.isios) ? false : function(e) {
1362              if (self.lastmouseup) {
1363                self.lastmouseup = false;
1364                return self.cancelEvent(e);
1365              } else {
1366                return true;
1367              }
1368            };
1369
1370            if (self.opt.grabcursorenabled&&cap.cursorgrabvalue) {
1371              self.css((self.ispage)?self.doc:self.win,{'cursor':cap.cursorgrabvalue});
1372              self.css(self.rail,{'cursor':cap.cursorgrabvalue});
1373            }
1374
1375          } else {
1376
1377            function checkSelectionScroll(e) {
1378              if (!self.selectiondrag) return;
1379
1380              if (e) {
1381                var ww = self.win.outerHeight();
1382                var df = (e.pageY - self.selectiondrag.top);
1383                if (df>0&&df<ww) df=0;
1384                if (df>=ww) df-=ww;
1385                self.selectiondrag.df = df;
1386              }
1387              if (self.selectiondrag.df==0) return;
1388
1389              var rt = -Math.floor(self.selectiondrag.df/6)*2;
1390//              self.doScrollTop(self.getScrollTop(true)+rt);
1391              self.doScrollBy(rt);
1392
1393              self.debounced("doselectionscroll",function(){checkSelectionScroll()},50);
1394            }
1395
1396            if ("getSelection" in document) {  // A grade - Major browsers
1397              self.hasTextSelected = function() {
1398                return (document.getSelection().rangeCount>0);
1399              }
1400            }
1401            else if ("selection" in document) {  //IE9-
1402              self.hasTextSelected = function() {
1403                return (document.selection.type != "None");
1404              }
1405            }
1406            else {
1407              self.hasTextSelected = function() {  // no support
1408                return false;
1409              }
1410            }
1411
1412            self.onselectionstart = function(e) {
1413              if (self.ispage) return;
1414              self.selectiondrag = self.win.offset();
1415            }
1416            self.onselectionend = function(e) {
1417              self.selectiondrag = false;
1418            }
1419            self.onselectiondrag = function(e) {
1420              if (!self.selectiondrag) return;
1421              if (self.hasTextSelected()) self.debounced("selectionscroll",function(){checkSelectionScroll(e)},250);
1422            }
1423
1424
1425          }
1426
1427          if (cap.hasmstouch) {
1428            self.css(self.rail,{'-ms-touch-action':'none'});
1429            self.css(self.cursor,{'-ms-touch-action':'none'});
1430
1431            self.bind(self.win,"MSPointerDown",self.ontouchstart);
1432            self.bind(document,"MSPointerUp",self.ontouchend);
1433            self.bind(document,"MSPointerMove",self.ontouchmove);
1434            self.bind(self.cursor,"MSGestureHold",function(e){e.preventDefault()});
1435            self.bind(self.cursor,"contextmenu",function(e){e.preventDefault()});
1436          }
1437
1438          if (this.istouchcapable) {  //desktop with screen touch enabled
1439            self.bind(self.win,"touchstart",self.ontouchstart);
1440            self.bind(document,"touchend",self.ontouchend);
1441            self.bind(document,"touchcancel",self.ontouchend);
1442            self.bind(document,"touchmove",self.ontouchmove);
1443          }
1444
1445          self.bind(self.cursor,"mousedown",self.onmousedown);
1446          self.bind(self.cursor,"mouseup",self.onmouseup);
1447
1448          if (self.railh) {
1449            self.bind(self.cursorh,"mousedown",function(e){self.onmousedown(e,true)});
1450            self.bind(self.cursorh,"mouseup",function(e){
1451              if (self.rail.drag&&self.rail.drag.pt==2) return;
1452              self.rail.drag = false;
1453              self.hasmoving = false;
1454              self.hideCursor();
1455              if (cap.hasmousecapture) document.releaseCapture();
1456              return self.cancelEvent(e);
1457            });
1458          }
1459
1460          if (self.opt.cursordragontouch||!cap.cantouch&&!self.opt.touchbehavior) {
1461
1462            self.rail.css({"cursor":"default"});
1463            self.railh&&self.railh.css({"cursor":"default"});
1464
1465            self.jqbind(self.rail,"mouseenter",function() {
1466              if (self.canshowonmouseevent) self.showCursor();
1467              self.rail.active = true;
1468            });
1469            self.jqbind(self.rail,"mouseleave",function() {
1470              self.rail.active = false;
1471              if (!self.rail.drag) self.hideCursor();
1472            });
1473
1474            if (self.opt.sensitiverail) {
1475              self.bind(self.rail,"click",function(e){self.doRailClick(e,false,false)});
1476              self.bind(self.rail,"dblclick",function(e){self.doRailClick(e,true,false)});
1477              self.bind(self.cursor,"click",function(e){self.cancelEvent(e)});
1478              self.bind(self.cursor,"dblclick",function(e){self.cancelEvent(e)});
1479            }
1480
1481            if (self.railh) {
1482              self.jqbind(self.railh,"mouseenter",function() {
1483                if (self.canshowonmouseevent) self.showCursor();
1484                self.rail.active = true;
1485              });
1486              self.jqbind(self.railh,"mouseleave",function() {
1487                self.rail.active = false;
1488                if (!self.rail.drag) self.hideCursor();
1489              });
1490
1491              if (self.opt.sensitiverail) {
1492                self.bind(self.railh, "click", function(e){self.doRailClick(e,false,true)});
1493                self.bind(self.railh, "dblclick", function(e){self.doRailClick(e, true, true) });
1494                self.bind(self.cursorh, "click", function (e) { self.cancelEvent(e) });
1495                self.bind(self.cursorh, "dblclick", function (e) { self.cancelEvent(e) });
1496              }
1497
1498            }
1499
1500          }
1501
1502          if (!cap.cantouch&&!self.opt.touchbehavior) {
1503
1504            self.bind((cap.hasmousecapture)?self.win:document,"mouseup",self.onmouseup);
1505            self.bind(document,"mousemove",self.onmousemove);
1506            if (self.onclick) self.bind(document,"click",self.onclick);
1507
1508            if (!self.ispage&&self.opt.enablescrollonselection) {
1509              self.bind(self.win[0],"mousedown",self.onselectionstart);
1510              self.bind(document,"mouseup",self.onselectionend);
1511              self.bind(self.cursor,"mouseup",self.onselectionend);
1512              if (self.cursorh) self.bind(self.cursorh,"mouseup",self.onselectionend);
1513              self.bind(document,"mousemove",self.onselectiondrag);
1514            }
1515
1516						if (self.zoom) {
1517							self.jqbind(self.zoom,"mouseenter",function() {
1518								if (self.canshowonmouseevent) self.showCursor();
1519								self.rail.active = true;
1520							});
1521							self.jqbind(self.zoom,"mouseleave",function() {
1522								self.rail.active = false;
1523								if (!self.rail.drag) self.hideCursor();
1524							});
1525						}
1526
1527          } else {
1528
1529            self.bind((cap.hasmousecapture)?self.win:document,"mouseup",self.ontouchend);
1530            self.bind(document,"mousemove",self.ontouchmove);
1531            if (self.onclick) self.bind(document,"click",self.onclick);
1532
1533            if (self.opt.cursordragontouch) {
1534              self.bind(self.cursor,"mousedown",self.onmousedown);
1535              self.bind(self.cursor,"mousemove",self.onmousemove);
1536              self.cursorh&&self.bind(self.cursorh,"mousedown",self.onmousedown);
1537              self.cursorh&&self.bind(self.cursorh,"mousemove",self.onmousemove);
1538            }
1539
1540          }
1541
1542					if (self.opt.enablemousewheel) {
1543						if (!self.isiframe) self.bind((cap.isie&&self.ispage) ? document : self.win /*self.docscroll*/ ,"mousewheel",self.onmousewheel);
1544						self.bind(self.rail,"mousewheel",self.onmousewheel);
1545						if (self.railh) self.bind(self.railh,"mousewheel",self.onmousewheelhr);
1546					}
1547
1548          if (!self.ispage&&!cap.cantouch&&!(/HTML|BODY/.test(self.win[0].nodeName))) {
1549            if (!self.win.attr("tabindex")) self.win.attr({"tabindex":tabindexcounter++});
1550
1551            self.jqbind(self.win,"focus",function(e) {
1552              domfocus = (self.getTarget(e)).id||true;
1553              self.hasfocus = true;
1554              if (self.canshowonmouseevent) self.noticeCursor();
1555            });
1556            self.jqbind(self.win,"blur",function(e) {
1557              domfocus = false;
1558              self.hasfocus = false;
1559            });
1560
1561            self.jqbind(self.win,"mouseenter",function(e) {
1562              mousefocus = (self.getTarget(e)).id||true;
1563              self.hasmousefocus = true;
1564              if (self.canshowonmouseevent) self.noticeCursor();
1565            });
1566            self.jqbind(self.win,"mouseleave",function() {
1567              mousefocus = false;
1568              self.hasmousefocus = false;
1569            });
1570
1571          };
1572
1573        }  // !ie9mobile
1574
1575        //Thanks to http://www.quirksmode.org !!
1576        self.onkeypress = function(e) {
1577          if (self.locked&&self.page.maxh==0) return true;
1578
1579          e = (e) ? e : window.e;
1580          var tg = self.getTarget(e);
1581          if (tg&&/INPUT|TEXTAREA|SELECT|OPTION/.test(tg.nodeName)) {
1582            var tp = tg.getAttribute('type')||tg.type||false;
1583            if ((!tp)||!(/submit|button|cancel/i.tp)) return true;
1584          }
1585
1586          if (self.hasfocus||(self.hasmousefocus&&!domfocus)||(self.ispage&&!domfocus&&!mousefocus)) {
1587            var key = e.keyCode;
1588
1589            if (self.locked&&key!=27) return self.cancelEvent(e);
1590
1591            var ctrl = e.ctrlKey||false;
1592            var shift = e.shiftKey || false;
1593
1594            var ret = false;
1595            switch (key) {
1596              case 38:
1597              case 63233: //safari
1598                self.doScrollBy(24*3);
1599                ret = true;
1600                break;
1601              case 40:
1602              case 63235: //safari
1603                self.doScrollBy(-24*3);
1604                ret = true;
1605                break;
1606              case 37:
1607              case 63232: //safari
1608                if (self.railh) {
1609                  (ctrl) ? self.doScrollLeft(0) : self.doScrollLeftBy(24*3);
1610                  ret = true;
1611                }
1612                break;
1613              case 39:
1614              case 63234: //safari
1615                if (self.railh) {
1616                  (ctrl) ? self.doScrollLeft(self.page.maxw) : self.doScrollLeftBy(-24*3);
1617                  ret = true;
1618                }
1619                break;
1620              case 33:
1621              case 63276: // safari
1622                self.doScrollBy(self.view.h);
1623                ret = true;
1624                break;
1625              case 34:
1626              case 63277: // safari
1627                self.doScrollBy(-self.view.h);
1628                ret = true;
1629                break;
1630              case 36:
1631              case 63273: // safari
1632                (self.railh&&ctrl) ? self.doScrollPos(0,0) : self.doScrollTo(0);
1633                ret = true;
1634                break;
1635              case 35:
1636              case 63275: // safari
1637                (self.railh&&ctrl) ? self.doScrollPos(self.page.maxw,self.page.maxh) : self.doScrollTo(self.page.maxh);
1638                ret = true;
1639                break;
1640              case 32:
1641                if (self.opt.spacebarenabled) {
1642                  (shift) ? self.doScrollBy(self.view.h) : self.doScrollBy(-self.view.h);
1643                  ret = true;
1644                }
1645                break;
1646              case 27: // ESC
1647                if (self.zoomactive) {
1648                  self.doZoom();
1649                  ret = true;
1650                }
1651                break;
1652            }
1653            if (ret) return self.cancelEvent(e);
1654          }
1655        };
1656
1657        if (self.opt.enablekeyboard) self.bind(document,(cap.isopera&&!cap.isopera12)?"keypress":"keydown",self.onkeypress);
1658
1659        self.bind(window,'resize',self.lazyResize);
1660        self.bind(window,'orientationchange',self.lazyResize);
1661
1662        self.bind(window,"load",self.lazyResize);
1663
1664        if (cap.ischrome&&!self.ispage&&!self.haswrapper) { //chrome void scrollbar bug - it persists in version 26
1665          var tmp=self.win.attr("style");
1666					var ww = parseFloat(self.win.css("width"))+1;
1667          self.win.css('width',ww);
1668          self.synched("chromefix",function(){self.win.attr("style",tmp)});
1669        }
1670
1671
1672// Trying a cross-browser implementation - good luck!
1673
1674        self.onAttributeChange = function(e) {
1675          self.lazyResize(250);
1676        }
1677
1678        if (!self.ispage&&!self.haswrapper) {
1679          // redesigned MutationObserver for Chrome18+/Firefox14+/iOS6+ with support for: remove div, add/remove content
1680          if (clsMutationObserver !== false) {
1681            self.observer = new clsMutationObserver(function(mutations) {
1682              mutations.forEach(self.onAttributeChange);
1683            });
1684            self.observer.observe(self.win[0],{childList: true, characterData: false, attributes: true, subtree: false});
1685
1686            self.observerremover = new clsMutationObserver(function(mutations) {
1687               mutations.forEach(function(mo){
1688                 if (mo.removedNodes.length>0) {
1689                   for (var dd in mo.removedNodes) {
1690                     if (mo.removedNodes[dd]==self.win[0]) return self.remove();
1691                   }
1692                 }
1693               });
1694            });
1695            self.observerremover.observe(self.win[0].parentNode,{childList: true, characterData: false, attributes: false, subtree: false});
1696
1697          } else {
1698            self.bind(self.win,(cap.isie&&!cap.isie9)?"propertychange":"DOMAttrModified",self.onAttributeChange);
1699            if (cap.isie9) self.win[0].attachEvent("onpropertychange",self.onAttributeChange); //IE9 DOMAttrModified bug
1700            self.bind(self.win,"DOMNodeRemoved",function(e){
1701              if (e.target==self.win[0]) self.remove();
1702            });
1703          }
1704        }
1705
1706//
1707
1708        if (!self.ispage&&self.opt.boxzoom) self.bind(window,"resize",self.resizeZoom);
1709        if (self.istextarea) self.bind(self.win,"mouseup",self.lazyResize);
1710
1711        self.checkrtlmode = true;
1712        self.lazyResize(30);
1713
1714      }
1715
1716      if (this.doc[0].nodeName == 'IFRAME') {
1717        function oniframeload(e) {
1718          self.iframexd = false;
1719          try {
1720            var doc = 'contentDocument' in this ? this.contentDocument : this.contentWindow.document;
1721            var a = doc.domain;
1722          } catch(e){self.iframexd = true;doc=false};
1723
1724          if (self.iframexd) {
1725            if ("console" in window) console.log('NiceScroll error: policy restriced iframe');
1726            return true;  //cross-domain - I can't manage this
1727          }
1728
1729          self.forcescreen = true;
1730
1731          if (self.isiframe) {
1732            self.iframe = {
1733              "doc":$(doc),
1734              "html":self.doc.contents().find('html')[0],
1735              "body":self.doc.contents().find('body')[0]
1736            };
1737            self.getContentSize = function(){
1738              return {
1739                w:Math.max(self.iframe.html.scrollWidth,self.iframe.body.scrollWidth),
1740                h:Math.max(self.iframe.html.scrollHeight,self.iframe.body.scrollHeight)
1741              }
1742            }
1743            self.docscroll = $(self.iframe.body);//$(this.contentWindow);
1744          }
1745
1746          if (!cap.isios&&self.opt.iframeautoresize&&!self.isiframe) {
1747            self.win.scrollTop(0); // reset position
1748            self.doc.height("");  //reset height to fix browser bug
1749            var hh=Math.max(doc.getElementsByTagName('html')[0].scrollHeight,doc.body.scrollHeight);
1750            self.doc.height(hh);
1751          }
1752          self.lazyResize(30);
1753
1754          if (cap.isie7) self.css($(self.iframe.html),{'overflow-y':'hidden'});
1755          //self.css($(doc.body),{'overflow-y':'hidden'});
1756          self.css($(self.iframe.body),{'overflow-y':'hidden'});
1757
1758          if (cap.isios&&self.haswrapper) {
1759            self.css($(doc.body),{'-webkit-transform':'translate3d(0,0,0)'});  // avoid iFrame content clipping - thanks to http://blog.derraab.com/2012/04/02/avoid-iframe-content-clipping-with-css-transform-on-ios/
1760
1761            console.log(1);
1762
1763          }
1764
1765          if ('contentWindow' in this) {
1766            self.bind(this.contentWindow,"scroll",self.onscroll);  //IE8 & minor
1767          } else {
1768            self.bind(doc,"scroll",self.onscroll);
1769          }
1770
1771          if (self.opt.enablemousewheel) {
1772            self.bind(doc,"mousewheel",self.onmousewheel);
1773          }
1774
1775          if (self.opt.enablekeyboard) self.bind(doc,(cap.isopera)?"keypress":"keydown",self.onkeypress);
1776
1777          if (cap.cantouch||self.opt.touchbehavior) {
1778            self.bind(doc,"mousedown",self.ontouchstart);
1779            self.bind(doc,"mousemove",function(e){self.ontouchmove(e,true)});
1780            if (self.opt.grabcursorenabled&&cap.cursorgrabvalue) self.css($(doc.body),{'cursor':cap.cursorgrabvalue});
1781          }
1782
1783          self.bind(doc,"mouseup",self.ontouchend);
1784
1785          if (self.zoom) {
1786            if (self.opt.dblclickzoom) self.bind(doc,'dblclick',self.doZoom);
1787            if (self.ongesturezoom) self.bind(doc,"gestureend",self.ongesturezoom);
1788          }
1789        };
1790
1791        if (this.doc[0].readyState&&this.doc[0].readyState=="complete"){
1792          setTimeout(function(){oniframeload.call(self.doc[0],false)},500);
1793        }
1794        self.bind(this.doc,"load",oniframeload);
1795
1796      }
1797
1798    };
1799
1800    this.showCursor = function(py,px) {
1801      if (self.cursortimeout) {
1802        clearTimeout(self.cursortimeout);
1803        self.cursortimeout = 0;
1804      }
1805      if (!self.rail) return;
1806      if (self.autohidedom) {
1807        self.autohidedom.stop().css({opacity:self.opt.cursoropacitymax});
1808        self.cursoractive = true;
1809      }
1810
1811      if (!self.rail.drag||self.rail.drag.pt!=1) {
1812        if ((typeof py != "undefined")&&(py!==false)) {
1813          self.scroll.y = Math.round(py * 1/self.scrollratio.y);
1814        }
1815        if (typeof px != "undefined") {
1816          self.scroll.x = Math.round(px * 1/self.scrollratio.x);
1817        }
1818      }
1819
1820      self.cursor.css({height:self.cursorheight,top:self.scroll.y});
1821      if (self.cursorh) {
1822        (!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});
1823        self.cursoractive = true;
1824      }
1825
1826      if (self.zoom) self.zoom.stop().css({opacity:self.opt.cursoropacitymax});
1827    };
1828
1829    this.hideCursor = function(tm) {
1830      if (self.cursortimeout) return;
1831      if (!self.rail) return;
1832      if (!self.autohidedom) return;
1833      self.cursortimeout = setTimeout(function() {
1834         if (!self.rail.active||!self.showonmouseevent) {
1835           self.autohidedom.stop().animate({opacity:self.opt.cursoropacitymin});
1836           if (self.zoom) self.zoom.stop().animate({opacity:self.opt.cursoropacitymin});
1837           self.cursoractive = false;
1838         }
1839         self.cursortimeout = 0;
1840      },tm||self.opt.hidecursordelay);
1841    };
1842
1843    this.noticeCursor = function(tm,py,px) {
1844      self.showCursor(py,px);
1845      if (!self.rail.active) self.hideCursor(tm);
1846    };
1847
1848    this.getContentSize =
1849      (self.ispage) ?
1850        function(){
1851          return {
1852            w:Math.max(document.body.scrollWidth,document.documentElement.scrollWidth),
1853            h:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
1854          }
1855        }
1856      : (self.haswrapper) ?
1857        function(){
1858          return {
1859            w:self.doc.outerWidth()+parseInt(self.win.css('paddingLeft'))+parseInt(self.win.css('paddingRight')),
1860            h:self.doc.outerHeight()+parseInt(self.win.css('paddingTop'))+parseInt(self.win.css('paddingBottom'))
1861          }
1862        }
1863      : function() {
1864        return {
1865          w:self.docscroll[0].scrollWidth,
1866          h:self.docscroll[0].scrollHeight
1867        }
1868      };
1869
1870    this.onResize = function(e,page) {
1871
1872	  if (!self.win) return false;
1873
1874      if (!self.haswrapper&&!self.ispage) {
1875        if (self.win.css('display')=='none') {
1876          if (self.visibility) self.hideRail().hideRailHr();
1877          return false;
1878        } else {
1879          if (!self.hidden&&!self.visibility) self.showRail().showRailHr();
1880        }
1881      }
1882
1883      var premaxh = self.page.maxh;
1884      var premaxw = self.page.maxw;
1885
1886      var preview = {h:self.view.h,w:self.view.w};
1887
1888      self.view = {
1889        w:(self.ispage) ? self.win.width() : parseInt(self.win[0].clientWidth),
1890        h:(self.ispage) ? self.win.height() : parseInt(self.win[0].clientHeight)
1891      };
1892
1893      self.page = (page) ? page : self.getContentSize();
1894
1895      self.page.maxh = Math.max(0,self.page.h - self.view.h);
1896      self.page.maxw = Math.max(0,self.page.w - self.view.w);
1897
1898      if ((self.page.maxh==premaxh)&&(self.page.maxw==premaxw)&&(self.view.w==preview.w)) {
1899        // test position
1900        if (!self.ispage) {
1901          var pos = self.win.offset();
1902          if (self.lastposition) {
1903            var lst = self.lastposition;
1904            if ((lst.top==pos.top)&&(lst.left==pos.left)) return self; //nothing to do
1905          }
1906          self.lastposition = pos;
1907        } else {
1908          return self; //nothing to do
1909        }
1910      }
1911
1912      if (self.page.maxh==0) {
1913        self.hideRail();
1914        self.scrollvaluemax = 0;
1915        self.scroll.y = 0;
1916        self.scrollratio.y = 0;
1917        self.cursorheight = 0;
1918        self.setScrollTop(0);
1919        self.rail.scrollable = false;
1920      } else {
1921        self.rail.scrollable = true;
1922      }
1923
1924      if (self.page.maxw==0) {
1925        self.hideRailHr();
1926        self.scrollvaluemaxw = 0;
1927        self.scroll.x = 0;
1928        self.scrollratio.x = 0;
1929        self.cursorwidth = 0;
1930        self.setScrollLeft(0);
1931        self.railh.scrollable = false;
1932      } else {
1933        self.railh.scrollable = true;
1934      }
1935
1936      self.locked = (self.page.maxh==0)&&(self.page.maxw==0);
1937      if (self.locked) {
1938				if (!self.ispage) self.updateScrollBar(self.view);
1939			  return false;
1940		  }
1941
1942      if (!self.hidden&&!self.visibility) {
1943        self.showRail().showRailHr();
1944      }
1945      else if (!self.hidden&&!self.railh.visibility) self.showRailHr();
1946
1947      if (self.istextarea&&self.win.css('resize')&&self.win.css('resize')!='none') self.view.h-=20;
1948
1949      self.cursorheight = Math.min(self.view.h,Math.round(self.view.h * (self.view.h / self.page.h)));
1950      self.cursorheight = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight,self.cursorheight);
1951
1952      self.cursorwidth = Math.min(self.view.w,Math.round(self.view.w * (self.view.w / self.page.w)));
1953      self.cursorwidth = (self.opt.cursorfixedheight) ? self.opt.cursorfixedheight : Math.max(self.opt.cursorminheight,self.cursorwidth);
1954
1955      self.scrollvaluemax = self.view.h-self.cursorheight-self.cursor.hborder;
1956
1957      if (self.railh) {
1958        self.railh.width = (self.page.maxh>0) ? (self.view.w-self.rail.width) : self.view.w;
1959        self.scrollvaluemaxw = self.railh.width-self.cursorwidth-self.cursorh.wborder;
1960      }
1961
1962      if (self.checkrtlmode&&self.railh) {
1963        self.checkrtlmode = false;
1964        if (self.opt.rtlmode&&self.scroll.x==0) self.setScrollLeft(self.page.maxw);
1965      }
1966
1967      if (!self.ispage) self.updateScrollBar(self.view);
1968
1969      self.scrollratio = {
1970        x:(self.page.maxw/self.scrollvaluemaxw),
1971        y:(self.page.maxh/self.scrollvaluemax)
1972      };
1973
1974      var sy = self.getScrollTop();
1975      if (sy>self.page.maxh) {
1976        self.doScrollTop(self.page.maxh);
1977      } else {
1978        self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
1979        self.scroll.x = Math.round(self.getScrollLeft() * (1/self.scrollratio.x));
1980        if (self.cursoractive) self.noticeCursor();
1981      }
1982
1983      if (self.scroll.y&&(self.getScrollTop()==0)) self.doScrollTo(Math.floor(self.scroll.y*self.scrollratio.y));
1984
1985      return self;
1986    };
1987
1988    this.resize = self.onResize;
1989
1990    this.lazyResize = function(tm) {   // event debounce
1991      tm = (isNaN(tm)) ? 30 : tm;
1992      self.delayed('resize',self.resize,tm);
1993      return self;
1994    }
1995
1996// modified by MDN https://developer.mozilla.org/en-US/docs/DOM/Mozilla_event_reference/wheel
1997    function _modernWheelEvent(dom,name,fn,bubble) {
1998      self._bind(dom,name,function(e){
1999        var  e = (e) ? e : window.event;
2000        var event = {
2001          original: e,
2002          target: e.target || e.srcElement,
2003          type: "wheel",
2004          deltaMode: e.type == "MozMousePixelScroll" ? 0 : 1,
2005          deltaX: 0,
2006          deltaZ: 0,
2007          preventDefault: function() {
2008            e.preventDefault ? e.preventDefault() : e.returnValue = false;
2009            return false;
2010          },
2011          stopImmediatePropagation: function() {
2012            (e.stopImmediatePropagation) ? e.stopImmediatePropagation() : e.cancelBubble = true;
2013          }
2014        };
2015
2016        if (name=="mousewheel") {
2017          event.deltaY = - 1/40 * e.wheelDelta;
2018          e.wheelDeltaX && (event.deltaX = - 1/40 * e.wheelDeltaX);
2019        } else {
2020          event.deltaY = e.detail;
2021        }
2022
2023        return fn.call(dom,event);
2024      },bubble);
2025    };
2026
2027    this._bind = function(el,name,fn,bubble) {  // primitive bind
2028      self.events.push({e:el,n:name,f:fn,b:bubble,q:false});
2029      if (el.addEventListener) {
2030        el.addEventListener(name,fn,bubble||false);
2031      }
2032      else if (el.attachEvent) {
2033        el.attachEvent("on"+name,fn);
2034      }
2035      else {
2036        el["on"+name] = fn;
2037      }
2038    };
2039
2040    this.jqbind = function(dom,name,fn) {  // use jquery bind for non-native events (mouseenter/mouseleave)
2041      self.events.push({e:dom,n:name,f:fn,q:true});
2042      $(dom).bind(name,fn);
2043    }
2044
2045    this.bind = function(dom,name,fn,bubble) {  // touch-oriented & fixing jquery bind
2046      var el = ("jquery" in dom) ? dom[0] : dom;
2047
2048      if (name=='mousewheel') {
2049        if ("onwheel" in self.win) {
2050          self._bind(el,"wheel",fn,bubble||false);
2051        } else {
2052          var wname = (typeof document.onmousewheel != "undefined") ? "mousewheel" : "DOMMouseScroll";  // older IE/Firefox
2053          _modernWheelEvent(el,wname,fn,bubble||false);
2054          if (wname=="DOMMouseScroll") _modernWheelEvent(el,"MozMousePixelScroll",fn,bubble||false);  // Firefox legacy
2055        }
2056      }
2057      else if (el.addEventListener) {
2058        if (cap.cantouch && /mouseup|mousedown|mousemove/.test(name)) {  // touch device support
2059          var tt=(name=='mousedown')?'touchstart':(name=='mouseup')?'touchend':'touchmove';
2060          self._bind(el,tt,function(e){
2061            if (e.touches) {
2062              if (e.touches.length<2) {var ev=(e.touches.length)?e.touches[0]:e;ev.original=e;fn.call(this,ev);}
2063            }
2064            else if (e.changedTouches) {var ev=e.changedTouches[0];ev.original=e;fn.call(this,ev);}  //blackberry
2065          },bubble||false);
2066        }
2067        self._bind(el,name,fn,bubble||false);
2068        if (cap.cantouch && name=="mouseup") self._bind(el,"touchcancel",fn,bubble||false);
2069      }
2070      else {
2071        self._bind(el,name,function(e) {
2072          e = e||window.event||false;
2073          if (e) {
2074            if (e.srcElement) e.target=e.srcElement;
2075          }
2076          if (!("pageY" in e)) {
2077            e.pageX = e.clientX + document.documentElement.scrollLeft;
2078            e.pageY = e.clientY + document.documentElement.scrollTop;
2079          }
2080          return ((fn.call(el,e)===false)||bubble===false) ? self.cancelEvent(e) : true;
2081        });
2082      }
2083    };
2084
2085    this._unbind = function(el,name,fn,bub) {  // primitive unbind
2086      if (el.removeEventListener) {
2087        el.removeEventListener(name,fn,bub);
2088      }
2089      else if (el.detachEvent) {
2090        el.detachEvent('on'+name,fn);
2091      } else {
2092        el['on'+name] = false;
2093      }
2094    };
2095
2096    this.unbindAll = function() {
2097      for(var a=0;a<self.events.length;a++) {
2098        var r = self.events[a];
2099        (r.q) ? r.e.unbind(r.n,r.f) : self._unbind(r.e,r.n,r.f,r.b);
2100      }
2101    };
2102
2103    // Thanks to http://www.switchonthecode.com !!
2104    this.cancelEvent = function(e) {
2105      var e = (e.original) ? e.original : (e) ? e : window.event||false;
2106      if (!e) return false;
2107      if(e.preventDefault) e.preventDefault();
2108      if(e.stopPropagation) e.stopPropagation();
2109      if(e.preventManipulation) e.preventManipulation();  //IE10
2110      e.cancelBubble = true;
2111      e.cancel = true;
2112      e.returnValue = false;
2113      return false;
2114    };
2115
2116    this.stopPropagation = function(e) {
2117      var e = (e.original) ? e.original : (e) ? e : window.event||false;
2118      if (!e) return false;
2119      if (e.stopPropagation) return e.stopPropagation();
2120      if (e.cancelBubble) e.cancelBubble=true;
2121      return false;
2122    }
2123
2124    this.showRail = function() {
2125      if ((self.page.maxh!=0)&&(self.ispage||self.win.css('display')!='none')) {
2126        self.visibility = true;
2127        self.rail.visibility = true;
2128        self.rail.css('display','block');
2129      }
2130      return self;
2131    };
2132
2133    this.showRailHr = function() {
2134      if (!self.railh) return self;
2135      if ((self.page.maxw!=0)&&(self.ispage||self.win.css('display')!='none')) {
2136        self.railh.visibility = true;
2137        self.railh.css('display','block');
2138      }
2139      return self;
2140    };
2141
2142    this.hideRail = function() {
2143      self.visibility = false;
2144      self.rail.visibility = false;
2145      self.rail.css('display','none');
2146      return self;
2147    };
2148
2149    this.hideRailHr = function() {
2150      if (!self.railh) return self;
2151      self.railh.visibility = false;
2152      self.railh.css('display','none');
2153      return self;
2154    };
2155
2156    this.show = function() {
2157      self.hidden = false;
2158      self.locked = false;
2159      return self.showRail().showRailHr();
2160    };
2161
2162    this.hide = function() {
2163      self.hidden = true;
2164      self.locked = true;
2165      return self.hideRail().hideRailHr();
2166    };
2167
2168    this.toggle = function() {
2169      return (self.hidden) ? self.show() : self.hide();
2170    };
2171
2172    this.remove = function() {
2173      self.stop();
2174      if (self.cursortimeout) clearTimeout(self.cursortimeout);
2175      self.doZoomOut();
2176      self.unbindAll();
2177
2178      if (cap.isie9) self.win[0].detachEvent("onpropertychange",self.onAttributeChange); //IE9 DOMAttrModified bug
2179
2180      if (self.observer !== false) self.observer.disconnect();
2181      if (self.observerremover !== false) self.observerremover.disconnect();
2182
2183      self.events = null;
2184
2185      if (self.cursor) {
2186        self.cursor.remove();
2187      }
2188      if (self.cursorh) {
2189        self.cursorh.remove();
2190      }
2191      if (self.rail) {
2192        self.rail.remove();
2193      }
2194      if (self.railh) {
2195        self.railh.remove();
2196      }
2197      if (self.zoom) {
2198        self.zoom.remove();
2199      }
2200      for(var a=0;a<self.saved.css.length;a++) {
2201        var d=self.saved.css[a];
2202        d[0].css(d[1],(typeof d[2]=="undefined") ? '' : d[2]);
2203      }
2204      self.saved = false;
2205      self.me.data('__nicescroll',''); //erase all traces
2206
2207      // memory leak fixed by GianlucaGuarini - thanks a lot!
2208      // remove the current nicescroll from the $.nicescroll array & normalize array
2209      var lst = $.nicescroll;
2210      lst.each(function(i){
2211        if (!this) return;
2212        if(this.id === self.id) {
2213          delete lst[i];
2214          for(var b=++i;b<lst.length;b++,i++) lst[i]=lst[b];
2215          lst.length--;
2216          if (lst.length) delete lst[lst.length];
2217        }
2218      });
2219
2220      for (var i in self) {
2221        self[i] = null;
2222        delete self[i];
2223      }
2224
2225      self = null;
2226
2227    };
2228
2229    this.scrollstart = function(fn) {
2230      this.onscrollstart = fn;
2231      return self;
2232    }
2233    this.scrollend = function(fn) {
2234      this.onscrollend = fn;
2235      return self;
2236    }
2237    this.scrollcancel = function(fn) {
2238      this.onscrollcancel = fn;
2239      return self;
2240    }
2241
2242    this.zoomin = function(fn) {
2243      this.onzoomin = fn;
2244      return self;
2245    }
2246    this.zoomout = function(fn) {
2247      this.onzoomout = fn;
2248      return self;
2249    }
2250
2251    this.isScrollable = function(e) {
2252      var dom = (e.target) ? e.target : e;
2253      if (dom.nodeName == 'OPTION') return true;
2254      while (dom&&(dom.nodeType==1)&&!(/BODY|HTML/.test(dom.nodeName))) {
2255        var dd = $(dom);
2256        var ov = dd.css('overflowY')||dd.css('overflowX')||dd.css('overflow')||'';
2257        if (/scroll|auto/.test(ov)) return (dom.clientHeight!=dom.scrollHeight);
2258        dom = (dom.parentNode) ? dom.parentNode : false;
2259      }
2260      return false;
2261    };
2262
2263    this.getViewport = function(me) {
2264      var dom = (me&&me.parentNode) ? me.parentNode : false;
2265      while (dom&&(dom.nodeType==1)&&!(/BODY|HTML/.test(dom.nodeName))) {
2266        var dd = $(dom);
2267        var ov = dd.css('overflowY')||dd.css('overflowX')||dd.css('overflow')||'';
2268        if ((/scroll|auto/.test(ov))&&(dom.clientHeight!=dom.scrollHeight)) return dd;
2269        if (dd.getNiceScroll().length>0) return dd;
2270        dom = (dom.parentNode) ? dom.parentNode : false;
2271      }
2272      return false;
2273    };
2274
2275    function execScrollWheel(e,hr,chkscroll) {
2276      var px,py;
2277      var rt = 1;
2278
2279      if (e.deltaMode==0) {  // PIXEL
2280        px = -Math.floor(e.deltaX*(self.opt.mousescrollstep/(18*3)));
2281        py = -Math.floor(e.deltaY*(self.opt.mousescrollstep/(18*3)));
2282      }
2283      else if (e.deltaMode==1) {  // LINE
2284        px = -Math.floor(e.deltaX*self.opt.mousescrollstep);
2285        py = -Math.floor(e.deltaY*self.opt.mousescrollstep);
2286      }
2287
2288      if (hr&&self.opt.oneaxismousemode&&(px==0)&&py) {  // classic vertical-only mousewheel + browser with x/y support
2289        px = py;
2290        py = 0;
2291      }
2292
2293      if (px) {
2294        if (self.scrollmom) {self.scrollmom.stop()}
2295        self.lastdeltax+=px;
2296        self.debounced("mousewheelx",function(){var dt=self.lastdeltax;self.lastdeltax=0;if(!self.rail.drag){self.doScrollLeftBy(dt)}},120);
2297      }
2298      if (py) {
2299        if (self.opt.nativeparentscrolling&&chkscroll&&!self.ispage&&!self.zoomactive) {
2300          if (py<0) {
2301            if (self.getScrollTop()>=self.page.maxh) return true;
2302          } else {
2303            if (self.getScrollTop()<=0) return true;
2304          }
2305        }
2306        if (self.scrollmom) {self.scrollmom.stop()}
2307        self.lastdeltay+=py;
2308        self.debounced("mousewheely",function(){var dt=self.lastdeltay;self.lastdeltay=0;if(!self.rail.drag){self.doScrollBy(dt)}},120);
2309      }
2310
2311      e.stopImmediatePropagation();
2312      return e.preventDefault();
2313//      return self.cancelEvent(e);
2314    };
2315
2316    this.onmousewheel = function(e) {
2317      if (self.locked) {
2318        self.debounced("checkunlock",self.resize,250);
2319        return true;
2320      }
2321      if (self.rail.drag) return self.cancelEvent(e);
2322
2323      if (self.opt.oneaxismousemode=="auto"&&e.deltaX!=0) self.opt.oneaxismousemode = false;  // check two-axis mouse support (not very elegant)
2324
2325      if (self.opt.oneaxismousemode&&e.deltaX==0) {
2326        if (!self.rail.scrollable) {
2327          if (self.railh&&self.railh.scrollable) {
2328            return self.onmousewheelhr(e);
2329          } else {
2330            return true;
2331          }
2332        }
2333      }
2334
2335      var nw = +(new Date());
2336      var chk = false;
2337      if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
2338//        self.checkarea = false;
2339        self.nativescrollingarea = self.isScrollable(e);
2340        chk = true;
2341      }
2342      self.checkarea = nw;
2343      if (self.nativescrollingarea) return true; // this isn't my business
2344//      if (self.locked) return self.cancelEvent(e);
2345      var ret = execScrollWheel(e,false,chk);
2346      if (ret) self.checkarea = 0;
2347      return ret;
2348    };
2349
2350    this.onmousewheelhr = function(e) {
2351      if (self.locked||!self.railh.scrollable) return true;
2352      if (self.rail.drag) return self.cancelEvent(e);
2353
2354      var nw = +(new Date());
2355      var chk = false;
2356      if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
2357//        self.checkarea = false;
2358        self.nativescrollingarea = self.isScrollable(e);
2359        chk = true;
2360      }
2361      self.checkarea = nw;
2362      if (self.nativescrollingarea) return true; // this isn't my business
2363      if (self.locked) return self.cancelEvent(e);
2364
2365      return execScrollWheel(e,true,chk);
2366    };
2367
2368    this.stop = function() {
2369      self.cancelScroll();
2370      if (self.scrollmon) self.scrollmon.stop();
2371      self.cursorfreezed = false;
2372      self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
2373      self.noticeCursor();
2374      return self;
2375    };
2376
2377    this.getTransitionSpeed = function(dif) {
2378      var sp = Math.round(self.opt.scrollspeed*10);
2379      var ex = Math.min(sp,Math.round((dif / 20) * self.opt.scrollspeed));
2380      return (ex>
238020) ? ex : 0;
2381    }
2382
2383    if (!self.opt.smoothscroll) {
2384      this.doScrollLeft = function(x,spd) {  //direct
2385        var y = self.getScrollTop();
2386        self.doScrollPos(x,y,spd);
2387      }
2388      this.doScrollTop = function(y,spd) {   //direct
2389        var x = self.getScrollLeft();
2390        self.doScrollPos(x,y,spd);
2391      }
2392      this.doScrollPos = function(x,y,spd) {  //direct
2393        var nx = (x>self.page.maxw) ? self.page.maxw : x;
2394        if (nx<0) nx=0;
2395        var ny = (y>self.page.maxh) ? self.page.maxh : y;
2396        if (ny<0) ny=0;
2397        self.synched('scroll',function(){
2398          self.setScrollTop(ny);
2399          self.setScrollLeft(nx);
2400        });
2401      }
2402      this.cancelScroll = function() {}; // direct
2403    }
2404    else if (self.ishwscroll&&cap.hastransition&&self.opt.usetransition) {
2405      this.prepareTransition = function(dif,istime) {
2406        var ex = (istime) ? ((dif>20)?dif:0) : self.getTransitionSpeed(dif);
2407        var trans = (ex) ? cap.prefixstyle+'transform '+ex+'ms ease-out' : '';
2408        if (!self.lasttransitionstyle||self.lasttransitionstyle!=trans) {
2409          self.lasttransitionstyle = trans;
2410          self.doc.css(cap.transitionstyle,trans);
2411        }
2412        return ex;
2413      };
2414
2415      this.doScrollLeft = function(x,spd) {  //trans
2416        var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
2417        self.doScrollPos(x,y,spd);
2418      }
2419
2420      this.doScrollTop = function(y,spd) {   //trans
2421        var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
2422        self.doScrollPos(x,y,spd);
2423      }
2424
2425      this.doScrollPos = function(x,y,spd) {  //trans
2426
2427        var py = self.getScrollTop();
2428        var px = self.getScrollLeft();
2429
2430        if (((self.newscrolly-py)*(y-py)<0)||((self.newscrollx-px)*(x-px)<0)) self.cancelScroll();  //inverted movement detection
2431
2432        if (self.opt.bouncescroll==false) {
2433          if (y<0) y=0;
2434          else if (y>self.page.maxh) y=self.page.maxh;
2435          if (x<0) x=0;
2436          else if (x>self.page.maxw) x=self.page.maxw;
2437        }
2438
2439        if (self.scrollrunning&&x==self.newscrollx&&y==self.newscrolly) return false;
2440
2441        self.newscrolly = y;
2442        self.newscrollx = x;
2443
2444        self.newscrollspeed = spd||false;
2445
2446        if (self.timer) return false;
2447
2448        self.timer = setTimeout(function(){
2449
2450          var top = self.getScrollTop();
2451          var lft = self.getScrollLeft();
2452
2453          var dst = {};
2454          dst.x = x-lft;
2455          dst.y = y-top;
2456          dst.px = lft;
2457          dst.py = top;
2458
2459          var dd = Math.round(Math.sqrt(Math.pow(dst.x,2)+Math.pow(dst.y,2)));
2460
2461//          var df = (self.newscrollspeed) ? self.newscrollspeed : dd;
2462
2463          var ms = (self.newscrollspeed && self.newscrollspeed>1) ? self.newscrollspeed : self.getTransitionSpeed(dd);
2464          if (self.newscrollspeed&&self.newscrollspeed<=1) ms*=self.newscrollspeed;
2465
2466          self.prepareTransition(ms,true);
2467
2468          if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
2469
2470          if (ms>0) {
2471
2472            if (!self.scrollrunning&&self.onscrollstart) {
2473              var info = {"type":"scrollstart","current":{"x":lft,"y":top},"request":{"x":x,"y":y},"end":{"x":self.newscrollx,"y":self.newscrolly},"speed":ms};
2474              self.onscrollstart.call(self,info);
2475            }
2476
2477            if (cap.transitionend) {
2478              if (!self.scrollendtrapped) {
2479                self.scrollendtrapped = true;
2480                self.bind(self.doc,cap.transitionend,self.onScrollEnd,false); //I have got to do something usefull!!
2481              }
2482            } else {
2483              if (self.scrollendtrapped) clearTimeout(self.scrollendtrapped);
2484              self.scrollendtrapped = setTimeout(self.onScrollEnd,ms);  // simulate transitionend event
2485            }
2486
2487            var py = top;
2488            var px = lft;
2489            self.timerscroll = {
2490              bz: new BezierClass(py,self.newscrolly,ms,0,0,0.58,1),
2491              bh: new BezierClass(px,self.newscrollx,ms,0,0,0.58,1)
2492            };
2493            if (!self.cursorfreezed) self.timerscroll.tm=setInterval(function(){self.showCursor(self.getScrollTop(),self.getScrollLeft())},60);
2494
2495          }
2496
2497          self.synched("doScroll-set",function(){
2498            self.timer = 0;
2499            if (self.scrollendtrapped) self.scrollrunning = true;
2500            self.setScrollTop(self.newscrolly);
2501            self.setScrollLeft(self.newscrollx);
2502            if (!self.scrollendtrapped) self.onScrollEnd();
2503          });
2504
2505
2506        },50);
2507
2508      };
2509
2510      this.cancelScroll = function() {
2511        if (!self.scrollendtrapped) return true;
2512        var py = self.getScrollTop();
2513        var px = self.getScrollLeft();
2514        self.scrollrunning = false;
2515        if (!cap.transitionend) clearTimeout(cap.transitionend);
2516        self.scrollendtrapped = false;
2517        self._unbind(self.doc,cap.transitionend,self.onScrollEnd);
2518        self.prepareTransition(0);
2519        self.setScrollTop(py); // fire event onscroll
2520        if (self.railh) self.setScrollLeft(px);
2521        if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
2522        self.timerscroll = false;
2523
2524        self.cursorfreezed = false;
2525
2526        //self.noticeCursor(false,py,px);
2527        self.showCursor(py,px);
2528        return self;
2529      };
2530      this.onScrollEnd = function() {
2531        if (self.scrollendtrapped) self._unbind(self.doc,cap.transitionend,self.onScrollEnd);
2532        self.scrollendtrapped = false;
2533        self.prepareTransition(0);
2534        if (self.timerscroll&&self.timerscroll.tm) clearInterval(self.timerscroll.tm);
2535        self.timerscroll = false;
2536        var py = self.getScrollTop();
2537        var px = self.getScrollLeft();
2538        self.setScrollTop(py);  // fire event onscroll
2539        if (self.railh) self.setScrollLeft(px);  // fire event onscroll left
2540
2541        self.noticeCursor(false,py,px);
2542
2543        self.cursorfreezed = false;
2544
2545        if (py<0) py=0
2546        else if (py>self.page.maxh) py=self.page.maxh;
2547        if (px<0) px=0
2548        else if (px>self.page.maxw) px=self.page.maxw;
2549        if((py!=self.newscrolly)||(px!=self.newscrollx)) return self.doScrollPos(px,py,self.opt.snapbackspeed);
2550
2551        if (self.onscrollend&&self.scrollrunning) {
2552          var info = {"type":"scrollend","current":{"x":px,"y":py},"end":{"x":self.newscrollx,"y":self.newscrolly}};
2553          self.onscrollend.call(self,info);
2554        }
2555        self.scrollrunning = false;
2556
2557      };
2558
2559    } else {
2560
2561      this.doScrollLeft = function(x,spd) {  //no-trans
2562        var y = (self.scrollrunning) ? self.newscrolly : self.getScrollTop();
2563        self.doScrollPos(x,y,spd);
2564      }
2565
2566      this.doScrollTop = function(y,spd) {  //no-trans
2567        var x = (self.scrollrunning) ? self.newscrollx : self.getScrollLeft();
2568        self.doScrollPos(x,y,spd);
2569      }
2570
2571      this.doScrollPos = function(x,y,spd) {  //no-trans
2572        var y = ((typeof y == "undefined")||(y===false)) ? self.getScrollTop(true) : y;
2573
2574        if  ((self.timer)&&(self.newscrolly==y)&&(self.newscrollx==x)) return true;
2575
2576        if (self.timer) clearAnimationFrame(self.timer);
2577        self.timer = 0;
2578
2579        var py = self.getScrollTop();
2580        var px = self.getScrollLeft();
2581
2582        if (((self.newscrolly-py)*(y-py)<0)||((self.newscrollx-px)*(x-px)<0)) self.cancelScroll();  //inverted movement detection
2583
2584        self.newscrolly = y;
2585        self.newscrollx = x;
2586
2587        if (!self.bouncescroll||!self.rail.visibility) {
2588          if (self.newscrolly<0) {
2589            self.newscrolly = 0;
2590          }
2591          else if (self.newscrolly>self.page.maxh) {
2592            self.newscrolly = self.page.maxh;
2593          }
2594        }
2595        if (!self.bouncescroll||!self.railh.visibility) {
2596          if (self.newscrollx<0) {
2597            self.newscrollx = 0;
2598          }
2599          else if (self.newscrollx>self.page.maxw) {
2600            self.newscrollx = self.page.maxw;
2601          }
2602        }
2603
2604        self.dst = {};
2605        self.dst.x = x-px;
2606        self.dst.y = y-py;
2607        self.dst.px = px;
2608        self.dst.py = py;
2609
2610        var dst = Math.round(Math.sqrt(Math.pow(self.dst.x,2)+Math.pow(self.dst.y,2)));
2611
2612        self.dst.ax = self.dst.x / dst;
2613        self.dst.ay = self.dst.y / dst;
2614
2615        var pa = 0;
2616        var pe = dst;
2617
2618        if (self.dst.x==0) {
2619          pa = py;
2620          pe = y;
2621          self.dst.ay = 1;
2622          self.dst.py = 0;
2623        } else if (self.dst.y==0) {
2624          pa = px;
2625          pe = x;
2626          self.dst.ax = 1;
2627          self.dst.px = 0;
2628        }
2629
2630        var ms = self.getTransitionSpeed(dst);
2631        if (spd&&spd<=1) ms*=spd;
2632        if (ms>0) {
2633          self.bzscroll = (self.bzscroll) ? self.bzscroll.update(pe,ms) : new BezierClass(pa,pe,ms,0,1,0,1);
2634        } else {
2635          self.bzscroll = false;
2636        }
2637
2638        if (self.timer) return;
2639
2640        if ((py==self.page.maxh&&y>=self.page.maxh)||(px==self.page.maxw&&x>=self.page.maxw)) self.checkContentSize();
2641
2642        var sync = 1;
2643
2644        function scrolling() {
2645          if (self.cancelAnimationFrame) return true;
2646
2647          self.scrollrunning = true;
2648
2649          sync = 1-sync;
2650          if (sync) return (self.timer = setAnimationFrame(scrolling)||1);
2651
2652          var done = 0;
2653
2654          var sc = sy = self.getScrollTop();
2655          if (self.dst.ay) {
2656            sc = (self.bzscroll) ? self.dst.py + (self.bzscroll.getNow()
2656*self.dst.ay) : self.newscrolly;
2657            var dr=sc-sy;
2658            if ((dr<0&&sc<self.newscrolly)||(dr>0&&sc>self.newscrolly)) sc = self.newscrolly;
2659            self.setScrollTop(sc);
2660            if (sc == self.newscrolly) done=1;
2661          } else {
2662            done=1;
2663          }
2664
2665          var scx = sx = self.getScrollLeft();
2666          if (self.dst.ax) {
2667            scx = (self.bzscroll) ? self.dst.px + (self.bzscroll.getNow()*self.dst.ax) : self.newscrollx;
2668            var dr=scx-sx;
2669            if ((dr<0&&scx<self.newscrollx)||(dr>0&&scx>self.newscrollx)) scx = self.newscrollx;
2670            self.setScrollLeft(scx);
2671            if (scx == self.newscrollx) done+=1;
2672          } else {
2673            done+=1;
2674          }
2675
2676          if (done==2) {
2677            self.timer = 0;
2678            self.cursorfreezed = false;
2679            self.bzscroll = false;
2680            self.scrollrunning = false;
2681            if (sc<0) sc=0;
2682            else if (sc>self.page.maxh) sc=self.page.maxh;
2683            if (scx<0) scx=0;
2684            else if (scx>self.page.maxw) scx=self.page.maxw;
2685            if ((scx!=self.newscrollx)||(sc!=self.newscrolly)) self.doScrollPos(scx,sc);
2686            else {
2687              if (self.onscrollend) {
2688                var info = {"type":"scrollend","current":{"x":sx,"y":sy},"end":{"x":self.newscrollx,"y":self.newscrolly}};
2689                self.onscrollend.call(self,info);
2690              }
2691            }
2692          } else {
2693            self.timer = setAnimationFrame(scrolling)||1;
2694          }
2695        };
2696        self.cancelAnimationFrame=false;
2697        self.timer = 1;
2698
2699        if (self.onscrollstart&&!self.scrollrunning) {
2700          var info = {"type":"scrollstart","current":{"x":px,"y":py},"request":{"x":x,"y":y},"end":{"x":self.newscrollx,"y":self.newscrolly},"speed":ms};
2701          self.onscrollstart.call(self,info);
2702        }
2703
2704        scrolling();
2705
2706        if ((py==self.page.maxh&&y>=py)||(px==self.page.maxw&&x>=px)) self.checkContentSize();
2707
2708        self.noticeCursor();
2709      };
2710
2711      this.cancelScroll = function() {
2712        if (self.timer) clearAnimationFrame(self.timer);
2713        self.timer = 0;
2714        self.bzscroll = false;
2715        self.scrollrunning = false;
2716        return self;
2717      };
2718
2719    }
2720
2721    this.doScrollBy = function(stp,relative) {
2722      var ny = 0;
2723      if (relative) {
2724        ny = Math.floor((self.scroll.y-stp)*self.scrollratio.y)
2725      } else {
2726        var sy = (self.timer) ? self.newscrolly : self.getScrollTop(true);
2727        ny = sy-stp;
2728      }
2729      if (self.bouncescroll) {
2730        var haf = Math.round(self.view.h/2);
2731        if (ny<-haf) ny=-haf
2732        else if (ny>(self.page.maxh+haf)) ny = (self.page.maxh+haf);
2733      }
2734      self.cursorfreezed = false;
2735
2736      py = self.getScrollTop(true);
2737      if (ny<0&&py<=0) return self.noticeCursor();
2738      else if (ny>self.page.maxh&&py>=self.page.maxh) {
2739        self.checkContentSize();
2740        return self.noticeCursor();
2741      }
2742
2743      self.doScrollTop(ny);
2744    };
2745
2746    this.doScrollLeftBy = function(stp,relative) {
2747      var nx = 0;
2748      if (relative) {
2749        nx = Math.floor((self.scroll.x-stp)*self.scrollratio.x)
2750      } else {
2751        var sx = (self.timer) ? self.newscrollx : self.getScrollLeft(true);
2752        nx = sx-stp;
2753      }
2754      if (self.bouncescroll) {
2755        var haf = Math.round(self.view.w/2);
2756        if (nx<-haf) nx=-haf
2757        else if (nx>(self.page.maxw+haf)) nx = (self.page.maxw+haf);
2758      }
2759      self.cursorfreezed = false;
2760
2761      px = self.getScrollLeft(true);
2762      if (nx<0&&px<=0) return self.noticeCursor();
2763      else if (nx>self.page.maxw&&px>=self.page.maxw) return self.noticeCursor();
2764
2765      self.doScrollLeft(nx);
2766    };
2767
2768    this.doScrollTo = function(pos,relative) {
2769      var ny = (relative) ? Math.round(pos*self.scrollratio.y) : pos;
2770      if (ny<0) ny=0
2771      else if (ny>self.page.maxh) ny = self.page.maxh;
2772      self.cursorfreezed = false;
2773      self.doScrollTop(pos);
2774    };
2775
2776    this.checkContentSize = function() {
2777      var pg = self.getContentSize();
2778      if ((pg.h!=self.page.h)||(pg.w!=self.page.w)) self.resize(false,pg);
2779    };
2780
2781    self.onscroll = function(e) {
2782      if (self.rail.drag) return;
2783      if (!self.cursorfreezed) {
2784        self.synched('scroll',function(){
2785          self.scroll.y = Math.round(self.getScrollTop() * (1/self.scrollratio.y));
2786          if (self.railh) self.scroll.x = Math.round(self.getScrollLeft() * (1/self.scrollratio.x));
2787          self.noticeCursor();
2788        });
2789      }
2790    };
2791    self.bind(self.docscroll,"scroll",self.onscroll);
2792
2793    this.doZoomIn = function(e) {
2794      if (self.zoomactive) return;
2795      self.zoomactive = true;
2796
2797      self.zoomrestore = {
2798        style:{}
2799      };
2800      var lst = ['position','top','left','zIndex','backgroundColor','marginTop','marginBottom','marginLeft','marginRight'];
2801      var win = self.win[0].style;
2802      for(var a in lst) {
2803        var pp = lst[a];
2804        self.zoomrestore.style[pp] = (typeof win[pp] != "undefined") ? win[pp] : '';
2805      }
2806
2807      self.zoomrestore.style.width = self.win.css('width');
2808      self.zoomrestore.style.height = self.win.css('height');
2809
2810      self.zoomrestore.padding = {
2811        w:self.win.outerWidth()-self.win.width(),
2812        h:self.win.outerHeight()-self.win.height()
2813      };
2814
2815      if (cap.isios4) {
2816        self.zoomrestore.scrollTop = $(window).scrollTop();
2817        $(window).scrollTop(0);
2818      }
2819
2820      self.win.css({
2821        "position":(cap.isios4)?"absolute":"fixed",
2822        "top":0,
2823        "left":0,
2824        "z-index":globalmaxzindex+100,
2825        "margin":"0px"
2826      });
2827      var bkg = self.win.css("backgroundColor");
2828      if (bkg==""||/transparent|rgba\(0, 0, 0, 0\)|rgba\(0,0,0,0\)/.test(bkg)) self.win.css("backgroundColor","#fff");
2829      self.rail.css({"z-index":globalmaxzindex+101});
2830      self.zoom.css({"z-index":globalmaxzindex+102});
2831      self.zoom.css('backgroundPosition','0px -18px');
2832      self.resizeZoom();
2833
2834      if (self.onzoomin) self.onzoomin.call(self);
2835
2836      return self.cancelEvent(e);
2837    };
2838
2839    this.doZoomOut = function(e) {
2840      if (!self.zoomactive) return;
2841      self.zoomactive = false;
2842
2843      self.win.css("margin","");
2844      self.win.css(self.zoomrestore.style);
2845
2846      if (cap.isios4) {
2847        $(window).scrollTop(self.zoomrestore.scrollTop);
2848      }
2849
2850      self.rail.css({"z-index":self.zindex});
2851      self.zoom.css({"z-index":self.zindex});
2852      self.zoomrestore = false;
2853      self.zoom.css('backgroundPosition','0px 0px');
2854      self.onResize();
2855
2856      if (self.onzoomout) self.onzoomout.call(self);
2857
2858      return self.cancelEvent(e);
2859    };
2860
2861    this.doZoom = function(e) {
2862      return (self.zoomactive) ? self.doZoomOut(e) : self.doZoomIn(e);
2863    };
2864
2865    this.resizeZoom = function() {
2866      if (!self.zoomactive) return;
2867
2868      var py = self.getScrollTop(); //preserve scrolling position
2869      self.win.css({
2870        width:$(window).width()-self.zoomrestore.padding.w+"px",
2871        height:$(window).height()-self.zoomrestore.padding.h+"px"
2872      });
2873      self.onResize();
2874
2875      self.setScrollTop(Math.min(self.page.maxh,py));
2876    };
2877
2878    this.init();
2879
2880    $.nicescroll.push(this);
2881
2882  };
2883
2884// Inspired by the work of Kin Blas
2885// http://webpro.host.adobe.com/people/jblas/momentum/includes/jquery.momentum.0.7.js
2886
2887
2888  var ScrollMomentumClass2D = function(nc) {
2889    var self = this;
2890    this.nc = nc;
2891
2892    this.lastx = 0;
2893    this.lasty = 0;
2894    this.speedx = 0;
2895    this.speedy = 0;
2896    this.lasttime = 0;
2897    this.steptime = 0;
2898    this.snapx = false;
2899    this.snapy = false;
2900    this.demulx = 0;
2901    this.demuly = 0;
2902
2903    this.lastscrollx = -1;
2904    this.lastscrolly = -1;
2905
2906    this.chkx = 0;
2907    this.chky = 0;
2908
2909    this.timer = 0;
2910
2911    this.time = function() {
2912      return +new Date();//beautifull hack
2913    };
2914
2915    this.reset = function(px,py) {
2916      self.stop();
2917      var now = self.time();
2918      self.steptime = 0;
2919      self.lasttime = now;
2920      self.speedx = 0;
2921      self.speedy = 0;
2922      self.lastx = px;
2923      self.lasty = py;
2924      self.lastscrollx = -1;
2925      self.lastscrolly = -1;
2926    };
2927
2928    this.update = function(px,py) {
2929      var now = self.time();
2930      self.steptime = now - self.lasttime;
2931      self.lasttime = now;
2932      var dy = py - self.lasty;
2933      var dx = px - self.lastx;
2934      var sy = self.nc.getScrollTop();
2935      var sx = self.nc.getScrollLeft();
2936      var newy = sy + dy;
2937      var newx = sx + dx;
2938      self.snapx = (newx<0)||(newx>self.nc.page.maxw);
2939      self.snapy = (newy<0)||(newy>self.nc.page.maxh);
2940      self.speedx = dx;
2941      self.speedy = dy;
2942      self.lastx = px;
2943      self.lasty = py;
2944    };
2945
2946    this.stop = function() {
2947      self.nc.unsynched("domomentum2d");
2948      if (self.timer) clearTimeout(self.timer);
2949      self.timer = 0;
2950      self.lastscrollx = -1;
2951      self.lastscrolly = -1;
2952    };
2953
2954    this.doSnapy = function(nx,ny) {
2955      var snap = false;
2956
2957      if (ny<0) {
2958        ny=0;
2959        snap=true;
2960      }
2961      else if (ny>self.nc.page.maxh) {
2962        ny=self.nc.page.maxh;
2963        snap=true;
2964      }
2965
2966      if (nx<0) {
2967        nx=0;
2968        snap=true;
2969      }
2970      else if (nx>self.nc.page.maxw) {
2971        nx=self.nc.page.maxw;
2972        snap=true;
2973      }
2974
2975      if (snap) self.nc.doScrollPos(nx,ny,self.nc.opt.snapbackspeed);
2976    };
2977
2978    this.doMomentum = function(gp) {
2979      var t = self.time();
2980      var l = (gp) ? t+gp : self.lasttime;
2981
2982      var sl = self.nc.getScrollLeft();
2983      var st = self.nc.getScrollTop();
2984
2985      var pageh = self.nc.page.maxh;
2986      var pagew = self.nc.page.maxw;
2987
2988      self.speedx = (pagew>0) ? Math.min(60,self.speedx) : 0;
2989      self.speedy = (pageh>0) ? Math.min(60,self.speedy) : 0;
2990
2991      var chk = l && (t - l) <= 60;
2992
2993      if ((st<0)||(st>pageh)||(sl<0)||(sl>
2993pagew)) chk = false;
2994
2995      var sy = (self.speedy && chk) ? self.speedy : false;
2996      var sx = (self.speedx && chk) ? self.speedx : false;
2997
2998      if (sy||sx) {
2999        var tm = Math.max(16,self.steptime); //timeout granularity
3000
3001        if (tm>50) {  // do smooth
3002          var xm = tm/50;
3003          self.speedx*=xm;
3004          self.speedy*=xm;
3005          tm = 50;
3006        }
3007
3008        self.demulxy = 0;
3009
3010        self.lastscrollx = self.nc.getScrollLeft();
3011        self.chkx = self.lastscrollx;
3012        self.lastscrolly = self.nc.getScrollTop();
3013        self.chky = self.lastscrolly;
3014
3015        var nx = self.lastscrollx;
3016        var ny = self.lastscrolly;
3017
3018        var onscroll = function(){
3019          var df = ((self.time()-t)>600) ? 0.04 : 0.02;
3020
3021          if (self.speedx) {
3022            nx = Math.floor(self.lastscrollx - (self.speedx*(1-self.demulxy)));
3023            self.lastscrollx = nx;
3024            if ((nx<0)||(nx>pagew)) df=0.10;
3025          }
3026
3027          if (self.speedy) {
3028            ny = Math.floor(self.lastscrolly - (self.speedy*(1-self.demulxy)));
3029            self.lastscrolly = ny;
3030            if ((ny<0)||(ny>pageh)) df=0.10;
3031          }
3032
3033          self.demulxy = Math.min(1,self.demulxy+df);
3034
3035          self.nc.synched("domomentum2d",function(){
3036
3037            if (self.speedx) {
3038              var scx = self.nc.getScrollLeft();
3039              if (scx!=self.chkx) self.stop();
3040              self.chkx=nx;
3041              self.nc.setScrollLeft(nx);
3042            }
3043
3044            if (self.speedy) {
3045              var scy = self.nc.getScrollTop();
3046              if (scy!=self.chky) self.stop();
3047              self.chky=ny;
3048              self.nc.setScrollTop(ny);
3049            }
3050
3051            if(!self.timer) {
3052              self.nc.hideCursor();
3053              self.doSnapy(nx,ny);
3054            }
3055
3056          });
3057
3058          if (self.demulxy<1) {
3059            self.timer = setTimeout(onscroll,tm);
3060          } else {
3061            self.stop();
3062            self.nc.hideCursor();
3063            self.doSnapy(nx,ny);
3064          }
3065        };
3066
3067        onscroll();
3068
3069      } else {
3070        self.doSnapy(self.nc.getScrollLeft(),self.nc.getScrollTop());
3071      }
3072
3073    }
3074
3075  };
3076
3077
3078// override jQuery scrollTop
3079
3080  var _scrollTop = jQuery.fn.scrollTop; // preserve original function
3081
3082  jQuery.cssHooks["pageYOffset"] = {
3083    get: function(elem,computed,extra) {
3084      var nice = $.data(elem,'__nicescroll')||false;
3085      return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
3086    },
3087    set: function(elem,value) {
3088      var nice = $.data(elem,'__nicescroll')||false;
3089      (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call(elem,value);
3090      return this;
3091    }
3092  };
3093
3094/*
3095  $.fx.step["scrollTop"] = function(fx){
3096    $.cssHooks["scrollTop"].set( fx.elem, fx.now + fx.unit );
3097  };
3098*/
3099
3100  jQuery.fn.scrollTop = function(value) {
3101    if (typeof value == "undefined") {
3102      var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
3103      return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
3104    } else {
3105      return this.each(function() {
3106        var nice = $.data(this,'__nicescroll')||false;
3107        (nice&&nice.ishwscroll) ? nice.setScrollTop(parseInt(value)) : _scrollTop.call($(this),value);
3108      });
3109    }
3110  }
3111
3112// override jQuery scrollLeft
3113
3114  var _scrollLeft = jQuery.fn.scrollLeft; // preserve original function
3115
3116  $.cssHooks.pageXOffset = {
3117    get: function(elem,computed,extra) {
3118      var nice = $.data(elem,'__nicescroll')||false;
3119      return (nice&&nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(elem);
3120    },
3121    set: function(elem,value) {
3122      var nice = $.data(elem,'__nicescroll')||false;
3123      (nice&&nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call(elem,value);
3124      return this;
3125    }
3126  };
3127
3128/*
3129  $.fx.step["scrollLeft"] = function(fx){
3130    $.cssHooks["scrollLeft"].set( fx.elem, fx.now + fx.unit );
3131  };
3132*/
3133
3134  jQuery.fn.scrollLeft = function(value) {
3135    if (typeof value == "undefined") {
3136      var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
3137      return (nice&&nice.ishwscroll) ? nice.getScrollLeft() : _scrollLeft.call(this);
3138    } else {
3139      return this.each(function() {
3140        var nice = $.data(this,'__nicescroll')||false;
3141        (nice&&nice.ishwscroll) ? nice.setScrollLeft(parseInt(value)) : _scrollLeft.call($(this),value);
3142      });
3143    }
3144  }
3145
3146  var NiceScrollArray = function(doms) {
3147    var self = this;
3148    this.length = 0;
3149    this.name = "nicescrollarray";
3150
3151    this.each = function(fn) {
3152      for(var a=0,i=0;a<self.length;a++) fn.call(self[a],i++);
3153      return self;
3154    };
3155
3156    this.push = function(nice) {
3157      self[self.length]=nice;
3158      self.length++;
3159    };
3160
3161    this.eq = function(idx) {
3162      return self[idx];
3163    };
3164
3165    if (doms) {
3166      for(a=0;a<doms.length;a++) {
3167        var nice = $.data(doms[a],'__nicescroll')||false;
3168        if (nice) {
3169          this[this.length]=nice;
3170          this.length++;
3171        }
3172      };
3173    }
3174
3175    return this;
3176  };
3177
3178  function mplex(el,lst,fn) {
3179    for(var a=0;a<lst.length;a++) fn(el,lst[a]);
3180  };
3181  mplex(
3182    NiceScrollArray.prototype,
3183    ['show','hide','toggle','onResize','resize','remove','stop','doScrollPos'],
3184    function(e,n) {
3185      e[n] = function(){
3186        var args = arguments;
3187        return this.each(function(){
3188          this[n].apply(this,args);
3189        });
3190      };
3191    }
3192  );
3193
3194  jQuery.fn.getNiceScroll = function(index) {
3195    if (typeof index == "undefined") {
3196      return new NiceScrollArray(this);
3197    } else {
3198      var nice = this[index]&&$.data(this[index],'__nicescroll')||false;
3199      return nice;
3200    }
3201  };
3202
3203  jQuery.extend(jQuery.expr[':'], {
3204    nicescroll: function(a) {
3205      return ($.data(a,'__nicescroll'))?true:false;
3206    }
3207  });
3208
3209  $.fn.niceScroll = function(wrapper,opt) {
3210    if (typeof opt=="undefined") {
3211      if ((typeof wrapper=="object")&&!("jquery" in wrapper)) {
3212        opt = wrapper;
3213        wrapper = false;
3214      }
3215    }
3216    var ret = new NiceScrollArray();
3217    if (typeof opt=="undefined") opt = {};
3218
3219    if (wrapper||false) {
3220      opt.doc = $(wrapper);
3221      opt.win = $(this);
3222    }
3223    var docundef = !("doc" in opt);
3224    if (!docundef&&!("win" in opt)) opt.win = $(this);
3225
3226    this.each(function() {
3227      var nice = $(this).data('__nicescroll')||false;
3228      if (!nice) {
3229        opt.doc = (docundef) ? $(this) : opt.doc;
3230        nice = new NiceScrollClass(opt,$(this));
3231        $(this).data('__nicescroll',nice);
3232      }
3233      ret.push(nice);
3234    });
3235    return (ret.length==1) ? ret[0] : ret;
3236  };
3237
3238  window.NiceScroll = {
3239    getjQuery:function(){return jQuery}
3240  };
3241
3242  if (!$.nicescroll) {
3243   $.nicescroll = new NiceScrollArray();
3244   $.nicescroll.options = _globaloptions;
3245  }
3246
3247})( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.