PageSourceSearch

https://takzetego.pl/wp-content/themes/zox-news/js/scripts.js?ver=5.9.2.4

js takzetego.pl collected 2026-10-09 01:50:03 UTC 123,676 bytes, 3,719 lines download raw bytes

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

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