PageSourceSearch

https://streetpainting.net/js/jquery.nicescroll.js

js streetpainting.net collected 2026-10-10 00:42:16 UTC 93,177 bytes, 2,701 lines download raw bytes

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

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.