PageSourceSearch

https://likumi.lv/js/1781779529_lvdd.js

js likumi.lv collected 2026-10-02 02:26:13 UTC 47,375 bytes, 1,155 lines download raw bytes

1(function($){
2  var self = this;
3  var applied_to = [];
4
5  self.return_parsed_data = function(data){
6    if(typeof(data) === "undefined"){
7      return "";
8    }
9    ul_content = "";
10    if(typeof(data) !== "undefined"){
11      for(i = 0; i < data.length; i += 1){
12        var element = data[i]; 
13        var myel = {};
14        
15        /* Kopējam objekta īpašības un to vērtības uz jauno objektu */
16        for (var attr in element) {
17          if (element.hasOwnProperty(attr)) myel[attr] = element[attr];
18        }
19        
20        /* Triks ar HTML simbolu kodēšanu */
21        var el = document.createElement("div");
22        el.innerText = el.textContent = element.content;
23        var li_div_html = element.content;
24        myel.content = el.innerHTML;
25        var ejson = JSON.stringify(myel)
26        if(typeof(element.value) !== "undefined" && typeof(element.content) !== "undefined"){
27          ul_content += "<li><div>"+li_div_html+"</div><div style='display:none;' class='element-data'>"+ejson+"</div></li>";
28        }
29      }
30    }
31    ret = '<ul style="list-style-type:none;margin:0;padding:0;">'+
32             ul_content +
33          '</ul>';
34    return ret;
35  }
36
37  self.init_dropdown = function(p){
38    p.dropdown.mCustomScrollbar({
39       scrollButtons:{
40         enable:true
41       },
42       moseWheel:true,
43       scrollInertia:500
44     });
45
46    if(p.if_one_dont_drop){
47      dlen = $("ul li", p.dropdown).length;
48      if(dlen < 2){
49        arrow = $(".dropdown-arrow", p.dropdown.parent());
50        arrow.css("visibility", "hidden");
51        arrow.parent().css("cursor", "default");
52      }
53      else{
54        arrow = $(".dropdown-arrow", p.dropdown.parent());
55        arrow.css("visibility", "visible");
56        arrow.parent().css("cursor", "pointer");       
57      }
58    }
59
60    $("li", p.dropdown).each(function(){
61      $(this).click(function(event){
62//        console.log($(".element-data", $(this)).text());
63        var el = JSON.parse($(".element-data", $(this)).text());
64        el.over_input = p.dropdown.over_input;
65        el.call_callback_function = true;
66//        console.log('before pick');console.log(el);
67        methods['pick'].apply(p.input, [el]);
68        event.stopPropagation();
69      });
70    });
71  }
72
73  self.scale_dropdown = function(p){
74      dheight = 300;
75      
76      drheight = 32;
77      if(typeof(p.drheight) !== "undefined"){
78        drheight = p.drheight;
79      }
80      
81      if(typeof(p.dheight) !== "undefined"){
82        if(p.dheight !== "auto"){
83          dheight = p.dheight * 1;
84        }
85        else{
86          dheight = p.data.length * drheight;
87          if(typeof(p.dhautomax) !== "undefined" && dheight > p.dhautomax*drheight){
88            dheight = p.dhautomax*drheight;
89          }
90        }
91        
92        if(typeof(p.dhautoplus) !== "undefined"){
93          dheight += p.dhautoplus;
94        }
95      }  
96      
97      if(typeof(p.dropdown) !== "undefined"){
98        p.dropdown.css("height", dheight+"px");
99      }
100  }
101
102  var methods = {
103    init : function(p) { 
104      var me = {
105        self: $(this).get(0)
106      };
107      
108      if(typeof(p.data) === "undefined" || !Array.isArray(p.data)){
109        /* Inicializejam ar tukšu, content ir vajadzīgs teksts, lai stila paddingi un stils darbojas korekti */
110        p.data = [{value:null, content:"<span style='color:transparent;'>Nav v\u0113rtību</span>"}];
111      }
112      
113      scroll_to_selected = false;
114      if(typeof(p.scroll_to_selected) !== "undefined"){
115        scroll_to_selected=p.scroll_to_selected;
116      }
117      me.scroll_to_selected = scroll_to_selected;
118      
119      
120      autowidth = true;      
121      width = 300;
122      if(typeof(p.width) !== "undefined"){
123        width = p.width * 1;
124        autowidth = false;
125      }
126
127      height = 30;
128      if(typeof(p.height) !== "undefined"){
129        height = p.height * 1;
130      }
131      
132      drheight = 32;
133      if(typeof(p.drheight) !== "undefined"){
134        drheight = p.drheight;
135      }
136
137      dheight = 300;
138      if(typeof(p.dheight) !== "undefined"){
139        if(p.dheight !== "auto"){
140          dheight = p.dheight * 1;
141          me.dheight = dheight;
142        }
143        else{
144          me.dheight = "auto";
145          dheight = p.data.length * drheight;
146          if(typeof(p.dhautomax) !== "undefined"){
147            me.dhautomax = p.dhautomax;
148          }
149          if(typeof(p.dhautomax) !== "undefined" && dheight > p.dhautomax*drheight){
150            dheight = p.dhautomax*drheight;
151          }
152        }
153        
154        if(typeof(p.dhautoplus) !== "undefined"){
155          dheight += p.dhautoplus;
156          me.dhautoplus = p.dhautoplus;
157        }
158      }
159      
160      var if_one_dont_drop = false;
161      if(typeof(p.if_one_dont_drop) !== "undefined"){
162        if_one_dont_drop = p.if_one_dont_drop;
163      }
164      
165      dwidth = width + 20;
166      if(typeof(p.dwidth) !== "undefined"){
167        dwidth = p.dwidth*1+20;
168      }
169
170      var select_width = null;
171      if(typeof(p.select_width) !== "undefined"){
172        select_width = p.select_width;
173      }
174
175      var expick = function(){}; /* dummy function */
176      if(typeof(p.pick) !== "undefined"){
177        expick = p.pick;
178      }
179
180      var input = $(this);
181      
182      me.pick = expick;
183      me.select_width = select_width;
184      me.if_one_dont_drop = if_one_dont_drop;
185      me.drheight = drheight;
186//      console.log(me);
187      applied_to.push(me);
188
189//          input.css("border", "1px solid #0f0");
190      input.css("float", "left");
191      input.css("display", "block");
192      input.css("white-space", "nowrap");
193      input.css("overflow", "hidden");
194      input.css("text-overflow", "ellipsis");
195
196      var wrapper = input.wrap("<dl class='lv-dropdown-wrapper' style='padding:0;'><dt/></dl>").parent();
197//          wrapper.css("border", "1px solid #f00");
198      if(autowidth !== true){
199        wrapper.css("width", width+"px");
200      }
201      input.css("maxWidth", "250px");
202      wrapper.css("height", (height-18)+"px");
203      wrapper.css("overflow", "hidden");
204      
205      /*WARNING: lūdzu nemainīt padding/margin verītbas. Vai arī, ja maina ir jāpārbauda visi skati kuros ir dropdowni!!!*/
206      wrapper.css("padding", "9px 10px");
207//      wrapper.css("padding-bottom", "8px");
208      wrapper.css("cursor", "pointer");
209      wrapper.css("background-color", "#fff");
210
211      input.after("<div style='clear:both;'></div>");         
212      input.after("<div class='dropdown-arrow'></div>");
213
214      mleft = $(".dropdown-arrow", input.parent()).css("margin-left");
215      if(mleft !== "auto" && typeof(mleft) !== "undefined"){
216        mleft_num = mleft.substring(0, mleft.length-2)*1;
217      }
218      else{
219        mleft_num = 0;
220      }
221      if(autowidth !== true){
222//        alert(width+":"+mleft_num);
223        input.css("width", (width-14-mleft_num)+"px");
224//        alert("w:"+input.css("width"));
225      }
226
227      wrapper.after('<dd style="position:absolute;height:'+dheight+'px;margin:0;padding:0;color:#fff;background-color:#414142;overflow:hidden;width:'+(dwidth+mleft_num)+'px;z-index:1">'+
228      return_parsed_data(p.data)+'</dd>');
229
230
231
232      var dropdown = $("dd", wrapper.parent());
233      self.init_dropdown({
234        dropdown: dropdown,
235        input: input,
236        if_one_dont_drop: if_one_dont_drop,
237        scroll_to_selected: scroll_to_selected
238      });
239
240
241      var nwrp = wrapper;
242      var doclick = true;
243      wrapper.click(function(event){
244        dropdown = $("dd", nwrp.parent().parent());
245        drecord_count = $("ul li", dropdown).length;
246        if(if_one_dont_drop){
247          doclick = drecord_count > 1;
248        }
249        
250        if(doclick){
251          if(dropdown.css("visibility") != "visible"){
252            methods.show.apply(input, []);
253          }
254          else{
255            methods.hide.apply(input, []);          
256          }
257        }  
258        event.stopPropagation();
259      });
260     
261      var obj = {value:"", content:input.html()};
262//      console.log({obj:obj});
263      if(input.html() == ""){
264//        console.log({p:p});
265        /* Inverss triks ar HTML simbolu kodēšanu */
266        var el = document.createElement("div");
267        el.innerHTML = p.data[0].content;
268        obj = p.data[0]; 
269        if(typeof(el.textContent) !== "undefined"){
270          obj.content = el.textContent;          
271        }
272        else if(typeof(el.innerText) !== "undefined"){
273          obj.content = el.innerText;          
274        }
275//        console.log(el.textContent);
276//        console.log(obj);
277      }
278//      console.log({obj:obj});
279      if(typeof(p.selected) !== "undefined"){
280        if(p.selected !== null){
281          obj = p.selected;
282        }
283      }
284      obj.call_callback_function = false;
285      if(select_width === "auto"){
286        obj.dwidth_auto_resize = true;
287      }
288      methods.pick.apply(input, [obj]);
289      return input;
290    },
291    show : function(p) {
292      var dropdown = $("dd", $(this).parent().parent());
293      dropdown.css("display", "block");
294      dropdown.css("visibility", "visible");
295      var me = $(this).get(0);
296      /* if show me, hide all others */
297      for(i = 0; i < applied_to.length; i += 1){
298        var obj = applied_to[i];
299        if(me != applied_to[i].self){
300          methods.hide.apply(obj.self, []);          
301        }
302      }
303    },
304    hide : function() { 
305//      console.log('HIDE');
306      var dropdown = $("dd", $(this).parent().parent());
307//      dropdown.css("display", "none");
308      dropdown.css("visibility", "hidden");
309    },
310    reload: function(data){
311      var input = $(this);
312      var me = input.get(0);
313      var dropdown = $("dd", $(this).parent().parent());
314      ul = return_parsed_data(data);
315      dropdown.html(ul);
316      myinfo = {};
317      for(i = 0; i < applied_to.length; i += 1){
318        if(me == applied_to[i].self){
319          myinfo = applied_to[i];
320        }
321      }
322      myinfo.dropdown = dropdown;
323      myinfo.data = data;     
324      dropdown.over_input = input;
325      scale_dropdown(myinfo);
326      dropdown.css("visibility", "hidden");
327      dropdown.css("display", "block");           
328      self.init_dropdown({
329        dropdown: dropdown,
330        if_one_dont_drop: myinfo.if_one_dont_drop,
331        scroll_to_selected: myinfo.scroll_to_selected
332      });
333      dropdown.css("visibility", "hidden");
334      dropdown.css("display", "none");            
335    },
336    get_by_val: function(value){
337      var input = $('.mCSB_container > ul > li > .element-data', $(this).parent().parent());
338      var ret = false;
339      
340      input.each(function(index, data){
341        var obj = $(data).html();
342        obj = getJSONObject(obj);
343        if(obj.value == value){
344          ret = obj;
345          return false;
346        }
347      });
348      return ret;
349    },
350    pick: function(e){
351      var input = $(this);
352      if(typeof(e.over_input) !== "undefined"){
353        input = e.over_input;
354      }
355      var me = input.get(0);
356//      console.log('pick'); console.log(e);
357      input.html(e.content);
358//      console.log(e);
359//      console.log(input);
360      methods.hide.apply(input);
361//      console.log($(me).position());
362//      console.log(applied_to[0].self);
363      do_callback = typeof(e.call_callback_function) == "undefined" || e.call_callback_function !== false;
364      do_autopick = typeof(e.dwidth_auto_resize) !== "undefined" && e.dwidth_auto_resize === true;
365      if(do_callback || do_autopick || e.scroll_to_selected){ 
366        for(i = 0; i < applied_to.length; i += 1){
367          if(me == applied_to[i].self){
368//            console.log("found me!");
369//            console.log(applied_to[i].self);
370            obj = applied_to[i];
371            if(obj.select_width !== null && obj.select_width == "auto"){
372//              input.css("width", "auto");
373//              needed_width = input.css("width");
374//              alert(needed_width);
375//              input.css("width", needed_width);
376//              nw = needed_width.substring(0, needed_width.length-2)*1;
377//              mleft = $(".dropdown-arrow", input.parent()).css("margin-left");
378//              console.log("margin-left:"+mleft);
379//              mleft_num = mleft.substring(0, mleft.length-2)*1;
380//              console.log("mleft_num:"+mleft_num);
381//              nw = nw*1;
382//              nw = nw + 14;
383//              alert(nw);
384//              input.parent().css("width", (nw+mleft_num+14)+"px");
385            }
386            
387            if(applied_to[i].scroll_to_selected){
388//              console.log(e);
389              var dati = $(applied_to[i].self).parent().parent().find("dd .mCSB_container ul li div.element-data");
390              var counter = 0;
391              dati.each(function(){
392                counter += 1;
393                var mini_obj = getJSONObject($(this).text());
394                if(e.value == mini_obj.value && e.content==mini_obj.content){
395                  var scroll_to = $(this).parent().position().top;
396                  var dd = $(applied_to[i].self).parents().eq(1).find("dd");
397                  dd.mCustomScrollbar('scrollTo', scroll_to);
398//                  console.log(dd);
399                }
400              });
401            }
402            
403            if(do_callback){
404              obj.pick(e);
405            }  
406            break;
407          }  
408        }
409      }
410    }
411  };
412
413
414  $.fn.lvDropdown = function(method) {
415    if ( methods[method] ) {
416      return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
417    } else if ( typeof method === 'object' || ! method ) {
418      var self = this;
419      $('html').click(function() {
420        self.lvDropdown("hide");
421      });
422      return methods.init.apply( this, arguments );
423    } else {
424      $.error( 'Method ' +  method + ' does not exist on jQuery.lvDropdown' );
425    } 
426  };
427})(jQuery);
428
429/* 
430== malihu jquery custom scrollbars plugin == 
431  Version: 2.1 
432  Author: malihu (http://manos.malihu.gr) 
433  Plugin home: http://manos.malihu.gr/jquery-custom-content-scroller 
434  Licensed under: CC Attribution 3.0
435  Licence link: http://creativecommons.org/licenses/by/3.0/legalcode
436  Download date: 29.10.2012
437*/
438(function($){
439	var methods={
440		init:function(options){
441			var defaults={ 
442				set_width:false, /*optional element width: boolean, pixels, percentage*/
443				set_height:false, /*optional element height: boolean, pixels, percentage*/
444				horizontalScroll:false, /*scroll horizontally: boolean*/
445				scrollInertia:550, /*scrolling inertia: integer (milliseconds)*/
446				scrollEasing:"easeOutCirc", /*scrolling easing: string*/
447				mouseWheel:"auto", /*mousewheel support and velocity: boolean, "auto", integer*/
448				autoDraggerLength:true, /*auto-adjust scrollbar dragger length: boolean*/
449				scrollButtons:{ /*scroll buttons*/
450					enable:false, /*scroll buttons support: boolean*/
451					scrollType:"continuous", /*scroll buttons scrolling type: "continuous", "pixels"*/
452					scrollSpeed:20, /*scroll buttons continuous scrolling speed: integer*/
453					scrollAmount:40 /*scroll buttons pixels scroll amount: integer (pixels)*/
454				},
455				advanced:{
456					updateOnBrowserResize:true, /*update scrollbars on browser resize (for layouts based on percentages): boolean*/
457					updateOnContentResize:false, /*auto-update scrollbars on content resize (for dynamic content): boolean*/
458					autoExpandHorizontalScroll:false /*auto-expand width for horizontal scrolling: boolean*/
459				},
460				callbacks:{
461					onScroll:function(){}, /*user custom callback function on scroll event*/
462					onTotalScroll:function(){}, /*user custom callback function on scroll end reached event*/
463					onTotalScrollOffset:0 /*scroll end reached offset: integer (pixels)*/
464				}
465			},
466			options=$.extend(true,defaults,options);
467			/*check for touch device*/
468			$(document).data("mCS-is-touch-device",false);
469			if(is_touch_device()){
470				$(document).data("mCS-is-touch-device",true);
471			}
472			function is_touch_device(){
473				return !!("ontouchstart" in window) ? 1 : 0;
474			}
475			return this.each(function(){
476				var $this=$(this);
477				/*set element width/height, create markup for custom scrollbars, add classes*/
478				if(options.set_width){
479					$this.css("width",options.set_width);
480				}
481				if(options.set_height){
482					$this.css("height",options.set_height);
483				}
484				if(!$(document).data("mCustomScrollbar-index")){
485					$(document).data("mCustomScrollbar-index","1");
486				}else{
487					var mCustomScrollbarIndex=parseInt($(document).data("mCustomScrollbar-index"));
488					$(document).data("mCustomScrollbar-index",mCustomScrollbarIndex+1);
489				}
490				$this.wrapInner("<div class='mCustomScrollBox' id='mCSB_"+$(document).data("mCustomScrollbar-index")+"' style='position:relative; height:100%; overflow:hidden; max-width:100%;' />").addClass("mCustomScrollbar _mCS_"+$(document).data("mCustomScrollbar-index"));
491				var mCustomScrollBox=$this.children(".mCustomScrollBox");
492				if(options.horizontalScroll){
493					mCustomScrollBox.addClass("mCSB_horizontal").wrapInner("<div class='mCSB_h_wrapper' style='position:relative; left:0; width:999999px;' />");
494					var mCSB_h_wrapper=mCustomScrollBox.children(".mCSB_h_wrapper");
495					mCSB_h_wrapper.wrapInner("<div class='mCSB_container' style='position:absolute; left:0;' />").children(".mCSB_container").css({"width":mCSB_h_wrapper.children().outerWidth(),"position":"relative"}).unwrap();
496				}else{
497					mCustomScrollBox.wrapInner("<div class='mCSB_container' style='position:relative; top:0;' />");
498				}
499				var mCSB_container=mCustomScrollBox.children(".mCSB_container");
500				if(!$(document).data("mCS-is-touch-device")){ /*not touch device - apply custom scrollbars functionality*/
501					mCSB_container.after("<div class='mCSB_scrollTools' style='position:absolute;'><div class='mCSB_draggerContainer' style='position:relative;'><div class='mCSB_dragger' style='position:absolute;'><div class='mCSB_dragger_bar' style='position:relative;'></div></div><div class='mCSB_draggerRail'></div></div></div>");
502					var mCSB_scrollTools=mCustomScrollBox.children(".mCSB_scrollTools"),
503						mCSB_draggerContainer=mCSB_scrollTools.children(".mCSB_draggerContainer"),
504						mCSB_dragger=mCSB_draggerContainer.children(".mCSB_dragger");
505					if(options.horizontalScroll){
506						mCSB_dragger.data("minDraggerWidth",mCSB_dragger.width());
507					}else{
508						mCSB_dragger.data("minDraggerHeight",mCSB_dragger.height());
509					}
510					if(options.scrollButtons.enable){
511						if(options.horizontalScroll){
512							mCSB_scrollTools.prepend("<a class='mCSB_buttonLeft' style='display:block; position:relative;'></a>").append("<a class='mCSB_buttonRight' style='display:block; position:relative;'></a>");
513						}else{
514							mCSB_scrollTools.prepend("<a class='mCSB_buttonUp' style='display:block; position:relative;'></a>").append("<a class='mCSB_buttonDown' style='display:block; position:relative;'></a>");
515						}
516					}
517					/*mCustomScrollBox scrollTop and scrollLeft is always 0 to prevent browser focus scrolling*/
518					mCustomScrollBox.bind("scroll",function(){
519						mCustomScrollBox.scrollTop(0).scrollLeft(0);
520					});
521					/*store element options and update element*/
522					$this.data({
523						"horizontalScroll":options.horizontalScroll,
524						"scrollInertia":options.scrollInertia,
525						"scrollEasing":options.scrollEasing,
526						"mouseWheel":options.mouseWheel,
527						"autoDraggerLength":options.autoDraggerLength,
528						"scrollButtons-enable":options.scrollButtons.enable,
529						"scrollButtons-scrollType":options.scrollButtons.scrollType,
530						"scrollButtons-scrollSpeed":options.scrollButtons.scrollSpeed,
531						"scrollButtons-scrollAmount":options.scrollButtons.scrollAmount,
532						"autoExpandHorizontalScroll":options.advanced.autoExpandHorizontalScroll,
533						"onScroll-Callback":options.callbacks.onScroll,
534						"onTotalScroll-Callback":options.callbacks.onTotalScroll,
535						"onTotalScroll-Offset":options.callbacks.onTotalScrollOffset
536					}).mCustomScrollbar("update");
537					/*window resize fn (for layouts based on percentages)*/
538					if(options.advanced.updateOnBrowserResize){
539						var mCSB_resizeTimeout;
540						$(window).resize(function(){
541							if(mCSB_resizeTimeout){
542								clearTimeout(mCSB_resizeTimeout);
543							}
544							mCSB_resizeTimeout=setTimeout(function(){
545								$this.mCustomScrollbar("update");
546							},150);
547						});
548					}
549				}else{ /*is touch device*/
550					/*check for mobile os/browser not supporting overflow:auto (Android 2.xx)*/
551					var ua=navigator.userAgent;
552					if(ua.indexOf("Android")!=-1){ 
553						var androidversion=parseFloat(ua.slice(ua.indexOf("Android")+8));
554						if(androidversion<3){
555							touchScroll("mCSB_"+$(document).data("mCustomScrollbar-index")); /*non overflow:auto fn*/
556						}else{
557							mCustomScrollBox.css({"overflow":"auto","-webkit-overflow-scrolling":"touch"});
558						}
559					}else{
560						mCustomScrollBox.css({"overflow":"auto","-webkit-overflow-scrolling":"touch"});
561					}
562					mCSB_container.addClass("mCS_no_scrollbar mCS_touch");
563					$this.data({
564						"horizontalScroll":options.horizontalScroll,
565						"scrollInertia":options.scrollInertia,
566						"scrollEasing":options.scrollEasing,
567						"autoExpandHorizontalScroll":options.advanced.autoExpandHorizontalScroll,
568						"onScroll-Callback":options.callbacks.onScroll,
569						"onTotalScroll-Callback":options.callbacks.onTotalScroll,
570						"onTotalScroll-Offset":options.callbacks.onTotalScrollOffset
571					});
572					mCustomScrollBox.scroll(function(){
573						$this.mCustomScrollbar("callbacks",mCustomScrollBox,mCSB_container); /*user custom callback functions*/
574					});
575					/*non overflow:auto fn 
576					(source: http://chris-barr.com/index.php/entry/scrolling_a_overflowauto_element_on_a_touch_screen_device/)*/
577					function touchScroll(id){
578						var el=document.getElementById(id),
579							scrollStartPosY=0,
580							scrollStartPosX=0;
581						document.getElementById(id).addEventListener("touchstart",function(event){
582							scrollStartPosY=this.scrollTop+event.touches[0].pageY;
583							scrollStartPosX=this.scrollLeft+event.touches[0].pageX;
584							/*event.preventDefault(); // Keep this remarked so you can click on buttons and links in the div*/
585						},false);
586						document.getElementById(id).addEventListener("touchmove",function(event){
587							/*These if statements allow the full page to scroll (not just the div) if they are
588							at the top of the div scroll or the bottom of the div scroll
589							The -5 and +5 below are in case they are trying to scroll the page sideways
590							but their finger moves a few pixels down or up.  The event.preventDefault() function
591							will not be called in that case so that the whole page can scroll.*/
592							if((this.scrollTop<this.scrollHeight-this.offsetHeight && this.scrollTop+event.touches[0].pageY<scrollStartPosY-5) || (this.scrollTop!=0 && this.scrollTop+event.touches[0].pageY>scrollStartPosY+5))
593								event.preventDefault();	
594							if((this.scrollLeft<this.scrollWidth-this.offsetWidth && this.scrollLeft+event.touches[0].pageX < scrollStartPosX-5
594) || (this.scrollLeft!=0&&this.scrollLeft+event.touches[0].pageX>scrollStartPosX+5))
595								event.preventDefault();	
596							this.scrollTop=scrollStartPosY-event.touches[0].pageY;
597							this.scrollLeft=scrollStartPosX-event.touches[0].pageX;
598						},false);
599					}
600				}
601				/*content resize fn (for dynamically generated content)*/
602				if(options.advanced.updateOnContentResize){
603					var mCSB_onContentResize;
604					if(options.horizontalScroll){
605						var mCSB_containerOldSize=mCSB_container.outerWidth();
606						if(is_touch_device()){
607							/*disable iOS webkit inertia for smooth scrolling*/
608							mCustomScrollBox.css({"-webkit-overflow-scrolling":"auto"});
609						}
610					}else{
611						var mCSB_containerOldSize=mCSB_container.outerHeight();
612					}
613					mCSB_onContentResize=setInterval(function(){
614						if(options.horizontalScroll){
615							if(options.advanced.autoExpandHorizontalScroll){
616								mCSB_container.css({"position":"absolute","width":"auto"}).wrap("<div class='mCSB_h_wrapper' style='position:relative; left:0; width:999999px;' />").css({"width":mCSB_container.outerWidth(),"position":"relative"}).unwrap();
617							}
618							var mCSB_containerNewSize=mCSB_container.outerWidth();
619						}else{
620							var mCSB_containerNewSize=mCSB_container.outerHeight();
621						}
622						if(mCSB_containerNewSize!=mCSB_containerOldSize){
623							$this.mCustomScrollbar("update");
624							mCSB_containerOldSize=mCSB_containerNewSize;
625						}
626					},300);
627				}
628			});
629		},
630		update:function(){
631			var $this=$(this),
632				mCustomScrollBox=$this.children(".mCustomScrollBox"),
633				mCSB_container=mCustomScrollBox.children(".mCSB_container");
634			if(!$(document).data("mCS-is-touch-device")){
635				mCSB_container.removeClass("mCS_no_scrollbar");
636			}
637			var mCSB_scrollTools=mCustomScrollBox.children(".mCSB_scrollTools"),
638				mCSB_draggerContainer=mCSB_scrollTools.children(".mCSB_draggerContainer"),
639				mCSB_dragger=mCSB_draggerContainer.children(".mCSB_dragger");
640			if($this.data("horizontalScroll")){
641				var mCSB_buttonLeft=mCSB_scrollTools.children(".mCSB_buttonLeft"),
642					mCSB_buttonRight=mCSB_scrollTools.children(".mCSB_buttonRight"),
643					mCustomScrollBoxW=mCustomScrollBox.width();
644				if($this.data("autoExpandHorizontalScroll")){
645					mCSB_container.css({"position":"absolute","width":"auto"}).wrap("<div class='mCSB_h_wrapper' style='position:relative; left:0; width:999999px;' />").css({"width":mCSB_container.outerWidth(),"position":"relative"}).unwrap();
646				}
647				var mCSB_containerW=mCSB_container.outerWidth();
648			}else{
649				var mCSB_buttonUp=mCSB_scrollTools.children(".mCSB_buttonUp"),
650					mCSB_buttonDown=mCSB_scrollTools.children(".mCSB_buttonDown"),
651					mCustomScrollBoxH=mCustomScrollBox.height(),
652					mCSB_containerH=mCSB_container.outerHeight();
653			}
654			if(mCSB_containerH>mCustomScrollBoxH && !$this.data("horizontalScroll") && !$(document).data("mCS-is-touch-device")){ /*content needs vertical scrolling*/
655				mCSB_scrollTools.css("display","block");
656				var mCSB_draggerContainerH=mCSB_draggerContainer.height();
657				/*auto adjust scrollbar dragger length analogous to content*/
658				if($this.data("autoDraggerLength")){
659					var draggerH=Math.round(mCustomScrollBoxH/mCSB_containerH*mCSB_draggerContainerH),
660						minDraggerH=mCSB_dragger.data("minDraggerHeight");
661					if(draggerH<=minDraggerH){ /*min dragger height*/
662						mCSB_dragger.css({"height":minDraggerH});
663					}else if(draggerH>=mCSB_draggerContainerH-10){ /*max dragger height*/
664						var mCSB_draggerContainerMaxH=mCSB_draggerContainerH-10;
665						mCSB_dragger.css({"height":mCSB_draggerContainerMaxH});
666					}else{
667						mCSB_dragger.css({"height":draggerH});
668					}
669					mCSB_dragger.children(".mCSB_dragger_bar").css({"line-height":mCSB_dragger.height()+"px"});
670				}
671				var mCSB_draggerH=mCSB_dragger.height(),
672				/*calculate and store scroll amount*/
673					scrollAmount=(mCSB_containerH-mCustomScrollBoxH)/(mCSB_draggerContainerH-mCSB_draggerH);
674				$this.data("scrollAmount",scrollAmount);
675				/*add scrolling*/
676				$this.mCustomScrollbar("scrolling",mCustomScrollBox,mCSB_container,mCSB_draggerContainer,mCSB_dragger,mCSB_buttonUp,mCSB_buttonDown,mCSB_buttonLeft,mCSB_buttonRight);
677				/*scroll*/
678				var mCSB_containerP=Math.abs(Math.round(mCSB_container.position().top));
679				$this.mCustomScrollbar("scrollTo",mCSB_containerP,{callback:false});
680			}else if(mCSB_containerW>mCustomScrollBoxW && $this.data("horizontalScroll") && !$(document).data("mCS-is-touch-device")){ /*content needs horizontal scrolling*/
681				mCSB_scrollTools.css("display","block");
682				var mCSB_draggerContainerW=mCSB_draggerContainer.width();
683				/*auto adjust scrollbar dragger length analogous to content*/
684				if($this.data("autoDraggerLength")){
685					var draggerW=Math.round(mCustomScrollBoxW/mCSB_containerW*mCSB_draggerContainerW),
686						minDraggerW=mCSB_dragger.data("minDraggerWidth");
687					if(draggerW<=minDraggerW){ /*min dragger height*/
688						mCSB_dragger.css({"width":minDraggerW});
689					}else if(draggerW>=mCSB_draggerContainerW-10){ /*max dragger height*/
690						var mCSB_draggerContainerMaxW=mCSB_draggerContainerW-10;
691						mCSB_dragger.css({"width":mCSB_draggerContainerMaxW});
692					}else{
693						mCSB_dragger.css({"width":draggerW});
694					}
695				}
696				var mCSB_draggerW=mCSB_dragger.width(),
697				/*calculate and store scroll amount*/
698					scrollAmount=(mCSB_containerW-mCustomScrollBoxW)/(mCSB_draggerContainerW-mCSB_draggerW);
699				$this.data("scrollAmount",scrollAmount);
700				/*add scrolling*/
701				$this.mCustomScrollbar("scrolling",mCustomScrollBox,mCSB_container,mCSB_draggerContainer,mCSB_dragger,mCSB_buttonUp,mCSB_buttonDown,mCSB_buttonLeft,mCSB_buttonRight);
702				/*scroll*/
703				var mCSB_containerP=Math.abs(Math.round(mCSB_container.position().left));
704				$this.mCustomScrollbar("scrollTo",mCSB_containerP,{callback:false});
705			}else{ /*content does not need scrolling*/
706				/*unbind events, reset content position, hide scrollbars, remove classes*/
707				mCustomScrollBox.unbind("mousewheel");
708				mCustomScrollBox.unbind("focusin");
709				if($this.data("horizontalScroll")){
710					mCSB_dragger.add(mCSB_container).css("left",0);
711				}else{
712					mCSB_dragger.add(mCSB_container).css("top",0);
713				}
714				mCSB_scrollTools.css("display","none");
715				mCSB_container.addClass("mCS_no_scrollbar");
716			}
717		},
718		scrolling:function(mCustomScrollBox,mCSB_container,mCSB_draggerContainer,mCSB_dragger,mCSB_buttonUp,mCSB_buttonDown,mCSB_buttonLeft,mCSB_buttonRight){
719			var $this=$(this);
720			/*drag scrolling*/
721			if(!mCSB_dragger.hasClass("ui-draggable")){ /*apply drag function once*/
722				if($this.data("horizontalScroll")){
723					var draggableAxis="x";
724				}else{
725					var draggableAxis="y";
726				}
727				mCSB_dragger.draggable({ 
728					axis:draggableAxis,
729					containment:"parent",
730					drag:function(event,ui){
731						$this.mCustomScrollbar("scroll");
732						mCSB_dragger.addClass("mCSB_dragger_onDrag");
733					},
734					stop:function(event,ui){
735						mCSB_dragger.removeClass("mCSB_dragger_onDrag");	
736					}
737				});
738			}
739			mCSB_draggerContainer.unbind("click").bind("click",function(e){
740				if($this.data("horizontalScroll")){
741					var mouseCoord=(e.pageX-mCSB_draggerContainer.offset().left);
742					if(mouseCoord<mCSB_dragger.position().left || mouseCoord>(mCSB_dragger.position().left+mCSB_dragger.width())){
743						var scrollToPos=mouseCoord;
744						if(scrollToPos>=mCSB_draggerContainer.width()-mCSB_dragger.width()){ /*max dragger position is bottom*/
745							scrollToPos=mCSB_draggerContainer.width()-mCSB_dragger.width();
746						}
747						mCSB_dragger.css("left",scrollToPos);
748						$this.mCustomScrollbar("scroll");
749					}
750				}else{
751					var mouseCoord=(e.pageY-mCSB_draggerContainer.offset().top);
752					if(mouseCoord<mCSB_dragger.position().top || mouseCoord>(mCSB_dragger.position().top+mCSB_dragger.height())){
753						var scrollToPos=mouseCoord;
754						if(scrollToPos>=mCSB_draggerContainer.height()-mCSB_dragger.height()){ /*max dragger position is bottom*/
755							scrollToPos=mCSB_draggerContainer.height()-mCSB_dragger.height();
756						}
757						mCSB_dragger.css("top",scrollToPos);
758						$this.mCustomScrollbar("scroll");
759					}
760				}
761			});
762			/*mousewheel scrolling*/
763			if($this.data("mouseWheel")){
764				var mousewheelVel=$this.data("mouseWheel");
765				if($this.data("mouseWheel")==="auto"){
766					mousewheelVel=8;
766 /*default mousewheel velocity*/
767					/*check for safari browser on mac osx to lower mousewheel velocity*/
768					var os=navigator.userAgent;
769					if(os.indexOf("Mac")!=-1 && os.indexOf("Safari")!=-1 && os.indexOf("AppleWebKit")!=-1 && os.indexOf("Chrome")==-1){ 
770						mousewheelVel=1;
771					}
772				}
773				mCustomScrollBox.unbind("mousewheel").bind("mousewheel",function(event,delta){
774					event.preventDefault();
775					var vel=Math.abs(delta*mousewheelVel);
776					if($this.data("horizontalScroll")){
777						var posX=mCSB_dragger.position().left-(delta*vel);
778						mCSB_dragger.css("left",posX);
779						if(mCSB_dragger.position().left<0){
780							mCSB_dragger.css("left",0);
781						}
782						var mCSB_draggerContainerW=mCSB_draggerContainer.width(),
783							mCSB_draggerW=mCSB_dragger.width();
784						if(mCSB_dragger.position().left>mCSB_draggerContainerW-mCSB_draggerW){
785							mCSB_dragger.css("left",mCSB_draggerContainerW-mCSB_draggerW);
786						}
787					}else{
788						var posY=mCSB_dragger.position().top-(delta*vel);
789						mCSB_dragger.css("top",posY);
790						if(mCSB_dragger.position().top<0){
791							mCSB_dragger.css("top",0);
792						}
793						var mCSB_draggerContainerH=mCSB_draggerContainer.height(),
794							mCSB_draggerH=mCSB_dragger.height();
795						if(mCSB_dragger.position().top>mCSB_draggerContainerH-mCSB_draggerH){
796							mCSB_dragger.css("top",mCSB_draggerContainerH-mCSB_draggerH);
797						}
798					}
799					$this.mCustomScrollbar("scroll");
800				});
801			}
802			/*buttons scrolling*/
803			if($this.data("scrollButtons-enable")){
804				if($this.data("scrollButtons-scrollType")==="pixels"){ /*scroll by pixels*/
805					var pixelsScrollTo;
806					if($.browser.msie && parseInt($.browser.version)<9){ /*stupid ie8*/
807						$this.data("scrollInertia",0);
808					}
809					if($this.data("horizontalScroll")){
810						mCSB_buttonRight.add(mCSB_buttonLeft).unbind("click mousedown mouseup mouseout",mCSB_buttonRight_stop,mCSB_buttonLeft_stop);
811						/*scroll right*/
812						mCSB_buttonRight.bind("click",function(e){
813							e.preventDefault();
814							if(!mCSB_container.is(":animated")){
815								pixelsScrollTo=Math.abs(mCSB_container.position().left)+$this.data("scrollButtons-scrollAmount");
816								$this.mCustomScrollbar("scrollTo",pixelsScrollTo);
817							}
818						});
819						/*scroll left*/
820						mCSB_buttonLeft.bind("click",function(e){
821							e.preventDefault();
822							if(!mCSB_container.is(":animated")){
823								pixelsScrollTo=Math.abs(mCSB_container.position().left)-$this.data("scrollButtons-scrollAmount");
824								if(mCSB_container.position().left>=-$this.data("scrollButtons-scrollAmount")){
825									pixelsScrollTo="left";
826								}
827								$this.mCustomScrollbar("scrollTo",pixelsScrollTo);
828							}
829						});
830					}else{
831						mCSB_buttonDown.add(mCSB_buttonUp).unbind("click mousedown mouseup mouseout",mCSB_buttonDown_stop,mCSB_buttonUp_stop);
832						/*scroll down*/
833						mCSB_buttonDown.bind("click",function(e){
834							e.preventDefault();
835							if(!mCSB_container.is(":animated")){
836								pixelsScrollTo=Math.abs(mCSB_container.position().top)+$this.data("scrollButtons-scrollAmount");
837								$this.mCustomScrollbar("scrollTo",pixelsScrollTo);
838							}
839						});
840						/*scroll up*/
841						mCSB_buttonUp.bind("click",function(e){
842							e.preventDefault();
843							if(!mCSB_container.is(":animated")){
844								pixelsScrollTo=Math.abs(mCSB_container.position().top)-$this.data("scrollButtons-scrollAmount");
845								if(mCSB_container.position().top>=-$this.data("scrollButtons-scrollAmount")){
846									pixelsScrollTo="top";
847								}
848								$this.mCustomScrollbar("scrollTo",pixelsScrollTo);
849							}
850						});
851					}
852				}else{ /*continuous scrolling*/
853					if($this.data("horizontalScroll")){
854						mCSB_buttonRight.add(mCSB_buttonLeft).unbind("click mousedown mouseup mouseout",mCSB_buttonRight_stop,mCSB_buttonLeft_stop);
855						/*scroll right*/
856						var mCSB_buttonScrollRight,
857							mCSB_draggerContainerW=mCSB_draggerContainer.width(),
858							mCSB_draggerW=mCSB_dragger.width();
859						mCSB_buttonRight.bind("mousedown",function(e){
860							e.preventDefault();
861							var draggerScrollTo=mCSB_draggerContainerW-mCSB_draggerW;
862							mCSB_buttonScrollRight=setInterval(function(){
863								var scrollToSpeed=Math.abs(mCSB_dragger.position().left-draggerScrollTo)*(100/$this.data("scrollButtons-scrollSpeed"));
864								mCSB_dragger.stop().animate({left:draggerScrollTo},scrollToSpeed,"linear");
865								$this.mCustomScrollbar("scroll");
866							},20);
867						});
868						var mCSB_buttonRight_stop=function(e){
869							e.preventDefault();
870							clearInterval(mCSB_buttonScrollRight);
871							mCSB_dragger.stop();
872						}
873						mCSB_buttonRight.bind("mouseup mouseout",mCSB_buttonRight_stop);
874						/*scroll left*/
875						var mCSB_buttonScrollLeft;
876						mCSB_buttonLeft.bind("mousedown",function(e){
877							e.preventDefault();
878							var draggerScrollTo=0;
879							mCSB_buttonScrollLeft=setInterval(function(){
880								var scrollToSpeed=Math.abs(mCSB_dragger.position().left-draggerScrollTo)*(100/$this.data("scrollButtons-scrollSpeed"));
881								mCSB_dragger.stop().animate({left:draggerScrollTo},scrollToSpeed,"linear");
882								$this.mCustomScrollbar("scroll");
883							},20);
884						});	
885						var mCSB_buttonLeft_stop=function(e){
886							e.preventDefault();
887							clearInterval(mCSB_buttonScrollLeft);
888							mCSB_dragger.stop();
889						}
890						mCSB_buttonLeft.bind("mouseup mouseout",mCSB_buttonLeft_stop);
891					}else{
892						mCSB_buttonDown.add(mCSB_buttonUp).unbind("click mousedown mouseup mouseout",mCSB_buttonDown_stop,mCSB_buttonUp_stop);
893						/*scroll down*/
894						var mCSB_buttonScrollDown,
895							mCSB_draggerContainerH=mCSB_draggerContainer.height(),
896							mCSB_draggerH=mCSB_dragger.height();
897						mCSB_buttonDown.bind("mousedown",function(e){
898							e.preventDefault();
899							var draggerScrollTo=mCSB_draggerContainerH-mCSB_draggerH;
900							mCSB_buttonScrollDown=setInterval(function(){
901								var scrollToSpeed=Math.abs(mCSB_dragger.position().top-draggerScrollTo)*(100/$this.data("scrollButtons-scrollSpeed"));
902								mCSB_dragger.stop().animate({top:draggerScrollTo},scrollToSpeed,"linear");
903								$this.mCustomScrollbar("scroll");
904							},20);
905						});
906						var mCSB_buttonDown_stop=function(e){
907							e.preventDefault();
908							clearInterval(mCSB_buttonScrollDown);
909							mCSB_dragger.stop();
910						}
911						mCSB_buttonDown.bind("mouseup mouseout",mCSB_buttonDown_stop);
912						/*scroll up*/
913						var mCSB_buttonScrollUp;
914						mCSB_buttonUp.bind("mousedown",function(e){
915							e.preventDefault();
916							var draggerScrollTo=0;
917							mCSB_buttonScrollUp=setInterval(function(){
918								var scrollToSpeed=Math.abs(mCSB_dragger.position().top-draggerScrollTo)*(100/$this.data("scrollButtons-scrollSpeed"));
919								mCSB_dragger.stop().animate({top:draggerScrollTo},scrollToSpeed,"linear");
920								$this.mCustomScrollbar("scroll");
921							},20);
922						});	
923						var mCSB_buttonUp_stop=function(e){
924							e.preventDefault();
925							clearInterval(mCSB_buttonScrollUp);
926							mCSB_dragger.stop();
927						}
928						mCSB_buttonUp.bind("mouseup mouseout",mCSB_buttonUp_stop);
929					}
930				}
931			}
932			/*scrolling on element focus (e.g. via TAB key)*/
933			mCustomScrollBox.unbind("focusin").bind("focusin",function(){
934				mCustomScrollBox.scrollTop(0).scrollLeft(0);
935				var focusedElem=$(document.activeElement);
936				if(focusedElem.is("input,textarea,select,button,a[tabindex],area,object")){
937					if($this.data("horizontalScroll")){
938						var mCSB_containerX=mCSB_container.position().left,
939							focusedElemX=focusedElem.position().left,
940							mCustomScrollBoxW=mCustomScrollBox.width(),
941							focusedElemW=focusedElem.outerWidth();
942						if(mCSB_containerX+focusedElemX>=0 && mCSB_containerX+focusedElemX<=mCustomScrollBoxW-focusedElemW){
943							/*just focus...*/
944						}else{ /*scroll, then focus*/
945							var moveDragger=focusedElemX/$this.data("scrollAmount");
946							if(moveDragger>=mCSB_draggerContainer.width()-mCSB_dragger.width()){ /*max dragger position is bottom*/
947								moveDragger=mCSB_draggerContainer.width()-mCSB_dragger.width();
948							}
949							mCSB_dragger.css("left",moveDragger);
950							$this.mCustomScrollbar("scroll");
951						}
952					}else{
953						var mCSB_containerY=mCSB_container.position().top,
954							focusedElemY=focusedElem.position().top,
955							mCustomScrollBoxH=mCustomScrollBox.height(),
956							focusedElemH=focusedElem.outerHeight();
957						if(mCSB_containerY+focusedElemY>=0 && mCSB_containerY+focusedElemY<=mCustomScrollBoxH-focusedElemH){
958							/*just focus...*/
959						}else{ /*scroll, then focus*/
960							var moveDragger=focusedElemY/$this.data("scrollAmount");
961							if(moveDragger>=mCSB_draggerContainer.height()-mCSB_dragger.height()){ /*max dragger position is bottom*/
962								moveDragger=mCSB_draggerContainer.height()-mCSB_dragger.height();
963							}
964							mCSB_dragger.css("top",moveDragger);
965							$this.mCustomScrollbar("scroll");
966						}
967					}
968				}
969			});
970		},
971		scroll:function(updated){
972			var $this=$(this),
973				mCSB_dragger=$this.find(".mCSB_dragger"),
974				mCSB_container=$this.find(".mCSB_container"),
975				mCustomScrollBox=$this.find(".mCustomScrollBox");
976			if($this.data("horizontalScroll")){
977				var draggerX=mCSB_dragger.position().left,
978					targX=-draggerX*$this.data("scrollAmount"),
979					thisX=mCSB_container.position().left,
980					posX=Math.round(thisX-targX);
981			}else{
982				var draggerY=mCSB_dragger.position().top,
983					targY=-draggerY*$this.data("scrollAmount"),
984					thisY=mCSB_container.position().top,
985					posY=Math.round(thisY-targY);
986			}
987			if($.browser.webkit){ /*fix webkit zoom and jquery animate*/
988				var screenCssPixelRatio=(window.outerWidth-8)/window.innerWidth,
989					isZoomed=(screenCssPixelRatio<.98 || screenCssPixelRatio>1.02);
990			}
991			if($this.data("scrollInertia")===0 || isZoomed){
992				if($this.data("horizontalScroll")){
993					mCSB_container.css("left",targX);
994				}else{
995					mCSB_container.css("top",targY);
996				}
997				if(!updated){
998					$this.mCustomScrollbar("callbacks",mCustomScrollBox,mCSB_container); /*user custom callback functions*/
999				}
1000			}else{
1001				if($this.data("horizontalScroll")){
1002					mCSB_container.stop().animate({left: "-="+posX},$this.data("scrollInertia"),$this.data("scrollEasing"),function(){
1003						if(!updated){
1004							$this.mCustomScrollbar("callbacks",mCustomScrollBox,mCSB_container); /*user custom callback functions*/
1005						}
1006					});
1007				}else{
1008					mCSB_container.stop().animate({top: "-="+posY},$this.data("scrollInertia"),$this.data("scrollEasing"),function(){
1009						if(!updated){
1010							$this.mCustomScrollbar("callbacks",mCustomScrollBox,mCSB_container); /*user custom callback functions*/
1011						}
1012					});
1013				}
1014			}
1015		},
1016		scrollTo:function(scrollTo,options){
1017			var defaults={
1018				moveDragger:false,
1019				callback:true
1020			},
1021				options=$.extend(defaults,options),
1022				$this=$(this),
1023				scrollToPos,
1024				mCustomScrollBox=$this.find(".mCustomScrollBox"),
1025				mCSB_container=mCustomScrollBox.children(".mCSB_container");
1026			if(!$(document).data("mCS-is-touch-device")){
1027				var mCSB_draggerContainer=$this.find(".mCSB_draggerContainer"),
1028					mCSB_dragger=mCSB_draggerContainer.children(".mCSB_dragger");
1029			}
1030			var targetPos;
1031			if(scrollTo){
1032				if(typeof(scrollTo)==="number"){ /*if integer, scroll by number of pixels*/
1033					if(options.moveDragger){ /*scroll dragger*/
1034						scrollToPos=scrollTo;
1035					}else{ /*scroll content by default*/
1036						targetPos=scrollTo;
1037						scrollToPos=Math.round(targetPos/$this.data("scrollAmount"));
1038					}
1039				}
1039else if(typeof(scrollTo)==="string"){ /*if string, scroll by element position*/
1040					var target;
1041					if(scrollTo==="top"){ /*scroll to top*/
1042						target=0;
1043					}else if(scrollTo==="bottom" && !$this.data("horizontalScroll")){ /*scroll to bottom*/
1044						target=mCSB_container.outerHeight()-mCustomScrollBox.height();
1045					}else if(scrollTo==="left"){ /*scroll to left*/
1046						target=0;
1047					}else if(scrollTo==="right" && $this.data("horizontalScroll")){ /*scroll to right*/
1048						target=mCSB_container.outerWidth()-mCustomScrollBox.width();
1049					}else if(scrollTo==="first"){ /*scroll to first element position*/
1050						target=$this.find(".mCSB_container").find(":first");
1051					}else if(scrollTo==="last"){ /*scroll to last element position*/
1052						target=$this.find(".mCSB_container").find(":last");
1053					}else{ /*scroll to element position*/
1054						target=$this.find(scrollTo);
1055					}
1056					if(target.length===1){ /*if such unique element exists, scroll to it*/
1057						if($this.data("horizontalScroll")){
1058							targetPos=target.position().left;
1059						}else{
1060							targetPos=target.position().top;
1061						}
1062						if($(document).data("mCS-is-touch-device")){
1063							scrollToPos=targetPos;
1064						}else{
1065							scrollToPos=Math.ceil(targetPos/$this.data("scrollAmount"));
1066						}
1067					}else{
1068						scrollToPos=target;
1069					}
1070				}
1071				/*scroll to*/
1072				if($(document).data("mCS-is-touch-device")){ /*is touch device*/
1073					if($this.data("horizontalScroll")){
1074						mCustomScrollBox.stop().animate({scrollLeft:scrollToPos},$this.data("scrollInertia"),$this.data("scrollEasing"),function(){
1075							if(options.callback){
1076								$this.mCustomScrollbar("callbacks",mCustomScrollBox,mCSB_container);
1077							}
1078						});
1079					}else{
1080						mCustomScrollBox.stop().animate({scrollTop:scrollToPos},$this.data("scrollInertia"),$this.data("scrollEasing"),function(){
1081							if(options.callback){
1082								$this.mCustomScrollbar("callbacks",mCustomScrollBox,mCSB_container);
1083							}
1084						});
1085					}
1086				}else{ /*not touch device*/
1087					if($this.data("horizontalScroll")){
1088						if(scrollToPos>=mCSB_draggerContainer.width()-mCSB_dragger.width()){ /*max dragger position is bottom*/
1089							scrollToPos=mCSB_draggerContainer.width()-mCSB_dragger.width();
1090						}
1091						mCSB_dragger.css("left",scrollToPos);
1092					}else{
1093						if(scrollToPos>=mCSB_draggerContainer.height()-mCSB_dragger.height()){ /*max dragger position is bottom*/
1094							scrollToPos=mCSB_draggerContainer.height()-mCSB_dragger.height();
1095						}
1096						mCSB_dragger.css("top",scrollToPos);
1097					}
1098					if(options.callback){
1099						$this.mCustomScrollbar("scroll");
1100					}else{
1101						$this.mCustomScrollbar("scroll",true);
1102					}
1103				}
1104					
1105			}
1106		},
1107		callbacks:function(mCustomScrollBox,mCSB_container){
1108			var $this=$(this);
1109			if(!$(document).data("mCS-is-touch-device")){ /*not touch device*/
1110				if($this.data("horizontalScroll")){
1111					var mCSB_containerX=Math.round(mCSB_container.position().left);
1112					if(mCSB_containerX<0 && mCSB_containerX<=mCustomScrollBox.width()-mCSB_container.outerWidth()+$this.data("onTotalScroll-Offset")){
1113						$this.data("onTotalScroll-Callback").call();
1114					}else{
1115						$this.data("onScroll-Callback").call();
1116					}
1117				}else{
1118					var mCSB_containerY=Math.round(mCSB_container.position().top);
1119					if(mCSB_containerY<0 && mCSB_containerY<=mCustomScrollBox.height()-mCSB_container.outerHeight()+$this.data("onTotalScroll-Offset")){
1120						$this.data("onTotalScroll-Callback").call();
1121					}else{
1122            if($this && $this.data && $this.data("onScroll-Callback")){
1123						  $this.data("onScroll-Callback").call();
1124            }
1125					}
1126				}
1127			}else{ /*is touch device*/
1128				if($this.data("horizontalScroll")){
1129					var mCustomScrollBoxX=Math.round(mCustomScrollBox.scrollLeft());
1130					if(mCustomScrollBoxX>0 && mCustomScrollBoxX>=mCSB_container.outerWidth()-$this.width()-$this.data("onTotalScroll-Offset")){
1131						$this.data("onTotalScroll-Callback").call();
1132					}else{
1133						$this.data("onScroll-Callback").call();
1134					}
1135				}else{
1136					var mCustomScrollBoxY=Math.round(mCustomScrollBox.scrollTop());
1137					if(mCustomScrollBoxY>0 && mCustomScrollBoxY>=mCSB_container.outerHeight()-$this.height()-$this.data("onTotalScroll-Offset")){
1138						$this.data("onTotalScroll-Callback").call();
1139					}else{
1140						$this.data("onScroll-Callback").call();
1141					}
1142				}
1143			}
1144		}
1145	}
1146	$.fn.mCustomScrollbar=function(method){
1147		if(methods[method]){
1148			return methods[method].apply(this,Array.prototype.slice.call(arguments,1
1148));
1149		}else if(typeof method==="object" || !method){
1150			return methods.init.apply(this,arguments);
1151		}else{
1152			$.error("Method "+method+" does not exist");
1153		}
1154	};
1155})(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.