PageSourceSearch

https://bargainsaverusa.com/oc-content/themes/beta/js/global.js?v=20261008011722

js bargainsaverusa.com collected 2026-10-08 08:17:49 UTC 48,153 bytes, 1,467 lines download raw bytes

1$(document).ready(function() {
2
3  // ITEM RATING
4  $('body').on('click', '.is-rating-item', function(e) {
5    e.preventDefault();
6    $('input[name="rating"]').val($(this).attr('data-value'));
7    $('.comment-rating-selected').text('(' + $(this).attr('data-value') + ' of 5)');
8    $(this).parent().find('i.is-rating-item').addClass('fill');
9    $(this).nextAll('i.is-rating-item').removeClass('fill');
10  });
11
12  // REUPLOAD PLUGIN ATTRIBUTES FOR CATEGORIES ON MOBILE SEARCH PAGE
13  $('body').on('change', '.search-mobile-filter-box input[name="sCategory"]', function(e) {
14    var sidebar = $('.search-mobile-filter-box form');
15    var ajaxSearchUrl = baseDir + "index.php?" + sidebar.serialize();
16    
17    $('.sidehook').addClass('loading');
18
19    $.ajax({
20      url: ajaxSearchUrl,
21      type: "GET",
22      success: function(response){
23        var length = response.length;
24
25        var sidehook = $(response).contents().find('.sidehook').html();
26
27        if(sidehook === undefined) {
28          $('.search-mobile-filter-box .sidehook').remove();
29          return false;
30        }
31
32        if (!$('.search-mobile-filter-box .sidehook').length) {
33          $('.filter .wrap .box').last().after('<div class="box sidehook"></div>');
34        }
35
36        $('.search-mobile-filter-box .sidehook').html(sidehook).removeClass('loading');
37
38      }
39    });
40  });
41
42
43  // OPEN SEARCH BOX ON MOBILE
44  $('body').on('click', 'a#m-search', function(e) {
45    e.preventDefault();
46
47    if($(this).hasClass('opened')) {
48      $(this).removeClass('opened');
49      $('#menu-search').css('opacity', 1).css('top', '60px').animate({opacity: 0, top:'0px'} , 300, function() { $('#menu-search').hide(0); });
50
51    } else {
52      $(this).addClass('opened')
53      $('#menu-search').show(0).css('opacity', 0).css('top', '0px').animate({ opacity: 1, top:'60px'}, 300);
54
55      if($('#m-options').hasClass('opened')) {
56        $('#m-options').click();
57      }
58
59    }
60  });
61
62
63  // DISABLE LINKS SEARCH ON MOBILE AND REPLACE WITH "CHECKBOX" LIKE
64  $('body').on('click', '.search-mobile-filter-box a', function(e) {
65    e.preventDefault();
66
67    var inptName = $(this).attr('data-name');
68    var inptVal = $(this).attr('data-val');
69 
70    $('[name="' + inptName + '"]').val(inptVal);
71
72    $(this).parent().find('a').removeClass('active');
73    $(this).addClass('active');
74
75  });
76
77
78  // SHOW PHONE CONTACT INFORMATION ON ITEM PAGE ON MOBILE
79  $('body').on('click', '.mobile-item.item-phone', function(e) {
80    e.preventDefault();
81 
82    $('.mobile-item-data').fadeToggle(300);
83    
84    if($(this).find('i').hasClass('fa-phone')) {
85      $(this).find('i').removeClass('fa-phone').addClass('fa-times');
86    } else {
87      $(this).find('i').addClass('fa-phone').removeClass('fa-times');
88    }
89  });
90
91
92  // COPY PHONE NUMBER
93  $('body').on('click', 'a.copy-number', function(e) {
94    e.preventDefault();
95
96    var inpt = $('<input class="just-sec"/>');
97    $('body').append(inpt);
98    inpt.val($(this).attr('href')).select();
99    document.execCommand('copy');
100    inpt.remove();
101    $(this).text($(this).attr('data-done'));
102  });
103
104
105  // ADD ICON TO USER MENU IF MISSING
106  $('ul.user_menu li a').each(function() {
107    if(!$(this).find('i').length) {
108      $(this).prepend('<i class="fa fa-folder-o"></i>');
109    }
110  });
111
112
113  // SCROLL - HEADER BORDER & MOBILE POST BUTTON ON HOME
114  $(window).scroll(function(e) {
115    var scroll = $(window).scrollTop();
116    
117    if(scroll <= 0) {
118      $('header').css('border-bottom-color', '#fff');
119    } else {
120      $('header').css('border-bottom-color', '#ccc');
121    }
122
123    if(scroll <= 500) {
124      $('.mobile-post-wrap').fadeOut(300);
125    } else {
126      $('.mobile-post-wrap').fadeIn(300);
127    }
128  });
129
130
131  // TABS FUNCTIONALITY ON ITEM PAGE
132  $('body').on('click', '.main-head a', function(e) {
133    e.preventDefault();
134
135    if($(this).hasClass('active')) {
136      return false;
137    }
138
139    if($(this).hasClass('tab-img')) {
140      $('.main-data .loc').hide(0);
141      $('.main-data .img').show(0);
142    } else {
143      $('.main-data .img').hide(0);
144      $('.main-data .loc').show(0);
145
146      if(typeof osmMap !== 'undefined') { 
147        osmMap.invalidateSize();
148      }
149
150    }
151
152    $('.main-head a').removeClass('active');
153    $(this).addClass('active');
154  });
155
156
157  // TOP PAGE LOADER
158  $(document).ajaxStart(function() {
159    Pace.restart();
160  });
161
162  $('body').on('click', 'a.alert-notify', function(e) {
163    e.preventDefault();
164    $('.alert-box').slideToggle(200);
165  });
166
167
168  $('body').on('click', '.cat-confirm, .loc-confirm', function(e) {
169    e.preventDefault();
170    $(this).closest('.shower').fadeOut(200);
171    $(this).closest('.cat-picker').find('input.term3').removeClass('open');
172    $(this).closest('.loc-picker').find('input.term2').removeClass('open');
173  });
174
175
176  // CATEGORY PICKER SMART
177  $('body').on('click', '.cat-tab .elem', function(e) {
178    e.preventDefault();
179    var elem = $(this);
180    var shower = $(this).closest('.cat-picker').find('.shower');
181
182    shower.find('.cat-tab:not(.root)').each(function() {
183      if($(this).attr('data-level') > elem.closest('.cat-tab').attr('data-level')) {
184        $(this).removeClass('active');
185        $(this).find('.elem').removeClass('active');
186      } 
187    });
188
189    //if(!elem.hasClass('active') && !elem.hasClass('blank')) {
190    if(!elem.hasClass('blank')) {
191      shower.find('.cat-tab[data-parent="' + elem.attr('data-category') + '"]').addClass('active');
192    }
193
194
195    //var boxCols = parseFloat(shower.find('.cat-tab[data-parent="' + elem.attr('data-category') + '"]').attr('data-level'))-1;
196    var boxCols = parseFloat(shower.find('.cat-tab.active').last().attr('data-level'))-1;
197    shower.find('.wrapper').attr('data-columns', boxCols);
198
199
200    $('input[name="sCategory"], input[name="catId"]').val($(this).attr('data-category'));
201
202    if(!$(this).closest('.search-mobile-filter-box').length) {
203      $('input[name="sCategory"], input[name="catId"]').change();
204    } else {
205      $('.search-mobile-filter-box form input[name="sCategory"]').change();
206    }
207
208    $(this).siblings().removeClass('active');
209    $(this).addClass('active');
210
211    $(this).closest('.cat-picker').find('input.term3').val($(this).text());
212   
213  });
214
215
216
217
218  // LATEST SEARCH BOX
219  var delayQuery = (function(){
220    var timer = 0;
221    return function(callback, ms){
222      clearTimeout (timer);
223      timer = setTimeout(callback, ms);
224    };
225  })();
226
227  $('body').on('click', '.query-picker .pattern', function() {
228    if(!$('.query-picker .shower .option').length) {
229      $(this).keypress();
230    } else {
231      if(!$(this).hasClass('open')) {
232        $(this).closest('.query-picker').find('.shower').show(0).css('opacity', 0).css('margin-top', '30px').css('margin-bottom', '-30px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} , 300);
233        $(this).addClass('open');
234        $(this).closest('.line1').addClass('open');
235      }
236    }
237  });
238
239
240
241  // AJAX LOCATION SMART
242  $('body').on('click', '.loc-tab .elem', function(e) {
243    e.preventDefault();
244
245    if(!$(this).hasClass('active') && !$(this).hasClass('city')) {
246      var elem = $(this);
247      var shower = $(this).closest('.loc-picker').find('.shower');
248
249      elem.addClass('loading');
250
251      if(elem.hasClass('region')) {
252        elem.closest('.loc-picker').find('.city-tab').addClass('loading');
253      } else if (elem.hasClass('country')) {
254        elem.closest('.loc-picker').find('.region-tab').addClass('loading');
255        elem.closest('.loc-picker').find('.city-tab').html('');
256      }
257
258      $.ajax({
259        type: "GET",
260        url: baseAjaxUrl + "&ajaxLoc2=1&country=" + elem.attr('data-country') + "&region=" + elem.attr('data-region') + "&city=" + elem.attr('data-city'),
261        success: function(data) {
262          //console.log(data);
263
264          if(elem.attr('data-region') != '') {
265            shower.find('.city-tab').replaceWith(data);
266          } else if(elem.attr('data-country') != '') {
267            shower.find('.region-tab').replaceWith(data);
268          }
269
270          elem.siblings().removeClass('active');
271          elem.addClass('active').removeClass('loading');
272
273        }
274      });
275    }
276
277    if($(this).hasClass('active')) {
278      if($(this).hasClass('country')) {
279        $(this).closest('.shower').find('.elem.region').removeClass('active');
280        $(this).closest('.shower').find('.elem.city').removeClass('active');
281
282      } else if($(this).hasClass('region')) {
283        $(this).closest('.shower').find('.elem.city').removeClass('active');
284
285      }
286    }
287
288
289    if($(this).hasClass('city')) {
290      $(this).parent().find('.elem').removeClass('active');
291      $(this).addClass('active');
292    }
293
294     $('input[name="sCountry"], input[name="countryId"]').val($(this).attr('data-country'));
295     $('input[name="sRegion"], input[name="regionId"]').val($(this).attr('data-region'));
296     $('input[name="sCity"], input[name="cityId"]').val($(this).attr('data-city'));
297
298     if($('body#body-search').length) {
299       $('input[name="locUpdate"]').change();
300     }
301 
302     $(this).closest('.loc-picker').find('input.term2').val($(this).text());
303   
304  });
305
306
307
308
309  // QUERY PICKER - LIVE ITEM SEARCH ON QUERY WRITTING
310  $('body').on('keyup keypress', '.query-picker .pattern', function(e) {
311    delayQuery(function(){
312      var min_length = 1;
313      var elem = $(e.target);
314      var query = encodeURIComponent(elem.val());
315      var queryOriginal = elem.val();
316
317      var block = elem.closest('.query-picker');
318      var shower = elem.closest('.query-picker').find('.shower');
319
320      //shower.html('');
321
322      if(query.length >= min_length) {
323        $.ajax({
324          type: "POST",
325          url: baseAjaxUrl + "&ajaxQuery=1&pattern=" + query,
326          dataType: 'json',
327          success: function(data) {
328            shower.html('');
329
330            var length = data.length;
331            var result = '';
332
333            for(key in data) {
334              if(!shower.find('div[data-hash="' + data[key].hash + '"]').length) {
335
336                result += '<div class="option query" data-hash="' + data[key].string_hash + '">' + data[key].string_format + '</div>';
337              }
338            }
339
340            if(length <= 0) {
341              result += '<div class="option query" data-hash="blank"><b>' + queryOriginal + '</b></div>';
342            }
343
344            shower.html(result);
345
346            if(!elem.hasClass('open')) {
347              shower.show(0).css('opacity', 0).css('margin-top', '30px').css('margin-bottom', '-30px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} , 300);
348              elem.addClass('open');
349              elem.closest('.line1').addClass('open');
350            }
351          }
352        });
353      } else {
354        shower.html('');
355
356        if(elem.hasClass('open') && queryOriginal != '') {
357          shower.hide(0);
358          elem.removeClass('open');
359          elem.closest('.line1').removeClass('open');
360        }
361      }
362    }, 100);
363  });
364
365
366  // QUERY PICKER - WHEN CLICK OUTSIDE LOCATION PICKER, HIDE SELECTION
367  $(document).mouseup(function (e){
368    var container = $('.query-picker');
369
370    if(!container.is(e.target) && container.has(e.target).length === 0) {
371      container.find('.shower').fadeOut(0);
372      container.find('.pattern').removeClass('open');
373      container.closest('.line1').removeClass('open');
374    }
375  });
376
377
378  // QUERY PICKER - PICK OPTION
379  $(document).on('click', '.query-picker .shower .option', function(e){
380    $('.query-picker .pattern').removeClass('open');
381    $('.query-picker .shower').fadeOut(0);
382    $('.query-picker .pattern').val($(this).text());
383    $('.query-picker').closest('.line1').removeClass('open');
384  });
385
386
387  // QUERY PICKER - OPEN ON CLICK IF NEEDED
388  $(document).on('click', '.query-picker .pattern', function(e){
389    if(!$(this).hasClass('open') && $(this).val() != '' && $(this).closest('.query-picker').find('.shower .option').length) {
390      $(this).closest('.query-picker').find('.shower').show(0).css('opacity', 0).css('margin-top', '30px').css('margin-bottom', '-30px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} , 300);
391      $(this).addClass('open');
392      $(this).closest('.line1').addClass('open');
393    }
394  });
395
396
397  // ARROW CLICK OPEN BOX
398  $(document).on('click', '#location-picker .fa-angle-down', function(e){
399    $(this).siblings('input[type="text"]').click();
400  });
401
402
403  // FANCYBOX - LISTING PREVIEW
404  $(document).on('click', '.simple-prod .preview:not(.disabled)', function(e){
405    e.preventDefault();
406    var url = this.href;
407
408    var maxWidth = 680;
409    var windowsWidth = parseInt($(window).outerWidth()) - 40;
410    var windowsHeight = parseInt($(window).outerHeight()) - 40;
411
412    if(windowsWidth > maxWidth) {
413      windowsWidth = maxWidth;
414    }
415
416    if(jqueryVersion == '1') {
417      if (!!$.prototype.fancybox) {
418        $.fancybox({
419          'padding': 0,
420          'width': windowsWidth,
421          'height': windowsHeight,
422          'scrolling': 'yes',
423          'wrapCSS': 'imgviewer',
424          'type': 'iframe',
425          'href': url
426        });
427      }
428    } else {
429      if (!!$.prototype.fancybox) {
430        windowsWidth = windowsWidth.toString() + 'px';
431        windowsHeight = windowsHeight.toString() + 'px';
432        
433        $.fancybox.open({
434          toolbar : true,
435          type: 'iframe',
436          src: url,
437          baseClass: 'imgviewer',
438          iframe: {
439            css: {
440              width : windowsWidth,
441              height : windowsHeight,
442              padding: 0
443            }
444          }
445        });
446      }      
447    }
448  });
449
450
451  // Handle no pictures
452  $(document).on('click', '.orange-but.open-image.disabled', function(e){
453    e.preventDefault();
454    return false;
455  });
456
457
458
459
460  // HOME SEARCH - LOCATION PICK AVOID EMPTY
461  //$(document).one('submit', 'form#home-form, form#search-form', function(e){
462  $(document).one('submit', 'form#home-form', function(e){
463    if(locationPick == "1" && 1==2) {
464      e.preventDefault();
465
466      if($(this).find('input.term').val() != '' && $(this).find('input[name="sCity"]') == '' && $(this).find('input[name="sRegion"]') == '' && $(this).find('input[name="sCountry"]') == '') {
467        if($(this).find('.shower .option:not(.service):not(.info)').length) {
468          $(this).find('.shower .option:not(.service):not(.info)').first().click();
469        }
470      }
471
472      $(this).submit();
473    }
474  });
475
476
477  // MASONRY - CREATE GRID WHEN IMAGES HAS DIFFERENT SIZE (height)
478  if(betMasonry == "1") {
479    var $grid = $('.products .prod-wrap, #search-items .products, .products .wrap').masonry({
480      itemSelector: '.simple-prod'
481    });
482
483    $grid.imagesLoaded().progress(function(){
484      $grid.masonry('layout');
485    });
486  }
487
488
489  // LAZY LOADING OF IMAGES
490  if(betLazy == "1" && betMasonry == "0" ) {
491    $('img.lazy').Lazy({
492      appendScroll: window,
493      scrollDirection: 'both',
494      effect: 'fadeIn',
495      effectTime: 300,
496      afterLoad: function(element) {
497        setTimeout(function() {
498          element.css('transition', '0.2s');
499        }, 300);
500      }
501    });
502  }
503
504
505  // PRINT ITEM
506  $('body').on('click', 'a.print', function(e){
507    e.preventDefault();
508    window.print();
509  });
510
511
512  // IF LABEL CONTAINS LINK, OPEN IT WITHOUT ANY ACTION
513  $(document).on('click', 'label a', function(e){
514    if($(this).attr('href') != '#') {
515      var newWin = window.open($(this).attr('href'), '_blank');
516      newWin.focus();
517      return false;
518    }
519  });
520
521
522  // ENSURE ATTRIBUTE PLUGIN LABEL CLICK WORKS CORRECTLY
523  $(document).on('click', 'input[type="checkbox"]:not([id^="bpr-cat-"]) + label', function(e){
524    var inpId = $(this).attr('for');
525
526    if(inpId != '') {
527      var checkBox = $('input[type="checkbox"][id="' + inpId + '"]');
528
529      if(!checkBox.length) {
530        e.preventDefault();
531        checkBox = $('input[type="checkbox"][name="' + inpId + '"]');
532      }
533
534      if(!checkBox.length) {
535        e.preventDefault();
536        checkBox = $(this).parent().find('input[type="checkbox"]');
537      }
538
539      if(checkBox.length) {
540        e.preventDefault();
541        checkBox.prop('checked', !checkBox.prop('checked'));
542      }
543    }
544  });
545
546
547  // ENSURE ATTRIBUTE PLUGIN LABEL CLICK WORKS CORRECTLY
548  $(document).on('click', '.atr-radio label[for^="atr_"]', function(e){
549    var checkBox = $('input[type="radio"][name="' + $(this).attr('for') + '"]');
550
551    if(checkBox.length) {
552      e.preventDefault();
553      $(this).closest('ul.atr-ul-radio').find('input[type="radio"]:checked').not(this).prop('checked', false);
554      checkBox.prop('checked', !checkBox.prop('checked'));
555    }
556  });
557
558
559  // MORE FILTERS ON SEARCH PAGE
560  $('body').on('click', '.show-hooks', function(e) {
561    e.preventDefault();
562
563    var textOpened = $(this).attr('data-opened');
564    var textClosed = $(this).attr('data-closed');
565 
566    if($(this).hasClass('opened')) {
567      $(this).removeClass('opened').find('span').text(textClosed);
568      $(this).find('i').removeClass('fa-minus').addClass('fa-plus');
569      $('input[name="showMore"]').val(0);
570      $('.sidebar-hooks').css('margin-top', '0px').css('margin-bottom', '0px').css('opacity', 1).animate( { opacity: 0, marginTop:'40px', marginBottom:'-40px'}, 300, function() { $('.sidebar-hooks').hide(0); });
571
572
573    } else {
574      $(this).addClass('opened').find('span').text(textOpened);
575      $(this).find('i').addClass('fa-minus').removeClass('fa-plus');
576      $('input[name="showMore"]').val(1);
577      $('.sidebar-hooks').show(0).css('margin-top', '40px').css('margin-bottom', '-40px').css('opacity', 0).animate( { opacity: 1, marginTop:'0px', marginBottom:'0px'}, 300);
578
579    }
580
581  });
582
583  
584  // SCROLL TO TOP
585  $('body').on('click', '#scroll-to-top', function(e) {
586    e.preventDefault();
587    $('html, body').animate({scrollTop: 0}, 600);
588  });
589
590
591
592  // REFINE SEARCH - CLOSE BUTTON
593  $('body').on('click', '.ff-close', function(e) {
594    e.preventDefault();
595    
596    if(jqueryVersion == '1') {
597      parent.$.fancybox.close();
598    } else {
599      parent.$.fancybox.close();
600    }
601  });
602
603
604  // REFINE SEARCH - MOBILE
605  $('body').on('click', '.filter-button', function(e) {
606    e.preventDefault();
607
608    if(jqueryVersion == '1') {
609      if (!!$.prototype.fancybox) {
610        $.fancybox({
611          'padding':  0,
612          'width':    320,
613          'height':   640,
614          'autoSize': false,
615          'autoDimensions': false,
616          'scrolling': 'yes',
617          'closeBtn': true,
618          'wrapCSS':  'search-mobile-filter-box',
619          'content':  '<div class="filter filter-fancy"">' + $('.filter').html() + '</div>'
620        });
621
622      }
623    } else {
624      if (!!$.prototype.fancybox) {
625        $.fancybox.open({
626          toolbar : true,
627          type: 'inline',
628          smallBtn: false,
629          src: '<div style="width:320px;height:640px;padding:0;"><div class="search-mobile-filter-box"><div class="filter filter-fancy"">' + $('.filter').html() + '</div></div></div>'
630        });
631      }      
632    }
633  });
634
635
636
637  // MOBILE USER MENU
638  $('body').on('click', '.user-button', function(e) {
639    e.preventDefault();
640
641    var elem = $(this);
642
643    if(elem.hasClass('opened')) {
644      //$('#user-menu').css('margin-top', '0px').css('margin-bottom', '0px').css('opacity', 1).animate( { opacity: 0, marginTop:'40px', marginBottom:'-40px'}, 300, function() { $('#user-menu').hide(0); });
645      $('#user-menu').slideUp(200);
646      elem.removeClass('opened');
647
648    } else {
649      //$('#user-menu').show(0).css('margin-top', '40px').css('margin-bottom', '-40px').css('opacity', 0).animate( { opacity: 1, marginTop:'0px', marginBottom:'0px'}, 300);
650      $('#user-menu').slideDown(200);
651      elem.addClass('opened');
652
653    }    
654  });
655
656
657  // MOBILE USER MENU - CLICK OUTSIDE
658  if (($(window).width() + scrollCompensate()) < 768) {
659    $(document).mouseup(function (e){
660      var container = $('.user-menu-wrap');
661      var elem = container.find('.user-button');
662
663      if (!container.is(e.target) && container.has(e.target).length === 0) {
664        //$('#user-menu').css('margin-top', '0px').css('margin-bottom', '0px').css('opacity', 1).animate( { opacity: 0, marginTop:'40px', marginBottom:'-40px'}, 300, function() { $('#user-menu').hide(0); });
665        $('#user-menu').slideUp(300);
666        elem.removeClass('opened');
667      }
668    });
669  }
670
671
672
673  // MOBILE BLOCKS
674  $('body').on('click', '.mobile-block a#m-options', function(e) {
675    e.preventDefault();
676
677    var elem = $(this);
678    var elemId = elem.attr('id');
679    var elemMenuId = elem.attr('data-menu-id');
680
681    if(elem.hasClass('opened')) {
682      var isOpened = true;
683    } else {
684      var isOpened = false;
685    }
686
687    if(isOpened) {
688      $('#menu-cover').fadeOut(300);
689      elem.removeClass('opened');
690      $('.mobile-box' + elemMenuId).removeClass('opened').css('margin-left', '0px').css('margin-right', '0px').css('opacity', 1).animate( { opacity: 0, marginLeft:'80px', marginRight:'-80px'}, 300, function() { $('.mobile-box' + elemMenuId).hide(0); });
691
692    } else {
693      $('#menu-cover').fadeIn(300);
694      elem.addClass('opened');
695      $('.mobile-box' + elemMenuId).show(0).addClass('opened').css('margin-left', '80px').css('margin-right', '-80px').css('opacity', 0).animate( { opacity: 1, marginLeft:'0px', marginRight:'0px'}, 300);
696
697      if($('#m-search').hasClass('opened')) {
698        $('#m-search').click();
699      }
700    }    
701
702  });
703
704
705  // CLOSE MOBILE MENU
706  $('body').on('click', '.mobile-box a.mclose, #menu-cover', function(e) {
707    e.preventDefault();
708    $('#menu-cover').fadeOut(300);
709    $('.mobile-block a').removeClass('opened');
710    $('.mobile-box.opened').removeClass('opened').css('margin-left', '0px').css('margin-right', '0px').css('opacity', 1).animate( { opacity: 0, marginLeft:'80px', marginRight:'-80px'}, 300, function() { $('.mobile-box').hide(0); });
711  });
712
713
714
715
716
717  // USER ACCOUNT - ALERTS SHOW HIDE
718  $('body').on('click', '.alerts .alert .menu', function(e) {
719    e.preventDefault();
720
721    var elem = $(this).closest('.alert');
722    var blocks = elem.find('.param, #alert-items');
723
724    if(elem.hasClass('opened')) {
725      blocks.css('opacity', 1).css('margin-top', '0px').css('margin-bottom', '0px').animate( { opacity: 0, marginTop:'40px', marginBottom:'-40px'}, 300, function() { blocks.hide(0); });
726      elem.removeClass('opened');
727
728    } else {
729      blocks.show(0).css('opacity', 0).css('margin-top', '40px').css('margin-bottom', '-40px').animate( { opacity: 1, marginTop:'0px', marginBottom:'0px'}, 300);
730      elem.addClass('opened');
731
732    }
733
734    return false;
735  });
736
737
738  // PROFILE PICTURE - OPEN BOX
739  $(document).on('click', '.update-avatar', function(e){
740    e.preventDefault();
741
742    if(jqueryVersion == '1') {
743      if (!!$.prototype.fancybox) {
744        $.fancybox({
745          'padding':  0,
746          'width':    320,
747          'height':   425,
748          'autoSize': false,
749          'autoDimensions': false,
750          'closeBtn' : true,
751          'wrapCSS':  '',
752          'content':  $('#show-update-picture-content').html()
753        });
754      }
755    } else {
756      if (!!$.prototype.fancybox) {
757        $.fancybox.open({
758          toolbar : true,
759          type: 'inline',
760          smallBtn: false,
761          src: '<div style="width:320px;height:425px;padding:0;">' + $('#show-update-picture-content').html() + '</div>'
762        });
763      }      
764    }
765  });
766
767
768  // USER ACCOUNT - MY PROFILE SHOW HIDE
769  $('body').on('click', '.body-ua #main.profile h3', function(e) {
770    if (($(window).width() + scrollCompensate()) < 1201) {
771      e.preventDefault();
772      $(this).siblings('form').slideToggle(200);
773    }
774  });
775
776
777  // POST-EDIT - CHANGE LOCALE
778  $('body').on('click', '.locale-links a', function(e) {
779    e.preventDefault();
780
781    var locale = $(this).attr('data-locale');
782    var localeText = $(this).attr('data-name');
783    $('.locale-links a').removeClass('active');
784    $(this).addClass('active');
785
786    if($('.tabbertab').length > 0) {
787      $('.tabbertab').each(function() {
788        if($(this).find('[id*="' + locale + '"]').length || $(this).find('h2').text() == localeText) {
789          $(this).removeClass('tabbertabhide').show(0).css('opacity', 0).css('margin-top', '40px').css('margin-bottom', '-40px').animate( { opacity: 1, marginTop:'0px', marginBottom:'0px'}, 300);
790        } else {
791          $(this).addClass('tabbertabhide').hide(0);
792        }
793      });
794    }
795
796  });
797
798
799  // PUBLISH PAGE - SWITCH PRICE
800  $('body').on('click', '.price-wrap .selection a', function(e) {
801    e.preventDefault();
802
803    var price = $(this).attr('data-price');
804
805    $('.price-wrap .selection a').removeClass('active');
806    $(this).addClass('active');
807    $('.price-wrap .enter').addClass('disable');
808    $('.post-edit .price-wrap .enter #price').val(price).attr('placeholder', '');
809  });
810
811  $('body').on('click', '.price-wrap .enter .input-box', function(e) {
812    if($(this).parent().hasClass('disable')) {
813      $('.price-wrap .selection a').removeClass('active');
814      $(this).parent().removeClass('disable');
815      $('.post-edit .price-wrap .enter #price').val('').attr('placeholder', '');
816    }
817  });
818
819
820  // ITEM LIGHTBOX
821  if(typeof $.fn.lightGallery !== 'undefined') { 
822    $('.bx-slider').lightGallery({
823      mode: 'lg-slide',
824      thumbnail:true,
825      cssEasing : 'cubic-bezier(0.25, 0, 0.25, 1)',
826      selector: 'a',
827      getCaptionFromTitleOrAlt: false,
828      download: false,
829      thumbWidth: 90,
830      thumbContHeight: 80,
831      share: false
832    }); 
833  }
834
835
836  // ITEM BX SLIDER
837  if(typeof $.fn.bxSlider !== 'undefined') { 
838    $('.bx-slider').bxSlider({
839      slideWidth: $(window).outerWidth(),
840      slideMargin: 0,
841      pager: true,
842      pagerCustom: '.item-bx-pager',
843      infiniteLoop: true,
844      nextText: '',
845      prevText: '',
846      touchEnabled: false
847    });
848
849    if($('ul.bx-slider').find('li').length <= 1) {
850      $('.bx-controls').hide(0);
851    }
852  }
853
854
855
856  // AJAX - SUBMIT ITEM FORM (COMMENT / SEND FRIEND / PUBLIC CONTACT / SELLER CONTACT)
857  $('body').on('click', 'button.item-form-submit', function(e){
858    if(ajaxForms == 1) {
859
860      var button = $(this);
861      var form = $(this).closest('form');
862      var inputs = form.find('input, select, textarea');
863      var formType = $(this).attr('data-type');
864
865      // Validate form first
866      inputs.each(function(){
867        form.validate().element($(this));
868      });
869
870
871      if(form.valid()) {
872        button.addClass('btn-loading').attr('disabled', true);
873
874        $.ajax({
875          url: form.attr('action'),
876          type: "POST",
877          data: form.find(":input").filter(function () { return $.trim(this.value).length > 0}).serialize(),
878          success: function(response){
879            button.removeClass('btn-loading').attr('disabled', false);
880
881            var type = $(response).contents().find('.flashmessage');
882            var message = $(response).contents().find('.flash-wrap').text().trim();
883
884            message = message.substring(1, message.length);
885            inputs.val("").removeClass('valid');
886
887            if(form.find('#recaptcha').length) { 
888              grecaptcha.reset(); 
889            }
890
891            if(type.hasClass('flashmessage-error')) {
892              betAddFlash(message, 'error', true); 
893            } else {
894              betAddFlash(message, 'ok', true); 
895            }
896
897            if(jqueryVersion == '1') {
898              parent.$.fancybox.close();
899            } else {
900              parent.$.fancybox.close();
901            }
902          }
903        });
904      }
905    }
906  });
907
908
909
910  // FANCYBOX - OPEN ITEM FORM (COMMENT / SEND FRIEND / PUBLIC CONTACT / SELLER CONTACT)
911  $('body').on('click', '.open-form', function(e) {
912    e.preventDefault();
913    var height = 540;
914    var url = $(this).attr('href');
915    var formType = $(this).attr('data-type');
916
917    if(formType == 'friend') {
918      height = 640;
919    }
920
921    
922    if(jqueryVersion == '1') {
923      if (!!$.prototype.fancybox) {
924        $.fancybox({
925          'padding': 0,
926          'width': 400,
927          'height': height,
928          'scrolling': 'yes',
929          'wrapCSS': 'fancy-form',
930          'closeBtn': true,
931          'type': 'iframe',
932          'href': url
933        });
934
935      }
936    } else { 
937      height = height.toString() + 'px';
938
939      if (!!$.prototype.fancybox) {
940        $.fancybox.open({
941          toolbar : true,
942          type: 'iframe',
943          src: url,
944          baseClass: 'fancy-form',
945          iframe: {
946            css: {
947              width : '400px',
948              height : height,
949              padding: 0
950            }
951          }
952        });
953      }
954    }
955  });
956
957  // CONTACT FORM - ADD REQUIRED PROPERTY
958  $('body#body-contact input[name="subject"], body#body-contact textarea[name="message"]').prop('required', true);
959
960
961  // ATTACHMENT - FIX FILE NAME
962  $('body').on('change', '.att-box input[type="file"]', function(e) {
963    if( $(this)[0].files[0]['name'] != '' ) {
964      $(this).closest('.att-box').find('.att-text').text($(this)[0].files[0]['name']);
965    }
966  });
967
968
969  // HIDE FLASH MESSAGE MANUALLY
970  $('body').on('click', '.flashmessage .ico-close', function(e) {
971    e.preventDefault();
972
973    var elem = $(this).closest('.flashmessage');
974
975    elem.show(0).css('opacity', 1).css('margin-top', '0px').css('margin-bottom', '0px').animate( { opacity: 0, marginTop:'30px', marginBottom:'-30px'}, 300);
976
977    window.setTimeout(function() {
978      elem.remove();
979    }, 300);
980
981    return false;
982  });
983
984
985  // HIDE FLASH MESSAGES AUTOMATICALLY
986  window.setTimeout(function(){ 
987    $('.flash-wrap .flashmessage:not(.js)').css('opacity', 1).css('margin-top', '0px').css('margin-bottom', '0px').animate( { opacity: 0, marginTop:'30px', marginBottom:'-30px'}, 300);
988
989    window.setTimeout(function() {
990      $('.flash-wrap .flashmessage:not(.js)').remove();
991    }, 300);
992  }, 10000);
993
994
995  // LOCATION PICKER - SHOW LIST OF LOCATIONS WHEN CLICK ON TERM
996  $('body').on('click', '.loc-picker .term', function() {
997    if(!$(this).hasClass('open')) {
998      $(this).closest('.loc-picker').find('.shower').show(0).css('opacity', 0).css('margin-top', '30px').css('margin-bottom', '-30px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} , 300);
999      $(this).closest('.loc-picker').find('.term').addClass('open');
1000    }
1001  });
1002
1003
1004  // LOCATION PICKER - WHEN CLICK OUTSIDE LOCATION PICKER, HIDE SELECTION
1005  $(document).mouseup(function (e){
1006    var container = $('.loc-picker');
1007    var form = container.closest('form');
1008
1009    if (!container.is(e.target) && container.has(e.target).length === 0 && container.find('.term').hasClass('open')) {
1010      if (($(window).width() + scrollCompensate()) >= 768) {
1011        if(container.find('.term').val() == '' && container.find('.term').hasClass('open') && ( form.find('input[name="sCountry"]').val() != '' || form.find('input.sCountry').val() != '' || form.find('input[name="sRegion"]').val() != '' || form.find('input.sRegion').val() != '' || form.find('input[name="sCity"]').val() != '' || form.find('input.sCity').val() != '' )) {
1012          $('input[name="sCountry"], input.sCountry, input[name="sRegion"], input.sRegion, input[name="sCity"], input.sCity').val("");
1013          $('input[name="sCity"]').change();
1014        }
1015      } else {
1016        form.find('input[name="sCountry"], input.sCountry, input[name="sRegion"], input.sRegion, input[name="sCity"], input.sCity').val("");
1017
1018      }
1019
1020      container.find('.shower').fadeOut(0);
1021      container.find('.term').removeClass('open');
1022    }
1023  });
1024
1025
1026  // CATEGORY PICKER 
1027  $('body').on('click', '.cat-picker .term3', function() {
1028    if(!$(this).hasClass('open')) {
1029      $(this).closest('.cat-picker').find('.shower').show(0).css('opacity', 0).css('margin-top', '30px').css('margin-bottom', '-30px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} , 300);
1030      $(this).closest('.cat-picker').find('.term3').addClass('open');
1031    }
1032  });
1033
1034
1035  // CATEGORY PICKER - WHEN CLICK OUTSIDE CATEGORY PICKER, HIDE SELECTION
1036  $(document).mouseup(function (e){
1037    var container = $('.cat-picker');
1038    var form = container.closest('form');
1039
1040    if (!container.is(e.target) && container.has(e.target).length === 0 && container.find('.term3').hasClass('open')) {
1041      container.find('.shower').fadeOut(0);
1042      container.find('.term3').removeClass('open');
1043    }
1044  });
1045
1046
1047
1048  // LOCATION PICKER - SHOW LIST OF LOCATIONS WHEN CLICK ON TERM
1049  $('body').on('click', '.loc-picker .term2', function() {
1050    if(!$(this).hasClass('open')) {
1051      $(this).closest('.loc-picker').find('.shower').show(0).css('opacity', 0).css('margin-top', '30px').css('margin-bottom', '-30px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} , 300);
1052      $(this).closest('.loc-picker').find('.term2').addClass('open');
1053    } else {
1054      $(this).closest('.loc-picker').find('.term2').removeClass('open');
1055      $(this).closest('.loc-picker').find('.shower').hide(0);
1056    }
1057  });
1058
1059
1060  // LOCATION PICKER - WHEN CLICK OUTSIDE LOCATION PICKER, HIDE SELECTION
1061  $(document).mouseup(function (e){
1062    var container = $('.loc-picker');
1063    var form = container.closest('form');
1064
1065    if (!container.is(e.target) && container.has(e.target).length === 0 && container.find('.term2').hasClass('open')) {
1066      if(container.find('.term2').val() == '' && container.find('.term2').hasClass('open') && ( form.find('input[name="sCountry"]').val() != '' || form.find('input.sCountry').val() != '' || form.find('input[name="sRegion"]').val() != '' || form.find('input.sRegion').val() != '' || form.find('input[name="sCity"]').val() != '' || form.find('input.sCity').val() != '' )) {
1067        $('input[name="sCountry"], input.sCountry, input[name="sRegion"], input.sRegion, input[name="sCity"], input.sCity').val("");
1068        $('input[name="sCity"]').change();
1069      }
1070
1071      container.find('.shower').fadeOut(0);
1072      container.find('.term2').removeClass('open');
1073    }
1074  });
1075
1076
1077
1078
1079  // LOCATION PICKER - CLICK FUNCTIONALITY
1080  $('body').on('click', '.loc-picker .shower .option', function() {
1081    var container = $(this).closest('.loc-picker');
1082
1083    if( !$(this).hasClass('empty-pick') && !$(this).hasClass('more-pick') && !$(this).hasClass('service') ) {
1084
1085      container.find('.shower .option').removeClass('selected');
1086      $(this).addClass('selected');
1087      container.find('.shower').fadeOut(0);
1088      container.find('.term').removeClass('open');
1089
1090
1091      var term = $(this).find('strong').text();
1092      $('input.term').val( term );
1093
1094      $('input[name="sCountry"], input.sCountry').val( $(this).attr('data-country') );
1095      $('input[name="sRegion"], input.sRegion').val( $(this).attr('data-region') );
1096      $('input[name="sCity"], input.sCity').val( $(this).attr('data-city') );
1097
1098      if (($(window).width() + scrollCompensate()) >= 768) {
1099        $('input[name="sCity"]').change();
1100      }
1101    }
1102  });
1103
1104
1105
1106  // SIMPLE SELECT - CLICK ELEMENT FUNCTIONALITY
1107  $('body').on('click', '.simple-select:not(.disabled) .option:not(.info):not(.nonclickable)', function() {
1108    $(this).parent().parent().find('input.input-hidden').val( $(this).attr('data-id') ).change();
1109    $(this).parent().parent().find('.text span').html( $(this).html() );
1110    $(this).parent().parent().find('.option').removeClass('selected');
1111    $(this).addClass('selected');
1112    $(this).parent().hide(0).removeClass('opened');
1113
1114    $(this).closest('.simple-select').removeClass('opened');
1115  });
1116
1117
1118  // SIMPLE SELECT - OPEN MENU
1119  $('body').on('click', '.simple-select', function(e) {
1120    if(!$(this).hasClass('disabled') && !$(this).hasClass('opened') && !$(e.target).hasClass('option')) {
1121      $('.simple-select').not(this).removeClass('opened');
1122
1123      $('.simple-select .list').hide(0);
1124      $(this).addClass('opened');
1125      $(this).find('.list').show(0).css('opacity', 0).css('margin-top', '30px').css('margin-bottom', '-30px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} , 300);
1126    }
1127  });
1128
1129
1130  // SIMPLE SELECT - HIDE WHEN CLICK OUTSIDE
1131  $(document).mouseup(function(e){
1132    var container = $('.simple-select');
1133
1134    if (!container.is(e.target) && container.has(e.target).length === 0) {
1135      $('.simple-select').removeClass('opened');
1136      $('.simple-select .list').hide(0);
1137    }
1138  });
1139
1140
1141  // SIMPLE SELECT - NONCLICKABLE, ADD TITLE
1142  $('.simple-select .option.nonclickable').attr('title', betTitleNc);
1143
1144
1145  
1146  // REGISTER FORM - SWAP FUNCTIONALITY
1147  $('body').on('click', '#i-forms .swap a', function(e){
1148    e.preventDefault();
1149
1150    var boxType = $(this).attr('data-type');
1151
1152    $('#i-forms .box').hide(0);
1153    $('#i-forms .box[data-type="' + boxType + '"]').show(0).css('opacity', 0).css('margin-top', '50px').css('margin-bottom', '-50px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} );
1154
1155    $('html, body').animate({ scrollTop: 0}, 300);
1156  });
1157
1158
1159  // TABS SWITCH - HOME PAGE
1160  $('body').on('click', '.home-container.tabs a.tab', function(e){
1161    e.preventDefault();
1162
1163    var tabId = $(this).attr('data-tab');
1164
1165    $('.home-container.tabs a.tab').removeClass('active');
1166    $(this).addClass('active');
1167
1168    $('.home-container .single-tab').hide(0);
1169    $('.home-container .single-tab[data-tab="' + tabId + '"]').show(0).css('opacity', 0).css('margin-top', '50px').css('margin-bottom', '-50px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} );
1170
1171
1172    // Trigger images to lazy load
1173    if(betLazy == "1") {
1174      $(window).scrollTop($(window).scrollTop()+1);
1175      $(window).scrollTop($(window).scrollTop()-1);
1176    }
1177
1178    // Resize when masonry
1179    if(betMasonry == "1") {
1180      $grid.masonry();
1181    }
1182  });
1183
1184
1185  // LIST OR GRID VIEW
1186  $('body').on('click', '.list-grid a', function(e){
1187    e.preventDefault();
1188
1189    if(!$(this).hasClass('active')) {
1190      var show = $(this).attr('data-view');
1191
1192      $('.list-grid a').removeClass('active');
1193      $(this).addClass('active');
1194
1195      $('#search-items .products').removeClass('list').removeClass('grid').addClass(show);
1196      $('input[name="sShowAs"]').val(show);
1197
1198      if(betMasonry == "1") {
1199        $('#search-items').addClass('no-transition');
1200        setTimeout(function() {
1201          $('#search-items').removeClass('no-transition')
1202        }, 500);
1203      }
1204
1205      var href = $(this).attr('href');
1206
1207      if(href != '') {
1208        var newUrl = href;
1209      } else {
1210        var newUrl = baseDir + 'index.php?' + $('form.search-side-form :input[value!=""], form.search-side-form select, form.search-side-form textarea').serialize();
1211      }
1212      
1213      window.history.pushState(null, null, newUrl);
1214    }
1215
1216    $('.paginate a, .user-type a, .sort-it a').each(function() {
1217      var url = $(this).attr('href');
1218
1219      if(!url.indexOf("index.php") >= 0 && url.match(/\/$/)) {
1220        url += (url.substr(-1) !== '/' ? '/' : '');
1221      }
1222
1223      if(url.indexOf("sShowAs") >= 0) {
1224        url += (url.substr(-1) !== '/' ? '/' : '');
1225        var newUrl = url.replace(/(sShowAs,).*?(\/)/,'$1' + show + '$2').replace(/(sShowAs,).*?(\/)/,'$1' + show + '$2');
1226      } else {
1227        if(url.indexOf("index.php") >= 0) {
1228          var newUrl = url + '&sShowAs=' + show;
1229        } else {
1230          var newUrl = url.replace(/\/+$/, '') + '/?sShowAs=' + show;
1231        }
1232      }
1233
1234      newUrl = (newUrl.substr(-1) == '/' ? newUrl.slice(0, -1) : newUrl);
1235      $(this).attr('href', newUrl);
1236    });
1237
1238    // MASONRY - CREATE GRID WHEN IMAGES HAS DIFFERENT SIZE (height)
1239    if(betMasonry == "1") {
1240      var $grid = $('.products .prod-wrap, #search-items .products, .products .wrap').masonry({
1241        itemSelector: '.simple-prod'
1242      });
1243
1244      $grid.imagesLoaded().progress(function(){
1245        $grid.masonry('layout');
1246      });
1247    }
1248  });
1249
1250
1251
1252
1253
1254  // AJAX SEARCH
1255  $('body#body-search').on('change click', '.link-check-box a, .filter-remove a, form.search-side-form input:not(.term), body#body-search #sub-nav a, #home-cat a, #sub-cat a, form.search-side-form select, .sort-it a, .user-type a, .paginate a', function(event) {
1256    var ajaxStop = false;
1257
1258    if(ajaxSearch == 1 && event.type != 'change' && !$(this).is('input:radio')) {
1259      event.preventDefault();
1260    }
1261
1262
1263    // Disable on mobile devices when input selected from fancybox
1264    if($(event.target).closest('.search-mobile-filter-box').length) {
1265      if(!$(event.target).closest('#search-sort').length && !$(event.target).closest('.sub-line').length) {     // it may not be required
1266        var ajaxStop = true;
1267        //return false;
1268      }
1269    }
1270
1271    var sidebarReload = true;
1272
1273    if($(this).closest('.sidebar-hooks').length || $(event.target).attr('name') == 'locUpdate') {
1274      sidebarReload = false;
1275    }
1276    
1277    // Make sure no sidebar reload for Car Attributes PRO inputs
1278    if($(this).closest('.cap-input-box').length) {
1279      sidebarReload = false;
1280    }
1281
1282    var sidebar = $('.filter form.search-side-form');
1283    var ajaxSearchUrl = '';
1284
1285    if (event.type == 'click' && !$(this).is('input:radio')) {
1286      if(typeof $(this).attr('href') !== typeof undefined && $(this).attr('href') !== false) {
1287        ajaxSearchUrl = $(this).attr('href');
1288      }
1289    } else if (event.type == 'change' || $(this).is('input:radio')) {
1290      //ajaxSearchUrl = baseDir + "index.php?" + sidebar.find(':input[value!=""]').serialize();
1291      ajaxSearchUrl = baseDir + "index.php?" + sidebar.find(":input").filter(function () { return $.trim(this.value).length > 0}).serialize();
1292    }
1293
1294
1295    if(ajaxSearch == 1 && $('input[name="ajaxRun"]').val() != "1" && (ajaxSearchUrl != '#' && ajaxSearchUrl != '') && !ajaxStop) {
1296      if(ajaxSearchUrl == $(location).attr('href')) {
1297        return false;
1298      }
1299
1300      sidebar.find('.init-search').addClass('btn-loading').addClass('disabled').attr('disabled', true);
1301      sidebar.find('input[name="ajaxRun"]').val("1");
1302      $('#search-items').addClass('loading');
1303
1304
1305      $.ajax({
1306        url: ajaxSearchUrl,
1307        type: "GET",
1308        success: function(response){
1309          var length = response.length;
1310          var currentUrl = $(response).contents().find('.hCurrentUrl').text();
1311
1312          var data = $(response).contents().find('#main').html();
1313          var bread = $(response).contents().find('ul.breadcrumb');
1314          var filter = $(response).contents().find('.filter').html();
1315
1316          sidebar.find('.init-search').removeClass('btn-loading').removeClass('disabled').attr('disabled', false);
1317          sidebar.find('input[name="ajaxRun"]').val("");
1318
1319          $('#main').fadeOut(0, function(){ 
1320            $('#main').html(data).show(0);
1321
1322            $('#search-items').hide(0);
1323            $('#search-items').removeClass('loading');
1324            $('#search-items').show(0).css('opacity', 0).css('margin-top', '50px').css('margin-bottom', '-50px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} , 300);
1325
1326          });
1327
1328          if(sidebarReload) {
1329            $('.filter').html(filter);
1330          }
1331          
1332          $('ul.breadcrumb').html(bread);
1333
1334
1335          // LAZY LOADING OF IMAGES
1336          if(betLazy == "1" && betMasonry == "0" ) {
1337            $('#search-items img.lazy').Lazy({
1338              effect: "fadeIn",
1339              effectTime: 300,
1340              afterLoad: function(element) {
1341                setTimeout(function() {
1342                  element.css('transition', '0.2s');
1343                }, 300);
1344              }
1345            });
1346          }
1347          
1348          // Update URL
1349          if(currentUrl != '') {
1350            window.history.pushState(null, null, currentUrl);
1351          } else {
1352            window.history.pushState(null, null, ajaxSearchUrl);
1353          }
1354
1355          if (($(window).width() + scrollCompensate()) >= 768) {
1356            $('body,html').animate({ scrollTop: $('#main').offset().top-75 }, 800);
1357          } else {
1358            $('body,html').animate({ scrollTop: $('#main').offset().top-60 }, 800);
1359          }
1360        },
1361
1362        error: function(response){
1363          sidebar.find('.init-search').removeClass('btn-loading').removeClass('disabled').attr('disabled', false);
1364          sidebar.find('input[name="ajaxRun"]').val("");
1365
1366          response = response.responseText;
1367
1368          var data = $(response).contents().find('#main').html();
1369          var bread = $(response).contents().find('ul.breadcrumb');
1370          var filter = $(response).contents().find('.filter').html();
1371          var currentUrl = $(response).contents().find('.hCurrentUrl').text();
1372
1373          $('#main').fadeOut(0, function(){ 
1374            $('#main').html(data).show(0);
1375
1376            $('#search-items').hide(0);
1377            $('#search-items').removeClass('loading');
1378            $('#search-items').show(0).css('opacity', 0).css('margin-top', '50px').css('margin-bottom', '-50px').animate( { opacity: 1, marginTop:'0', marginBottom:'0'} , 300);
1379
1380          });
1381
1382          if(sidebarReload) {
1383            $('.filter').html(filter);
1384          }
1385
1386          $('ul.breadcrumb').html(bread);
1387
1388
1389          // LAZY LOADING OF IMAGES
1390          if(betLazy == "1" && betMasonry == "0" ) {
1391            $('#search-items img.lazy').Lazy({
1392              effect: "fadeIn",
1393              effectTime: 300,
1394              afterLoad: function(element) {
1395                setTimeout(function() {
1396                  element.css('transition', '0.2s');
1397                }, 300);
1398              }
1399            });
1400          }
1401
1402          // Update URL
1403          if(currentUrl != '') {
1404            window.history.pushState(null, null, currentUrl);
1405          } else {
1406            window.history.pushState(null, null, ajaxSearchUrl);
1407          }
1408          
1409          if (($(window).width() + scrollCompensate()) >= 768) {
1410            $('body,html').animate({ scrollTop: $('#main').offset().top-75 }, 800);
1411          } else {
1412            $('body,html').animate({ scrollTop: $('#main').offset().top-60 }, 800);
1413          }
1414        }
1415      });
1416
1417      if(!$(this).is('input:radio')) {
1418        return false;
1419      }
1420    }
1421  });
1422
1423
1424});
1425
1426
1427
1428// THEME FUNCTIONS
1429function betAddFlash(text, type, parent = false) {
1430  var rand = Math.floor(Math.random() * 1000);
1431  var html = '<div id="flashmessage" class="flashmessage js flashmessage-' + type + ' rand-' + rand + '"><a class="btn ico btn-mini ico-close">x</a>
1431' + text + '</div>';
1432
1433  if(!parent) {
1434    $('.flash-box .flash-wrap').append(html);
1435  } else {
1436    $('.flash-box .flash-wrap', window.parent.document).append(html);
1437  }
1438
1439}
1440
1441
1442// CALCULATE SCROLL WIDTH
1443function scrollCompensate() {
1444  var inner = document.createElement('p');
1445  inner.style.width = "100%";
1446  inner.style.height = "200px";
1447
1448  var outer = document.createElement('div');
1449  outer.style.position = "absolute";
1450  outer.style.top = "0px";
1451  outer.style.left = "0px";
1452  outer.style.visibility = "hidden";
1453  outer.style.width = "200px";
1454  outer.style.height = "150px";
1455  outer.style.overflow = "hidden";
1456  outer.appendChild(inner);
1457
1458  document.body.appendChild(outer);
1459  var w1 = inner.offsetWidth;
1460  outer.style.overflow = 'scroll';
1461  var w2 = inner.offsetWidth;
1462  if (w1 == w2) w2 = outer.clientWidth;
1463
1464  document.body.removeChild(outer);
1465
1466  return (w1 - w2);
1467}

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.