PageSourceSearch

https://amtanmedical.com.au/wp-content/plugins/photo-gallery/js/bwg_frontend.js?ver=1.8.27

js amtanmedical.com.au collected 2026-09-26 11:47:20 UTC 193,239 bytes, 4,270 lines download raw bytes

1var bwg = 0;
2var isMobile = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
3var bwg_click = isMobile ? 'touchend' : 'click';
4var bwg_slideshow_filmstrip_thumbnail_timer = false;
5window.bwg_slideshow_filmstrip_thumb = {};
6
7/* Slideshow params */
8var bwg_params = [];
9/* Image browser params */
10var bwg_params_ib = [];
11/* Carousel params */
12var bwg_params_carousel = [];
13
14jQuery(function () {
15  if ( isMobile ) {
16    jQuery(".bwg-container.bwg-standard-thumbnails .bwg-title1, .bwg-container.bwg-masonry-thumbnails .bwg-title1, .bwg-mosaic-thumbnails").css("opacity","1");
17    jQuery(".bwg-zoom-effect .bwg-zoom-effect-overlay, .bwg-zoom-effect-overlay > span").css({"opacity":1,"background-color":"unset"});
18  }
19});
20
21jQuery(function () {
22  /**
23   * @param {boolean} isAll   do you need to stop all slideshows?.
24   */
25  function bwg_hiddenFunction(isAll) {
26    bwg_slideshow_blur(isAll);
27    bwg_carousel_blur(isAll);
28    if (jQuery('.bwg_play_pause').length > 0) {
29      window.clearInterval(gallery_box_data['bwg_playInterval'])
30    }
31  }
32
33  /**
34   * @param {object} container gallery main container.
35   */
36  function bwg_visibleFunction(container) {
37    if ( container ) {
38      bwg_main_ready(container);
39    }
40    bwg_slideshow_focus();
41    bwg_carousel_focus();
42    if (jQuery(".bwg_play_pause").length && jQuery(".bwg_play_pause").hasClass("bwg-icon-play") && !jQuery(".bwg_comment_container").hasClass("bwg_open")) {
43      bwg_play(gallery_box_data['data']);
44    }
45  }
46
47  var bwg_error = false;
48  jQuery(".bwg_container").each(function () {
49    if (jQuery(this).find(".wd_error").length > 0) {
50      bwg_error = true;
51    }
52    if (!bwg_error) {
53      var bwg_container1 = jQuery(this);
54        if (bwg_container1[0].offsetHeight) {
55          var bwg_visibilityCounter = 0;
56        }
57        else {
58          var bwg_visibilityCounter = 1;
59        }
60        setInterval(function () {
61          if (bwg_container1[0].offsetHeight) {
62            if (bwg_visibilityCounter == 1) {
63              bwg_visibilityCounter = 0;
64              bwg_visibleFunction(bwg_container1);
65            }
66          }
67          else {
68            if (bwg_visibilityCounter == 0) {
69              bwg_visibilityCounter = 1;
70              bwg_hiddenFunction(false);
71            }
72          }
73        }, 200);
74    }
75  });
76  if (!bwg_error) {
77    jQuery(window)
78      .focus(function () {
79        bwg_visibleFunction();
80      })
81      .blur(function () {
82        bwg_hiddenFunction(true);
83      })
84  }
85});
86
87/* For removing the 'lazy_loader' class (loading icon), when 'Lazy load' options is Yes */
88function bwg_remove_lazy_loader_icon() {
89  if ( bwg_objectsL10n.lazy_load == 1 ) {
90    jQuery('img.bwg_lazyload').Lazy({
91      afterLoad: function() {
92        jQuery(".lazy_loader").removeClass("lazy_loader");
93      },
94      onFinishedAll: function() {
95        jQuery(".lazy_loader").removeClass("lazy_loader");
96      }
97    });
98  }
99}
100/**
101 * @param {object} container gallery main container.
102 */
103function bwg_main_ready(container) {
104  var bwg = container.data('bwg');
105  if (container.data("scroll") === 1) {
106    form_id = 'gal_front_form_' + bwg;
107    jQuery("html, body").animate({scrollTop: jQuery('#' + form_id).offset().top - 150}, 500);
108  }
109
110  bwg_remove_lazy_loader_icon();
111
112  /* If there is error (empty gallery).*/
113  if ( container.find(".wd_error").length > 0 ) {
114    bwg_container_loaded(bwg);
115  }
116
117  var last_container = container.find(".bwg-container");
118
119  /* Go back from gallery to album.*/
120  if ( container.data("is-album") === 'album' && last_container.hasClass('bwg-thumbnails') ) {
121    var gallery_type = 'thumbnails';
122  }
123  else {
124    var gallery_type = container.data("gallery-type");
125  }
126  bwg_document_ready(container);
127  switch ( gallery_type) {
128    case "thumbnails":
129    case "thumbnails_masonry":
130    case "album_compact_preview":
131    case "album_masonry_preview":
132    case "album_extended_preview":
133      bwg_all_thumnails_loaded(last_container);
134      break;
135    case "thumbnails_mosaic":
136      bwg_thumbnail_mosaic(last_container);
137      break;
138    case "slideshow":
139      bwg_slideshow_ready(bwg);
140      break;
141    case "carousel":
142      bwg_carousel_ready(bwg);
143      bwg_carousel_onload(container);
144      break;
145    case "image_browser":
146      bwg_image_browser_ready(container);
147      break;
148    case "blog_style":
149      bwg_blog_style_ready(container);
150      break;
151  }
152}
153
154function bwg_resize_search_line() {
155  jQuery('.search_line').each(function() {
156    var element = jQuery(this);
157    if (element.width() < 410) {
158      element.addClass('bwg-search-line-responsive');
159    }
160    else {
161      element.removeClass('bwg-search-line-responsive');
162    }
163  });
164}
165
166/* Tags Filter - Buttons View Section Height */
167function bwg_tags_button_section_visibility() {
168  jQuery( 'div[id^="bwg_container1_"]' ).each( function () {
169    var bwg_container = jQuery( this );
170    var current_view = bwg_container.find('.current_view').val();
171    var show_bottom_tag =  bwg_container.find('.show_bottom_tag').val();
172    var tags_button_filter = bwg_container.find('.bwg_tags_container_' + current_view + ' .bwg_tag_button_view_container');
173
174    if ( tags_button_filter.length ) {
175      var tags_button_filter_full = tags_button_filter[0].scrollHeight;
176    }
177    var visible_buttons_minheight = tags_button_filter.find('.bwg_tags_filter_buttons').outerHeight(true);
178    var visible_buttons_maxheight = parseInt( (tags_button_filter.find('.bwg_tags_filter_buttons').outerHeight(true) * 2 ) + 3 );
179
180    if( tags_button_filter_full > visible_buttons_maxheight ) {
181      /* Check for not closing see all tags container if it is already open ex. during page load */
182      if(jQuery(this).find(".see_all_tags.bwg_hide").length === 0 ) {
183        tags_button_filter.css({
184          'min-height':visible_buttons_minheight,
185          'max-height':visible_buttons_maxheight,
186          'overflow':"hidden",
187        });
188      }
189      tags_button_filter.next('.bwg_tag_button_see_all').show();
190    }
191    else {
192      tags_button_filter.css({
193        'min-height':'auto',
194        'max-height':'100%',
195        'height':'auto',
196        'overflow':"visible",
197      });
198      tags_button_filter.next('.bwg_tag_button_see_all').hide();
199    }
200
201    var see_all_button_width = (tags_button_filter.next().find('.see_all_tags').width() / 2) ;
202    tags_button_filter.next().find('.see_all_tags').attr('style', 'margin-left: -'+ see_all_button_width +'px');
203
204    tags_button_filter.next().find('.see_all_tags').off("click").on('click', function () {
205      if ( jQuery(this).hasClass("bwg_show") ) {
206        jQuery(this).removeClass("bwg_show").addClass("bwg_hide").html("<span>&#8722;</span>" + bwg_objectsL10n.bwg_tag_see_less);
207        tags_button_filter.css({
208          'min-height':'auto',
209          'max-height':'100%',
210          'height':'auto',
211          'overflow':"visible",
212        });
213      }
214      else if ( jQuery(this).hasClass("bwg_hide") ) {
215        jQuery(this).removeClass("bwg_hide").addClass("bwg_show").html("<span>&#43;</span>" + bwg_objectsL10n.bwg_tag_see_all);
216        tags_button_filter.css({
217          'min-height':visible_buttons_minheight,
218          'max-height':visible_buttons_maxheight,
219          'overflow':"hidden",
220        });
221      }
222    });
223    /* Show all tags section, if selected tags position is under than 2-rd line */
224    if ( show_bottom_tag == 1 ) {
225      jQuery(this).find('.see_all_tags').removeClass("bwg_show").addClass("bwg_hide").html("<span>&#8722;</span>" + bwg_objectsL10n.bwg_tag_see_less);
226      tags_button_filter.css({
227        'min-height':'auto',
228        'max-height':'100%',
229        'height':'auto',
230        'overflow':"visible",
231      });
232    }
233  });
234}
235
236jQuery(window).on("resize", function () {
237  /* Move to the end of query to get proper sizes. Otherwize Carousel resize does not work correctly.*/
238  setTimeout(function () {
239    var bwg_error = false;
240    /* If there is error (empty gallery).*/
241    jQuery(".bwg_container").each(function () {
242      if (jQuery(this).find(".wd_error").length > 0) {
243        bwg_error = true;
244      }
245    });
246
247    /* Tags Filter - Buttons View Section Height */
248    bwg_tags_button_section_visibility();
249
250    if (!bwg_error) {
251      jQuery(".bwg-thumbnails, .bwg-masonry-thumbnails, .bwg-album-thumbnails").each(function () {
252        bwg_all_thumnails_loaded(this);
253      });
254      bwg_slideshow_resize();
255      bwg_image_browser_resize();
256      bwg_carousel_resize();
257      bwg_blog_style_resize();
258      jQuery(".bwg-mosaic-thumbnails").each(function () {
259        bwg_thumbnail_mosaic(this);
260      });
261    }
262    bwg_resize_search_line();
263  }, 0);
264});
265
266jQuery(window).on("load", function () {
267  var bwg_error = false;
268  /* If there is error (empty gallery).*/
269  jQuery(".bwg_container").each(function () {
270    if ( jQuery(this).find(".wd_error").length > 0 ) {
271      bwg_error = true;
272    }
273  });
274  if ( !bwg_error ) {
275    bwg_blog_style_onload();
276    jQuery(".bwg-mosaic-thumbnails").each(function () {
277      bwg_thumbnail_mosaic(this);
278    });
279  }
280});
281
282jQuery(".bwg-masonry-thumb-span img, .bwg-mosaic-thumb-span img").on("error", function() {
283  jQuery(this).height(100);
284  jQuery(this).width(100);
285});
286
287function bwg_slideshow_resize() {
288  jQuery(".bwg_slideshow").each(function () {
289    bwg = jQuery(this).attr('data-bwg');
290    if ( jQuery("#bwg_slideshow_image_container_" + bwg).length ) {
291      bwg_params[bwg] = JSON.parse(jQuery("#bwg_slideshow_image_container_" + bwg).attr("data-params"));
292      bwg_params[bwg]['event_stack'] = [];
293      bwg_popup_resize(bwg);
294    }
295  });
296}
297
298function bwg_blog_style_resize() {
299  jQuery(".bwg_blog_style").each(function () {
300    bwg = jQuery(this).attr('data-bwg');
301    jQuery('.bwg_embed_frame_16x9_'+bwg).each(function (e) {
302      jQuery(this).width(jQuery(this).parent().width());
303      jQuery(this).height(jQuery(this).width() * 0.5625);
304    });
305    jQuery('.bwg_embed_frame_instapost_'+bwg).each(function (e) {
306        jQuery(this).width(jQuery(this).parent().width());
307        var height = (jQuery(this).width() - 16) * jQuery(this).attr('data-height') / jQuery(this).attr('data-width') + 96;
308        jQuery(this).height(height);
309        jQuery(this).find('iframe[id^="instagram-embed-"]').css({
310          'max-height': height + 'px',
311        });
312    });
313  })
314}
315
316function bwg_blog_style_onload() {
317  jQuery(".bwg_blog_style").each(function () {
318    bwg = jQuery(this).attr('data-bwg');
319    var data_right_click = jQuery("#bwg_blog_style_"+bwg);
320    jQuery('.bwg_embed_frame_16x9_'+bwg).each(function (e) {
321      /* Conflict with Sydney Theme */
322      if ( jQuery('.bwg_blog_style_image_' + bwg).find('.fluid-width-video-wrapper').length ) {
323        jQuery('.fluid-width-video-wrapper').removeAttr('style');
324        var content = jQuery(this).parents('.bwg_blog_style_image_' + bwg).find('.fluid-width-video-wrapper').contents();
325        jQuery(this).parents('.fluid-width-video-wrapper').replaceWith(content);
326      }
327      jQuery(this).width(jQuery(this).parents('.bwg_blog_style_image_' + bwg).width());
328      jQuery(this).height(jQuery(this).width() * 0.5625);
329    });
330
331    jQuery('.bwg_embed_frame_instapost_'+bwg).each(function (e) {
332      jQuery(this).width(jQuery(this).parents('.bwg_blog_style_image_' + bwg).width());
333      /* 16 is 2*padding inside iframe */
334      /* 96 is 2*padding(top) + 1*padding(bottom) + 40(footer) + 32(header) */
335      var height = (jQuery(this).width() - 16) * jQuery(this).attr('data-height') / jQuery(this).attr('data-width') + 96;
336      jQuery(this).height(height);
337      jQuery(this).find('iframe[id^="instagram-embed-"]').css({
338        'max-height': height + 'px',
339      });
340    });
341
342    bwg_container_loaded(bwg);
343  });
344}
345
346/**
347 * @param {object} container gallery main container.
348 */
349function bwg_blog_style_ready(container) {
350  var bwg = container.data('bwg');
351  bwg_container_loaded( bwg );
352  if ( typeof instgrm !== 'undefined' && typeof instgrm.Embeds !== 'undefined' ) {
353    instgrm.Embeds.process();
354  }
355
356  var bwg_touch_flag = false;
357  container.find('.bwg_lightbox_' + bwg).on('click', function () {
358    var image_id = jQuery(this).attr('data-image-id');
359    jQuery('#bwg_blog_style_share_buttons_' + image_id ).removeAttr('data-open-comment');
360    if ( !bwg_touch_flag ) {
361      bwg_touch_flag = true;
362      setTimeout( function(){ bwg_touch_flag = false; }, 100 );
363      bwg_gallery_box(image_id, container.closest('.bwg_container'));
364      return false;
365    }
366  });
367  jQuery(".bwg_lightbox_" + bwg + " .bwg_ecommerce").on("click", function (event) {
368    event.stopPropagation();
369    if (!bwg_touch_flag) {
370      bwg_touch_flag = true;
371      setTimeout(function(){ bwg_touch_flag = false; }, 100);
372      bwg_gallery_box(container.attr( "data-image-id" ), container.closest( '.bwg_container' ), true);
373      return false;
374    }
375  });
376
377  var bwg_hash = window.location.hash.substring(1);
378  if (bwg_hash) {
379    if (bwg_hash.indexOf("bwg") != "-1") {
380      bwg_hash_array = bwg_hash.replace("bwg", "").split("/");
381      if(bwg_hash_array[0] == "<?php echo $params_array['gallery_id']; ?>"){
382        bwg_gallery_box(bwg_hash_array[1]);
383      }
384    }
385  }
386}
387
388function bwg_slideshow_focus() {
389  jQuery(".bwg_slideshow").each(function () {
390    bwg = jQuery(this).data('bwg');
391    if (jQuery('.bwg_slideshow[data-bwg=' + bwg + ']')[0].offsetHeight) {
392      if ( jQuery("#bwg_slideshow_image_container_" + bwg).length ) {
393        bwg_params[bwg] = JSON.parse(jQuery("#bwg_slideshow_image_container_" + bwg).attr("data-params"));
394        bwg_params[bwg]['event_stack'] = [];
395        window.clearInterval(window['bwg_playInterval' + bwg]);
396        if (!jQuery(".bwg_ctrl_btn_" + bwg).hasClass("bwg-icon-play")) {
397          bwg_play(bwg_params[bwg]['data'], bwg);
398        }
399      }
400    }
401  });
402}
403
404function bwg_carousel_focus() {
405  jQuery(".bwg_carousel").each(function () {
406    bwg = jQuery(this).data('bwg');
407    if ( jQuery('.bwg_carousel[data-bwg=' + bwg + ']')[0].offsetHeight ) {
408      if ( jQuery(".bwg_carousel_image_container_" + bwg).length ) {
409        if ( jQuery(".bwg_ctrl_btn_" + bwg).hasClass("bwg-icon-pause") ) {
410          bwg_params_carousel[bwg]['carousel'].start();
411        }
412      }
413    }
414  });
415}
416
417
418/**
419 * @param {boolean} isAll   do you need to stop all slideshows?.
420 */
421function bwg_slideshow_blur(isAll) {
422  jQuery(".bwg_slideshow").each(function () {
423    bwg = jQuery(this).data('bwg');
424    if (isAll || !jQuery('.bwg_slideshow[data-bwg=' + bwg + ']')[0].offsetHeight) {
425      if (jQuery("#bwg_slideshow_image_container_" + bwg).length) {
426        bwg_params[bwg] = JSON.parse(jQuery("#bwg_slideshow_image_container_" + bwg).attr("data-params"));
427        bwg_params[bwg]['event_stack'] = [];
428        window.clearInterval(window['bwg_playInterval' + bwg]);
429      }
430    }
431  });
432}
433
434/**
435 * @param {boolean} isAll   do you need to stop all carousels?.
436 */
437function bwg_carousel_blur( isAll ) {
438  jQuery(".bwg_carousel").each(function () {
439    bwg = jQuery(this).data('bwg');
440    if ( isAll || !jQuery('.bwg_carousel[data-bwg=' + bwg + ']')[0].offsetHeight ) {
441      if ( jQuery(".bwg_carousel_image_container_" + bwg).length && typeof bwg_params_carousel[bwg] !== 'undefined') {
442        bwg_params_carousel[bwg]['carousel'].pause();
443      }
444    }
445  });
446}
447
448
449/**
450 * @param {number} bwg.
451 */
452function bwg_carousel_ready(bwg) {
453  bwg_params_carousel[bwg] = [];
454  bwg_params_carousel[bwg]['bwg_currentCenterNum'] = 1;
455  bwg_params_carousel[bwg]['bwg_currentlyMoving'] = false;
456  bwg_params_carousel[bwg]['data'] = [];
457
458  if ( typeof instgrm !== 'undefined' && typeof instgrm.Embeds !== 'undefined' ) {
459    var instagram_embed = jQuery('.bwg_embed_frame_' + bwg);
460    var embed_max_height = instagram_embed.data('height');
461    instagram_embed.css({ 'display': 'none' });
462    instgrm.Embeds.process();
463    jQuery('.bwg_embed_frame_' + bwg + ' #instagram-embed-' + bwg ).css({
464      'max-height': embed_max_height + 'px',
465    });
466    instagram_embed.css({ 'display': 'inline-block' });
467  }
468
469
470  jQuery("#spider_carousel_left-ico_" + bwg).on("click", function (event) {
471    bwg_params_carousel[bwg]['carousel'].prev();
472    event.stopPropagation();
473    event.stopImmediatePropagation();
474  });
475  jQuery("#spider_carousel_right-ico_" + bwg).on("click", function (event) {
476    bwg_params_carousel[bwg]['carousel'].next();
477    event.stopPropagation();
478    event.stopImmediatePropagation();
479  });
480  if ( parseInt(bwg_params_carousel[bwg]['carousel_enable_autoplay']) ) {
481    jQuery(".bwg_carousel_play_pause_" + bwg).attr("title", bwg_objectsL10n.pause);
482    jQuery(".bwg_carousel_play_pause_" + bwg).attr("class", "bwg-icon-pause bwg_ctrl_bt
482n_" + bwg + " bwg_carousel_play_pause_" + bwg + "");
483  }
484
485  jQuery(".bwg_carousel_play_pause_" + bwg).on(bwg_click, function (event) {
486    if (jQuery(".bwg_ctrl_btn_" + bwg).hasClass("bwg-icon-play") ) {
487      /*play*/
488      jQuery(".bwg_carousel_play_pause_" + bwg).attr("title", bwg_objectsL10n.pause);
489      jQuery(".bwg_carousel_play_pause_" + bwg).attr("class", "bwg-icon-pause bwg_ctrl_btn_" + bwg + " bwg_carousel_play_pause_" + bwg + "");
490      bwg_params_carousel[bwg]['carousel'].start();
491    }
492    else {
493      /* Pause.*/
494      jQuery(".bwg_carousel_play_pause_" + bwg).attr("title", bwg_objectsL10n.play);
495      jQuery(".bwg_carousel_play_pause_" + bwg).attr("class", "bwg-icon-play bwg_ctrl_btn_" + bwg + " bwg_carousel_play_pause_" + bwg + "");
496      bwg_params_carousel[bwg]['carousel'].pause();
497    }
498    event.stopPropagation();
499    event.stopImmediatePropagation();
500  });
501  jQuery("#bwg_container1_" + bwg).on("swiperight", function () {
502    bwg_params_carousel[bwg]['carousel'].prev();
503  });
504  jQuery("#bwg_container1_" + bwg).on("swipeleft", function () {
505    bwg_params_carousel[bwg]['carousel'].next();
506  });
507}
508
509function bwg_carousel_resize() {
510  jQuery(".bwg-carousel").each(function () {
511    var bwg = jQuery(this).data("bwg");
512    if ( jQuery(".bwg_carousel-container" + bwg).length ) {
513      bwg_carousel_params(bwg, true);
514      bwg_params_carousel[bwg]['carousel'].pause();
515      bwg_carousel_watermark(bwg);
516      if ( !jQuery(".bwg_ctrl_btn_" + bwg).hasClass("bwg-icon-play") ) {
517        bwg_params_carousel[bwg]['carousel'].start();
518      }
519    }
520  });
521}
522
523/**
524 * @param {object} container gallery's container.
525 */
526function bwg_carousel_onload( container ) {
527  var bwg = container.data('bwg');
528  var last_container = container.find(".bwg_carousel-container" + bwg);
529  if ( last_container.length ) {
530    bwg_params_carousel[bwg] = last_container.data("params");
531    /* Store parent width to resize carousel only if width is changed. */
532    bwg_params_carousel[bwg]['parent_width'] = 0;
533    bwg_carousel_watermark(bwg);
534    bwg_carousel_params(bwg, false);
535    bwg_container_loaded(bwg);
536  }
537}
538
539function bwg_carousel_params(bwg, resize) {
540  var parentt = jQuery("#bwg_container1_" + bwg).parent();
541  /* Trick to set parent's width to elementor tab. */
542  if (parentt.hasClass('elementor-tab-content')) {
543    parentt.width(parentt.closest('.elementor-widget-wrap').width());
544  }
545  var parent_width = parentt.width();
546  var par = 1;
547  if ( parent_width < bwg_params_carousel[bwg]['carousel_r_width'] ) {
548    par = parent_width / bwg_params_carousel[bwg]['carousel_r_width'];
549  }
550  else {
551    parent_width = bwg_params_carousel[bwg]['carousel_r_width'];
552  }
553  /* Resize carousel only if parent width is changed. */
554  if ( bwg_params_carousel[bwg]['parent_width'] != parent_width ) {
555    bwg_params_carousel[bwg]['parent_width'] = parent_width;
556    if (bwg_params_carousel[bwg]['carousel_image_column_number'] > bwg_params_carousel[bwg]['count']) {
557      bwg_params_carousel[bwg]['carousel_image_column_number'] = bwg_params_carousel[bwg]['count'];
558    }
559
560    jQuery(".bwg_carousel_play_pause_" + bwg).css({display: (!parseInt(bwg_params_carousel[bwg]['carousel_play_pause_butt']) ? 'none' : '')});
561
562    if (!parseInt(bwg_params_carousel[bwg]['carousel_prev_next_butt'])) {
563      jQuery("#bwg_carousel-left" + bwg).css({display: 'none'});
564      jQuery("#bwg_carousel-right" + bwg).css({display: 'none'});
565    } else {
566      jQuery("#bwg_carousel-right" + bwg).css({display: ''});
567      jQuery("#bwg_carousel-left" + bwg).css({display: ''});
568    }
569
570    jQuery(".inner_instagram_iframe_bwg_embed_frame_" + bwg).each(function () {
571      /* 16 is 2*padding inside iframe */
572      /* 96 is 2*padding(top) + 1*padding(bottom) + 40(footer) + 32(header) */
573      var parent_container = jQuery(this).parent();
574      if (bwg_params_carousel[bwg]['image_height'] / (parseInt(parent_container.attr('data-height')) + 96) < bwg_params_carousel[bwg]['image_width'] / parseInt(parent_container.attr('data-width'))) {
575        parent_container.height(bwg_params_carousel[bwg]['image_height'] * par);
576        parent_container.width((parent_container.height() - 96) * parent_container.attr('data-width') / parent_container.attr('data-height') + 16);
577      } else {
578        parent_container.width(bwg_params_carousel[bwg]['image_width'] * par);
579        parent_container.height((parent_container.width() - 16) * parent_container.attr('data-height') / parent_container.attr('data-width') + 96);
580      }
581    });
582
583    jQuery(".bwg_carousel_image_container_" + bwg).css({
584      width: bwg_params_carousel[bwg]['image_width'] * par,
585      height: bwg_params_carousel[bwg]['image_height'] * par
586    });
587    jQuery(".bwg_carousel_watermark_text_" + bwg + ", .bwg_carousel_watermark_text_" + bwg + ":hover").css({fontSize: ((parent_width) * (bwg_params_carousel[bwg]['watermark_font_size'] / bwg_params_carousel[bwg]['image_width']) * par)});
588    jQuery(".bwg_carousel-image " + bwg).css({
589      width: bwg_params_carousel[bwg]['image_width'] * par,
590      height: bwg_params_carousel[bwg]['image_height'] * par
591    });
592    jQuery(".bwg_carousel_watermark_container_" + bwg).css({
593      width: bwg_params_carousel[bwg]['image_width'] * par,
594      height: bwg_params_carousel[bwg]['image_height'] * par
595    });
596    jQuery(".bwg_carousel_embed_video_" + bwg).css({
597      width: bwg_params_carousel[bwg]['image_width'] * par,
598      height: bwg_params_carousel[bwg]['image_height'] * par
599    });
600    jQuery(".bwg_carousel_watermark_spun_" + bwg).css({
601      width: bwg_params_carousel[bwg]['image_width'] * par,
602      height: bwg_params_carousel[bwg]['image_height'] * par
603    });
604    jQuery(".bwg_carousel-container" + bwg).css({
605      width: parent_width,
606      height: bwg_params_carousel[bwg]['image_height'] * par
607    });
608    jQuery(".bwg_video_hide" + bwg).css({
609      width: bwg_params_carousel[bwg]['image_width'] * par,
610      height: bwg_params_carousel[bwg]['image_height'] * par
611    });
612
613    if (!bwg_params_carousel[bwg]['carousel'] || resize) {
614      if (resize && bwg_params_carousel[bwg]['carousel']) {
615        bwg_params_carousel[bwg]['carousel'].pause();
616      }
617      bwg_params_carousel[bwg]['carousel'] = jQuery("#bwg_carousel" + bwg).featureCarousel({
618        containerWidth: parent_width * par,
619        containerHeight: bwg_params_carousel[bwg]['image_height'] * par,
620        fit_containerWidth: bwg_params_carousel[bwg]['carousel_fit_containerWidth'],
621        largeFeatureWidth: bwg_params_carousel[bwg]['image_width'] * par,
622        largeFeatureHeight: bwg_params_carousel[bwg]['image_height'] * par,
623        smallFeaturePar: bwg_params_carousel[bwg]['carousel_image_par'],
624        currentlyMoving: false,
625        startingFeature: bwg_params_carousel[bwg]['bwg_currentCenterNum'],
626        featuresArray: [],
627        timeoutVar: null,
628        rotationsRemaining: 0,
629        autoPlay: bwg_params_carousel[bwg]['car_inter'] * 1000,
630        interval: bwg_params_carousel[bwg]['carousel_interval'] * 1000,
631        imagecount: bwg_params_carousel[bwg]['carousel_image_column_number'],
632        bwg_number: bwg,
633        enable_image_title: bwg_params_carousel[bwg]['enable_image_title'],
634        borderWidth: 0
635      });
636    }
637  }
638}
639
640function bwg_carousel_watermark(bwg) {
641  var par = 1;
642  var parent_width = jQuery("#bwg_container1_" + bwg).parent().width();
643  if ( parent_width < bwg_params_carousel[bwg]['carousel_r_width'] ) {
644    par = parent_width / bwg_params_carousel[bwg]['carousel_r_width'];
645  }
646  if ( parent_width >= bwg_params_carousel[bwg]['image_width'] ) {
647    /* Set watermark container size.*/
648    bwg_carousel_change_watermark_container(bwg);
649    jQuery("#bwg_carousel_play_pause-ico_" + bwg).css({fontSize: bwg_params_carousel[bwg]['carousel_play_pause_btn_size']});
650    jQuery(".bwg_carousel_watermark_image_" + bwg).css({maxWidth: bwg_params_carousel[bwg]['watermark_width'] * par, maxHeight: bwg_params_carousel[bwg]['watermark_height'] * par});
651    jQuery(".bwg_carousel_watermark_text_" + bwg + ", .bwg_carousel_watermark_text_" + bwg + ":hover").css({fontSize: par * bwg_params_carousel[bwg]['watermark_font_size']});
652  }
653  else {
654    /* Set watermark container size.*/
655    var img_width = bwg_params_carousel[bwg]['image_width'] / par;
656    bwg_carousel_change_watermark_container(bwg);
657    jQuery(".bwg_carousel_watermark_image_" + bwg).css({maxWidth: ( parent_width * bwg_params_carousel[bwg]['watermark_width'] / img_width), maxHeight: (parent_width * bwg_params_carousel[bwg]['watermark_height'] / img_width)});
658    jQuery(".bwg_carousel_watermark_text_" + bwg + ", .bwg_carousel_watermark_text_" + bwg + ":hover").css({fontSize:  (parent_width * bwg_params_carousel[bwg]['watermark_font_size'] / img_width )});
659  }
660}
661
662function bwg_carousel_change_watermark_container(bwg) {
663  jQuery(".bwg_carousel" + bwg).children().each(function() {
664    if (jQuery(this).css("zIndex") == 2) {
665      var bwg_current_image_span = jQuery(this).find("img");
666      if (!bwg_current_image_span.length) {
667        bwg_current_image_span = jQuery(this).find("iframe");
668      }
669      var width = bwg_current_image_span.width();
670      var height = bwg_current_image_span.height();
671      jQuery(".bwg_carousel_watermark_spun_" + bwg).width(width);
672      jQuery(".bwg_carousel_watermark_spun_" + bwg).height(height);
673      jQuery(".bwg_carousel_title_spun_" + bwg).width(width);
674      jQuery(".bwg_carouel_title_spun_" + bwg).height(height);
675      jQuery(".bwg_carousel_watermark_" + bwg).css({display: 'none'});
676    }
677  });
678}
679
680/* Change hidden carousel items to visiblle */
681function bwg_carousel_preload( bwg, right ) {
682  var preload_images_count = 1;
683
684  var selector = jQuery(".bwg_carousel_preload").get();
685  if ( !right ) {
686    selector.reverse();
687  }
688  var i = 0;
689  jQuery(selector).each(function () {
690    if ( ++i > preload_images_count ) {
691      return false;
692    }
693    if ( jQuery(this).parent().hasClass('bwg_carousel_embed_video_' + bwg)
694      || jQuery(this).parent().hasClass('bwg_embed_frame_' + bwg)
695      || jQuery(this).parent().hasClass('bwg_carousel_video') ) {
696      /* Embed. */
697      jQuery(this).attr('src', jQuery(this).attr('data-src'));
698      jQuery(this).on("load", function () {
699        jQuery(this).removeClass('bwg_carousel_preload');
700      });
701      /* Load video after changing source. */
702      if ( jQuery(this).parent().hasClass('bwg_carousel_video') ) {
703        jQuery(".bwg_carousel_video")[0].load();
704        jQuery(this).parent().parent().removeClass('bwg_carousel_preload');
705      }
706      jQuery(this).removeAttr('data-src');
707    }
708    else {
709      /* Image. */
710      jQuery(this).css({
711        'background-image': "url('" + jQuery(this).attr('data-background') + "')",
712        'height': '100%',
713      });
714      jQuery(this).removeClass('bwg_carousel_preload');
715      jQuery(this).removeAttr('data-background');
716    }
717  });
718}
719
720/**
721 * @param {number} bwg.
722 */
723function bwg_slideshow_ready( bwg ) {
724  if ( jQuery("#bwg_slideshow_image_container_" + bwg).length ) {
725    bwg_params[bwg] = JSON.parse(jQuery("#bwg_slideshow_image_container_" + bwg).attr("data-params"));
726    bwg_params[bwg]['event_stack'] = [];
727    var slideshow_filmstrip_class_name = ".bwg_slideshow_filmstrip_" + bwg;
728    var filmstrip_thumbnail_key = 'bwg_slideshow_filmstrip_thumbnail_' + bwg;
729    bwg_slideshow_filmstrip_thumb[filmstrip_thumbnail_key] = {};
730    bwg_slideshow_filmstrip_thumb[filmstrip_thumbnail_key]['next_prev_index'] = 0;
731    var  slideshow_filmstrip_fix_count = false;
732    // Slideshow filmstrip type is Fix count.
733    if ( bwg_params[bwg]['slideshow_filmstrip_type'] == 2 ) {
734      slideshow_filmstrip_fix_count = true;
735      slideshow_filmstrip_class_name = ".bwg_slideshow_filmstrip_fix_count_" + bwg;
736    }
737    bwg_container_loaded(bwg);
738    var data = bwg_params[bwg]['data'];
739    jQuery("#bwg_container1_" + bwg).on("swiperight", function () {
740      bwg_change_image(parseInt(jQuery("#bwg_current_image_key_" + bwg).val()), (parseInt(jQuery("#bwg_current_image_key_" + bwg).val()) - bwg_iterator(bwg)) >= 0 ? (parseInt(jQuery("#bwg_current_image_key_" + bwg).val()) - bwg_iterator(bwg)) % data.length : data.length - 1, data, '', bwg);
741      return false;
742    });
743    jQuery("#bwg_container1_" + bwg).on("swipeleft", function () {
744      bwg_change_image(parseInt(jQuery("#bwg_current_image_key_" + bwg).val()), (parseInt(jQuery("#bwg_current_image_key_" + bwg).val()) + bwg_iterator(bwg) % data.length), data, '', bwg);
745      return false;
746    });
747    var isMobile = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
748    var bwg_click = isMobile ? 'touchend' : 'click';
749    bwg_popup_resize(bwg);
750    jQuery(".bwg_slideshow_watermark_" + bwg).css({ display: 'none' });
751    jQuery(".bwg_slideshow_title_text_" + bwg).css({ display: 'none' });
752    jQuery(".bwg_slideshow_description_text_" + bwg).css({ display: 'none' });
753    setTimeout(function () {
754      bwg_change_watermark_container(bwg);
755    }, 500);
756    /* Set image container height for Fix dimension */
757    if ( bwg_params[bwg]['slideshow_filmstrip_type'] == 1 ) {
758      if ( bwg_params[bwg]['filmstrip_direction'] == 'horizontal' ) {
759        jQuery(".bwg_slideshow_image_container_" + bwg).height(jQuery(".bwg_slideshow_image_wrap_" + bwg).height() - bwg_params[bwg]['slideshow_filmstrip_height']);
760      }
761      else {
762        jQuery(".bwg_slideshow_image_container_" + bwg).width(jQuery(".bwg_slideshow_image_wrap_" + bwg).width() - bwg_params[bwg]['slideshow_filmstrip_width']);
763      }
764    }
765    var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel";
766    /* FF doesn't recognize mousewheel as of FF3.x */
767    jQuery(slideshow_filmstrip_class_name).bind(mousewheelevt, function ( e ) {
768      var evt = window.event || e;
769      /* Equalize event object.*/
770      evt = evt.originalEvent ? evt.originalEvent : evt;
771      /* Convert to originalEvent if possible.*/
772      var delta = evt.detail ? evt.detail * (-40) : evt.wheelDelta;
773      /* Check for detail first, because it is used by Opera and FF.*/
774      if ( delta > 0 ) {
775        /* Scroll up.*/
776        jQuery(".bwg_slideshow_filmstrip_left_" + bwg).trigger("click");
777      }
778      else {
779        /* Scroll down.*/
780        jQuery(".bwg_slideshow_filmstrip_right_" + bwg).trigger("click");
781      }
782      return false;
783    });
784
785    var next_prev_params = {
786      'bwg': bwg,
787      'params': bwg_params[bwg],
788      'slideshow_filmstrip_class_name': slideshow_filmstrip_class_name
789    };
790
791    jQuery(".bwg_slideshow_filmstrip_right_" + bwg).on(bwg_click, function () {
792      if ( slideshow_filmstrip_fix_count == true ) {
793        // Slideshow filmstrip thumbnails animation busy.
794        // Lets allow to slide only previews sliding finished.
795        if ( bwg_slideshow_filmstrip_thumbnail_timer === false ) {
796          bwg_slideshow_filmstrip_thumbnail_timer = true;
797          bwg_slideshow_filmstrip_next( next_prev_params );
798          // Lets set timeout counter equal sliding duration time.
799          setTimeout(function () {
800            bwg_slideshow_filmstrip_thumbnail_timer = false;
801          }, 505);
802        }
803      }
804      else {
805        bwg_slideshow_filmstrip_next( next_prev_params );
806      }
807    });
808    jQuery(".bwg_slideshow_filmstrip_left_" + bwg).on(bwg_click, function () {
809      if ( slideshow_filmstrip_fix_count == true ) {
810        // Slideshow filmstrip thumbnails animation busy.
811        // Lets allow to slide only previews sliding finished.
812        if ( bwg_slideshow_filmstrip_thumbnail_timer === false ) {
813          bwg_slideshow_filmstrip_thumbnail_timer = true;
814          bwg_slideshow_filmstrip_prev( next_prev_params );
815          // Lets set timeout counter equal sliding duration time.
816          setTimeout(function () {
817            bwg_slideshow_filmstrip_thumbnail_timer = false;
818          }
818, 505);
819        }
820      }
821      else {
822        bwg_slideshow_filmstrip_prev( next_prev_params );
823      }
824    });
825    if ( bwg_params[bwg]['width_or_height'] == 'width' ) {
826      /* Set filmstrip initial position.*/
827      bwg_set_filmstrip_pos(jQuery(slideshow_filmstrip_class_name).width(), bwg);
828    }
829    else {
830      /* Set filmstrip initial position.*/
831      bwg_set_filmstrip_pos(jQuery(slideshow_filmstrip_class_name).height(), bwg);
832    }
833    /* Play/pause.*/
834    jQuery("#bwg_slideshow_play_pause_" + bwg).off(bwg_click).on(bwg_click, function () {
835      if ( jQuery(".bwg_ctrl_btn_" + bwg).hasClass("bwg-icon-play") ) {
836        bwg_play(bwg_params[bwg]['data'], bwg);
837        jQuery(".bwg_slideshow_play_pause_" + bwg).attr("title", bwg_objectsL10n.pause);
838        jQuery(".bwg_slideshow_play_pause_" + bwg).attr("class", "bwg-icon-pause bwg_ctrl_btn_" + bwg + " bwg_slideshow_play_pause_" + bwg + "");
839        if ( bwg_params[bwg]['enable_slideshow_music'] == 1 ) {
840          document.getElementById("bwg_audio_" + bwg).play();
841        }
842      }
843      else {
844        /* Pause.*/
845        window.clearInterval(window['bwg_playInterval' + bwg]);
846        jQuery(".bwg_slideshow_play_pause_" + bwg).attr("title", "Play");
847        jQuery(".bwg_slideshow_play_pause_" + bwg).attr("class", "bwg-icon-play bwg_ctrl_btn_" + bwg + " bwg_slideshow_play_pause_" + bwg + "");
848        if ( bwg_params[bwg]['enable_slideshow_music'] == 1 ) {
849          document.getElementById("bwg_audio_" + bwg).pause();
850        }
851      }
852    });
853    if ( bwg_params[bwg]['enable_slideshow_autoplay'] != 0 ) {
854      bwg_play(bwg_params[bwg]['data'], bwg);
855      jQuery(".bwg_slideshow_play_pause_" + bwg).attr("title", bwg_objectsL10n.pause);
856      jQuery(".bwg_slideshow_play_pause_" + bwg).attr("class", "bwg-icon-pause bwg_ctrl_btn_" + bwg + " bwg_slideshow_play_pause_" + bwg + "");
857      if ( bwg_params[bwg]['enable_slideshow_music'] == 1 && jQuery("#bwg_audio_" + bwg).length ) {
858        document.getElementById("bwg_audio_" + bwg).play();
859      }
860    }
861    if ( bwg_params[bwg]['preload_images'] ) {
862      bwg_preload_images(parseInt(jQuery("#bwg_current_image_key_".$bwg).val()), bwg);
863    }
864    jQuery(".bwg_slideshow_image_" + bwg).removeAttr("width");
865    jQuery(".bwg_slideshow_image_" + bwg).removeAttr("height");
866    /* Uses Instagram oEmbed data to create iframe tag. */
867    jQuery('#instagram-embed-' + bwg).hide();
868    if ( typeof instgrm !== 'undefined' && typeof instgrm.Embeds !== 'undefined' ) {
869      var instagram_embed = jQuery('.bwg_embed_frame_' + bwg);
870      var embed_max_height = instagram_embed.data('height');
871      instagram_embed.css({ 'display': 'none' });
872      instgrm.Embeds.process();
873      jQuery('.bwg_embed_frame_' + bwg + ' #instagram-embed-' + bwg ).css({
874        'max-height': embed_max_height + 'px',
875      });
876      instagram_embed.css({ 'display': 'inline-block' });
877    }
878
879    /* Set max height to instagram embed iframe */
880    if ( jQuery('.elementor-editor-active .bwg_embed_frame_' + bwg).length > 0 ) {
881      checkIframeLoaded();
882      function checkIframeLoaded() {
883        // Get a handle to the iframe element
884        var iframe = jQuery(document).find('.bwg_embed_frame_' + bwg+' iframe');
885
886        // Check if loading is complete
887        if (  iframe.length  > 0 ) {
888          var instagram_embed = jQuery('.bwg_embed_frame_' + bwg);
889          var embed_max_height = instagram_embed.data('height');
890          iframe.css({
891            'max-height': embed_max_height + 'px',
892          });
893          return;
894        }
895
896        // If we are here, it is not loaded. Set things up so we check   the status again in 100 milliseconds
897        window.setTimeout(checkIframeLoaded, 500);
898      }
899    }
900  }
901}
902
903function bwg_image_browser_resize() {
904  jQuery(".bwg_image_browser").each(function () {
905    var bwg = jQuery(this).attr('data-bwg');
906    if (jQuery('.image_browser_images_conteiner_' + bwg).length) {
907      bwg_params_ib[bwg] = JSON.parse(jQuery('#bwg_container1_' + bwg + ' .image_browser_images_conteiner_' + bwg ).attr('data-params'));
908      bwg_image_browser( bwg );
909    }
910  });
911}
912
913/**
914 * @param {object} container gallery main container.
915 */
916function bwg_image_browser_ready(container) {
917  /* For ImageBrowser */
918  var bwg = container.data('bwg');
919  bwg_container_loaded( bwg );
920  if ( typeof instgrm !== 'undefined' && typeof instgrm.Embeds !== 'undefined' ) {
921    instgrm.Embeds.process();
922  }
923  if (jQuery('.image_browser_images_conteiner_' + bwg).length) {
924    bwg_params_ib[bwg] = JSON.parse(jQuery('.image_browser_images_conteiner_' + bwg).attr('data-params'));
925    setTimeout(function () {
926      bwg_image_browser(bwg);
927    }, 3);
928  }
929}
930
931/* hide search_placeholder_title class container */
932function bwg_search_focus(that) {
933  jQuery(that).parent().find('.bwg_search_input').focus();
934  jQuery(that).hide();
935}
936
937/* show search and reset icons */
938function bwg_key_press(that) {
939  jQuery(that).parent().find('.bwg_search_reset_container').removeClass("bwg-hidden");
940  jQuery(that).parent().find('.bwg_search_loupe_container1').removeClass("bwg-hidden");
941}
942
943function bwg_all_thumnails_loaded(that) {
944  var thumbnails_count = 0;
945  var thumbnails_loaded = jQuery(that).find("img").length;
946  if (0 == thumbnails_loaded) {
947    bwg_all_thumbnails_loaded_callback(that);
948  }
949  else {
950    jQuery( that ).find( "img" ).each( function () {
951      var fakeSrc = jQuery( this ).attr( "src" );
952      jQuery( "<img/>" ).attr( "src", fakeSrc ).on( "load error", function () {
953        if ( ++thumbnails_count >= thumbnails_loaded ) {
954          bwg_all_thumbnails_loaded_callback( that );
955        }
956      });
957    });
958  }
959
960  /* If there is error (empty gallery, "No Images found."). Show Load Icon before load gallery. */
961  jQuery(".bwg_container").each(function () {
962    var bwg = jQuery(this).data('bwg');
963    if ( jQuery(this).find(".wd_error").length > 0 ) {
964      bwg_container_loaded(bwg);
965    }
966  });
967
968  return thumbnails_loaded == 0;
969}
970
971function bwg_all_thumbnails_loaded_callback(that) {
972  if (jQuery(that).hasClass('bwg-thumbnails') && !jQuery(that).hasClass('bwg-masonry-thumbn
972ails')) {
973    bwg_thumbnail( that );
974  }
975  if (jQuery(that).hasClass('bwg-masonry-thumbnails')) {
976    bwg_thumbnail_masonry( that );
977  }
978  if (jQuery(that).hasClass('bwg-album-extended')) {
979    bwg_album_extended( that );
980  }
981}
982
983function bwg_album_thumbnail(that) {
984  bwg_container_loaded(jQuery(that).data('bwg'));
985}
986function bwg_album_extended(that) {
987  var container_width = jQuery(that).width();
988  var thumb_width = jQuery(that).data("thumbnail-width");
989  var spacing = jQuery(that).data("spacing");
990  var max_count = jQuery(that).data("max-count");
991  var column_count = parseInt(container_width / (2 * thumb_width));
992  if ( column_count < 1 ) {
993    column_count = 1;
994  }
995  if (column_count > max_count) {
996    column_count = max_count;
997  }
998  var min_width = 100 / column_count;
999  var bwg_item = jQuery(that).find(".bwg-extended-item");
1000  var margin_left = parseInt(bwg_item.css("margin-left"));
1001  var margin_right = parseInt(bwg_item.css("margin-right"));
1002  bwg_item.css({
1003    width: "calc(" + min_width + "% - " + (margin_left + margin_right) + "px)"
1004  });
1005  if ( bwg_item.width() < thumb_width ) {
1006    bwg_item.find(".bwg-extended-item0, .bwg-extended-item1").css({
1007      width: 'calc(100% - ' + spacing + 'px)'
1008    });
1009  }
1010  else if ( bwg_item.width() > 2 * thumb_width ) {
1011    bwg_item.find(".bwg-extended-item0").css({
1012      width: 'calc(50% - ' + spacing + 'px)'
1013    });
1014    bwg_item.find(".bwg-extended-item1").css({
1015      width: 'calc(100% - ' + (thumb_width + spacing * 2) + 'px)'
1016    });
1017  }
1018  else {
1019    bwg_item.find(".bwg-extended-item0, .bwg-extended-item1").css({
1020      width: 'calc(50% - ' + spacing + 'px)'
1021    });
1022  }
1023
1024  jQuery(that).children(".bwg-extended-item").each(function () {
1025    var image = jQuery(this).find("img");
1026    var item0 = jQuery(this).find(".bwg-item0");
1027    var item2 = jQuery(this).find(".bwg-item2");
1028    var image_width = image.data('width');
1029    var image_height = image.data('height');
1030    if(image_width == '' || image_height == '') {
1031      image_width = image.width();
1032      image_height = image.height();
1033    }
1034    var scale = image_width/image_height;
1035
1036    if ( (item2.width() / item2.height()) > (image_width / image_height) ) {
1037      if ( item2.width() > image_width ) {
1038        image.css({width: "100%", height: item2.width()/scale});
1039      }
1040      else {
1041        image.css({maxWidth: "100%", height: item2.width()/scale});
1042      }
1043      image_width = item2.width();
1044      image_height = item2.width()/scale;
1045    }
1046    else {
1047      if ( item2.height() > image_height ) {
1048        image.css({height : "100%", width : item2.height()*scale, maxWidth : 'initial'});
1049      }
1050      else {
1051        image.css({maxHeight: "100%", width: item2.height()*scale, maxWidth:'initial'});
1052      }
1053      image_height = item2.height();
1054      image_width = item2.height()*scale;
1055    }
1056    jQuery(this).find(".bwg-item2").css({
1057      marginLeft: (item0.width() - image_width) / 2,
1058      marginTop: (item0.height() - image_height) / 2
1059    });
1060  });
1061  bwg_container_loaded(jQuery(that).data('bwg'));
1062}
1063
1064function bwg_thumbnail(that) {
1065  var container_width = jQuery(that).width();
1066  var thumb_width = jQuery(that).data("thumbnail-width");
1067  var max_count = jQuery(that).data("max-count");
1068  var column_count = parseInt(container_width / thumb_width) + 1;
1069  if (column_count > max_count) {
1070    column_count = max_count;
1071  }
1072  /*var flex = 1 / column_count;*/
1073  var min_width = 100 / column_count;
1074  var bwg_item = jQuery(that).find(".bwg-item");
1075  bwg_item.css({
1076    /*flexGrow: flex,*/
1077    width: min_width + "%"
1078  });
1079  jQuery(that).children(".bwg-item").each(function () {
1080    var image = jQuery(this).find("img");
1081    var item2 = jQuery(this).find(".bwg-item2");
1082    var item1 = jQuery(this).find(".bwg-item1");
1083    var container_width = item2.width() > 0 ? item2.width() : item1.width();
1084    var container_height = item2.height() > 0 ? item2.height() : item1.height();
1085    var image_width = image.data('width');
1086    var image_height = image.data('height');
1087    if(image_width == '' || image_height == '' || typeof image_width === 'undefined' || typeof image_height === 'undefined') {
1088      image_width = image.width();
1089      image_height = image.height();
1090    }
1091    var scale = image_width/image_height;
1092    image.removeAttr("style");
1093    if ( (container_width / container_height) > scale ) {
1094      if ( container_width > image_width ) {
1095        image.css({width: "100%", height: container_width/scale});
1096      }
1097      else {
1098        /* Math.ceil image width in some cases less from the container with due to rounded */
1099        image.css({maxWidth: "100%", height: Math.ceil(container_width/scale)});
1100      }
1101      image_width = container_width;
1102      image_height = container_width/scale;
1103    }
1104    else {
1105      if ( container_height > image.height() ) {
1106        image.css({height : "100%", width : container_height*scale, maxWidth : 'initial'});
1107      }
1108      else {
1109        image.css({maxHeight: "100%", width: container_height*scale, maxWidth:'initial'});
1110      }
1111      image_height = container_height;
1112      image_width = container_height*scale;
1113    }
1114
1115    jQuery(this).find(".bwg-item2").css({
1116      marginLeft: (container_width - image_width) / 2,
1117      marginTop: (container_height - image_height) / 2
1118    });
1119  });
1120  bwg_container_loaded(jQuery(that).data('bwg'));
1121}
1122
1123function bwg_thumbnail_masonry(that) {
1124  bwg = jQuery(that).attr("data-bwg");
1125  var type = "#bwg_thumbnails_masonry_" + bwg;
1126  if ( jQuery("#bwg_album_masonry_" + bwg ).length) {
1127    type = "#bwg_album_masonry_" + bwg;
1128  }
1129  if ( jQuery(".bwg-container-temp" + bwg ).length === 0 ) {
1130    jQuery(type).clone().appendTo("#bwg_container3_" + bwg).removeAttr("id").removeClass("bwg-container-" + bwg).addClass("bwg-container-temp" + bwg);
1131    jQuery(".bwg-container-temp" + bwg).empty();
1132  }
1133  var temp = jQuery(".bwg-container-temp" + bwg);
1134  var cont = jQuery(type);
1135  var container = temp;
1136  temp.prepend( cont.html() );
1137
1138  container.find('.bwg-empty-item').remove();
1139  var masonry_type = container.data("masonry-type");
1140  if ('horizontal' == masonry_type) {
1141    var thumb_height = container.data( "thumbnail-height" );
1142    var max_count = container.data( "max-count" );
1143    var column_widths = [];
1144    for ( i = 0; i < max_count; i++ ) {
1145      column_widths.push( 0 );
1146    }
1147    container.find( ".bwg-item" ).each( function () {
1148      var order = column_widths.indexOf( Math.min.apply( Math, column_widths ) );
1149      jQuery( this ).css( { height: thumb_height, order: order + 1 } );
1150      /* Use getBoundingClientRect instead of jQuery.width() to avoid rounding. */
1151      column_widths[order] += jQuery( this )[0].getBoundingClientRect().width;
1152    } );
1153    var container_width = Math.max.apply( Math, column_widths );
1154    container.width( container_width );
1155    /* Equalize all rows. */
1156    for ( i = 0; i < max_count; i++ ) {
1157      if ( column_widths[i] < container_width ) {
1158        container.append( jQuery( '<div class="bwg-item bwg-empty-item"></div>' ).css( {
1159          height: thumb_height,
1160          order: i + 1,
1161          width: container_width - column_widths[i]
1162        } ) );
1163      }
1164    }
1165  }
1166  else {
1167    container.removeAttr('style');
1168    var container_width = container.width();
1169    var thumb_width = container.data( "thumbnail-width" );
1170    var thumb_border = container.data( "thumbnail-border" );
1171    var thumb_padding = container.data( "thumbnail-padding" );
1172    var max_count = container.data( "max-count" );
1173    var column_count = parseInt( container_width / thumb_width ) + (container.data('resizable-thumbnails') == '0' ? 0 : 1);
1174    if ( column_count > max_count ) {
1175      column_count = max_count;
1176    }
1177    var thumb_count = container.find( ".bwg-item" ).length;
1178    if ( thumb_count < column_count ) {
1179      column_count = thumb_count;
1180    }
1181    var min_width = 100 / column_count;
1182    var column_heights = [];
1183    var scaleHeight;
1184    var scale;
1185    for ( i = 0; i < column_count; i++ ) {
1186      column_heights.push( 0 );
1187    }
1188    container.find( ".bwg-item" ).each( function () {
1189      var order = column_heights.indexOf( Math.min.apply( Math, column_heights ) );
1190      var bwg_item_image = jQuery( this ).find("img");
1191
1192      jQuery( this ).css( { width: min_width + "%", order: order + 1 } );
1193
1194      /* need set height for all images formats, except for SVG */
1195      if ( typeof bwg_item_image.data("src") !== "undefined" && bwg_item_image.data("src").indexOf("svg") === -1 ) {
1196        if ( bwg_item_image.attr("data-width").length > 0 && bwg_item_image.attr("data-height").length > 0 ) {
1197          scale = parseInt(bwg_item_image.data("width")) / parseInt(bwg_item_image.data("height"));
1198          scaleHeight = bwg_item_image.width () / scale;
1199
1200          /* calculating height of image title and description */
1201          /* finding title/description with 'a>' selector to avoid calculating heights for 'Show on hover' option. */
1202          var title_h = this.querySelector("a .bwg-zoom-effect-overlay .bwg-title2") || !this.querySelector("a .bwg-title1 .bwg-title2") ? 0 : this.querySelector("a .bwg-title1 .bwg-title2").getClientRects()[0].height;
1203          var desc_h = ( jQuery( this ).find('.bwg-masonry-thumb-description').length > 0 ) ? jQuery( this ).find('.bwg-masonry-thumb-description').height() : 0;
1204          var k = title_h + desc_h;
1205          jQuery( this ).height( Math.floor(scaleHeight + k + (thumb_border * 2)));
1206        }
1207      }
1208      /* Use getBoundingClientRect instead of jQuery.height() to avoid rounding. */
1209      column_heights[order] += jQuery( this )[0].getBoundingClientRect().height;
1210    } );
1211
1212    var container_height = Math.max.apply( Math, column_heights );
1213
1214    /* Equalize all columns. */
1215    for ( i = 0; i < column_count; i++ ) {
1216      if ( column_heights[i] < container_height ) {
1217        container.append( jQuery( '<div class="bwg-item bwg-empty-item"></div>' ).css( {
1218          width: min_width + "%",
1219          order: i + 1,
1220          height: container_height - column_heights[i]
1221        } ) );
1222      }
1223    }
1224
1225    container.outerWidth( column_count * ( thumb_width + (thumb_border * 2) ) );
1226    container.height( container_height );
1227  }
1228
1229  if ( temp.html() != "" ) {
1230    cont.outerWidth( column_count * ( thumb_width + (thumb_border * 2) ) );
1231    if ( container_height != '0' ) {
1232      cont.css('opacity',"1");
1233      cont.height( container_height );
1234    } else {
1235      cont.css('opacity',"0");
1236    }
1237
1238    cont.empty();
1239    var html = temp.html();
1240    cont.append(html);
1241
1242    /* Lazy Load */
1243    cont.find('.bwg_lazyload').each( function() {
1244      if (jQuery(this).data("src") != undefined && jQuery(this).data("src") != '') {
1245        jQuery(this).attr("src", jQuery(this).data("src"));
1246        jQuery(this).on("load", function() {
1247          jQuery(this).removeClass("lazy_loader");
1248        });
1249      }
1250    });
1251    temp.empty().hide();
1252  }
1253  bwg_container_loaded(container.data('bwg'));
1254}
1255
1256function bwg_container_loaded(bwg) {
1257  jQuery('#gal_front_form_' + bwg).removeClass('bwg-hidden');
1258  jQuery('#ajax_loading_' + bwg).addClass('bwg-hidden');
1259  jQuery(".bwg_container img").removeAttr('width').removeAttr('height');
1260}
1261
1262function bwg_thumbnail_mosaic_logic( container ) {
1263  var bwg = container.attr('data-bwg');
1264  var block_id = container.attr('data-block-id');
1265  var padding_px = parseInt(container.attr('data-thumb-padding')) / 2;
1266  var border_px = parseInt(container.attr('data-thumb-border'));
1267  var border_and_padding = border_px + padding_px;
1268  if (container.attr('data-mosaic-direction') == 'horizontal') {
1269    var thumb_height = parseInt(container.attr('data-height'));
1270    /*resizable mosaic*/
1271    if (container.attr('data-resizable') == '1') {
1272      if (jQuery(window).width() >= 1920) {
1273        var thumbnail_height = (1+jQuery(window).width()/1920)*thumb_height;
1274      }
1275      else if (jQuery(window).width() <= 640) {
1276        var thumbnail_height = jQuery(window).width()/640*thumb_height;
1277      }
1278      else {
1279        var thumbnail_height = thumb_height;
1280      }
1281    }
1282    else {
1283      var thumbnail_height = thumb_height;
1284    }
1285
1286    /* initialize */
1287    var mosaic_pics = jQuery(".bwg_mosaic_thumb_" + bwg);
1288    mosaic_pics.each(function (index) {
1289      var thumb_w = jQuery(this).data('width');
1290      var thumb_h = jQuery(this).data('height');
1291      if(thumb_w == '' || thumb_h == '' || typeof thumb_w === 'undefined' || typeof thumb_h === 'undefined') {
1292        thumb_w = mosaic_pics.get(index).naturalWidth;
1293        thumb_h = mosaic_pics.get(index).naturalHeight;
1294      }
1295      thumb_w = thumb_w * thumbnail_height / thumb_h;
1296      mosaic_pics.eq(index).css({ cssText: 'width:' + thumb_w + 'px !important; height:' + thumbnail_height + 'px !important;' });
1297    });
1298    /* resize */
1299    var divwidth = jQuery("#bwg_mosaic_thumbnails_div_" + bwg).width() / 100 * parseInt(container.attr('data-total-width'));
1300    /*set absolute mosaic width*/
1301    jQuery("#" + block_id).width(divwidth);
1302    var row_height = thumbnail_height + 2 * border_and_padding;
1303    var row_number = 0;
1304    var row_of_img = [];
1305    /* row of the current image*/
1306    row_of_img[0] = 0;
1307    var imgs_by_rows = [];
1308    /* number of images in each row */
1309    imgs_by_rows[0] = 0;
1310    var row_cum_width = 0;
1311    /* width of the current row */
1312    /* create masonry horizontal */
1313    mosaic_pics.each(function (index) {
1314      row_cum_width2 = row_cum_width + mosaic_pics.eq(index).width() + 2 * border_and_padding;
1315      if (row_cum_width2 - divwidth < 0) { /* add the image to the row */
1316        row_cum_width = row_cum_width2;
1317        row_of_img[index] = row_number;
1318        imgs_by_rows[row_number]++;
1319      }
1320      else {
1321        if (index !== mosaic_pics.length - 1) { /* if not last element */
1322          if ((Math.abs(row_cum_width - divwidth) > Math.abs(row_cum_width2 - divwidth)) || !(!(Math.abs(row_cum_width - divwidth) <= Math.abs(row_cum_width2 - divwidth)) || !(imgs_by_rows[row_number] == 0))) {
1323            if (index !== mosaic_pics.length - 2) { /* add and shrink if not the second */
1324              row_cum_width = row_cum_width2;
1325              row_of_img[index] = row_number;
1326              imgs_by_rows[row_number]++;
1327              row_number++;
1328              imgs_by_rows[row_number] = 0;
1329              row_cum_width = 0;
1330            }
1331            else { /* add second but NOT shrink and not change row */
1332              row_cum_width = row_cum_width2;
1333              row_of_img[index] = row_number;
1334              imgs_by_rows[row_number]++;
1335            }
1336          }
1337          else { /* add to new row and  stretch prev row (or shrink if even one pic is big) */
1338            row_number++;
1339            imgs_by_rows[row_number] = 1;
1340            row_of_img[index] = row_number;
1341            row_cum_width = row_cum_width2 - row_cum_width;
1342          }
1343        }
1344        else { /* if the last element, add and shrink */
1345          row_cum_width = row_cum_width2;
1346          row_of_img[index] = row_number;
1347          imgs_by_rows[row_number]++;
1348        }
1349      }
1350    });
1351    /* create mosaics */
1352    var stretch = [];
1353    /* stretch[row] factors */
1354    var row_new_height = [];
1355    /* find stretch factors */
1356    for (var row = 0; row <= row_number; row++) {
1357      row_cum_width = 0;
1358      mosaic_pics.each(function (index) {
1359        if (row_of_img[index] == row) {
1360          row_cum_width += mosaic_pics.eq(index).width();
1361        }
1362      });
1363      stretch[row] = x = (divwidth - imgs_by_rows[row] * 2 * border_and_padding) / row_cum_width;
1364      row_new_height[row] = (row_height - 2 * border_and_padding) * stretch[row] + 2 * border_and_padding;
1365    }
1366    /* To fix images width if the count of images are few counts and there is only one row */
1367    if ( row_number == 0 ) {
1368      for ( var row = 0; row <= row_number; row++ ) {
1369        if ( row_new_height[row] > thumbnail_height )  {
1370          stretch[row] = 1;
1371          row_new_height[row] = row_height;
1372        }
1373      }
1374    }
1375    /* stretch and shift to create mosaic horizontal */
1376    var last_img_index = [];
1377    /* last image in row */
1378    last_img_index[0] = 0;
1379    /* zero points */
1380    var img_left = [];
1381    var row_top = [];
1382    img_left[0] = 0;
1383    row_top[0] = 0;
1384    for (var row = 1; row <= row_number; row++) {
1385      img_left[row] = img_left[0];
1386      row_top[row] = row_top[row - 1] + row_new_height[row - 1];
1387    }
1388    mosaic_pics.each(function (index) {
1389      var thumb_w = mosaic_pics.eq(index).width();
1390      var thumb_h = mosaic_pics.eq(index).height();
1391      var pic_width = thumb_w * stretch[row_of_img[index]];
1392      var pic_height = thumb_h * stretch[row_of_img[index]]
1393      mosaic_pics.eq(index).css({ cssText: 'width:' + pic_width + 'px !important; height:' + pic_height + 'px !important;' });
1394      mosaic_pics.eq(index).parent().css({
1395        top: row_top[row_of_img[index]],
1396        left: img_left[row_of_img[index]]
1397      });
1398      img_left[row_of_img[index]] += thumb_w * stretch[row_of_img[index]] + 2 * border_and_padding;
1399      last_img_index[row_of_img[index]] = index;
1400    });
1401    jQuery("#" + block_id).height(row_top[row_number] + row_new_height[row_number] - row_top[0]);
1402  }
1403  else {
1404    var thumb_width = parseInt(container.attr('data-width'));
1405    /* Resizable mosaic.*/
1406    if (container.attr('data-resizable') == '1') {
1407      if (jQuery(window).width() >= 1920) {
1408        var thumbnail_width = (1 + jQuery(window).width() / 1920) * thumb_width;
1409      }
1410      else if (jQuery(window).width() <= 640) {
1411        var thumbnail_width = jQuery(window).width() / 640 * thumb_width;
1412      }
1413      else {
1414        var thumbnail_width = thumb_width;
1415      }
1416      /* Custom solution for 10web.io web site gallery plugin page mosaic view for 4 columns view */
1417      if( jQuery(".header-content-with_tab").length > 0 ) {
1418        var thumbnail_width = (jQuery(".header-content-with_tab").width()) / 4 - 10;
1419      }
1420    }
1421    else {
1422      var thumbnail_width = thumb_width;
1423      var container_width = jQuery(".bwg_container").width();
1424      if ( typeof container_width !== 'undefined' && container_width < thumb_width ) {
1425        thumbnail_width = container_width;
1426      }
1427    }
1428    /* Initialize.*/
1429    var mosaic_pics = jQuery(".bwg_mosaic_thumb_" + bwg);
1430    mosaic_pics.each(function (index) {
1431      jQuery(this).removeAttr('style');
1432      jQuery(this).parent().removeAttr('style');
1433      var thumb_w = jQuery(this).data('width');
1434      var thumb_h = jQuery(this).data('height');
1435      if(thumb_w == '' || thumb_h == '' || typeof thumb_w === 'undefined' || typeof thumb_h === 'undefined') {
1436        thumb_w = mosaic_pics.get(index).naturalWidth;
1437        thumb_h = mosaic_pics.get(index).naturalHeight;
1438        if ( thumb_h === 0 || thumb_h === '' ) {
1439          thumb_h = thumbnail_width;
1440        }
1441        if ( thumb_w === 0 || thumb_w === '' ) {
1442          thumb_w = thumbnail_width;
1443        }
1444      }
1445      mosaic_pics.eq(index).css({ cssText: 'width:' + thumbnail_width +'px !important; height:' + (thumb_h * thumbnail_width / thumb_w) + 'px !important;' });
1446    });
1447    /* Resize.*/
1448    var divwidth = jQuery("#bwg_mosaic_thumbnails_div_" + bwg).width() / 100 * parseInt(container.attr('data-total-width'));
1449    /* Set absolute width of mosaic.*/
1450    jQuery('#' + block_id).width(divwidth);
1451    var col_width = thumbnail_width + 2 * border_and_padding < divwidth ? thumbnail_width : divwidth - 2 * border_and_padding;
1452    /* Use Math.min to fix images width if the count of images are less than the column count */
1453    var col_number = Math.min( Math.floor(divwidth / (col_width + 2 * border_and_padding)), mosaic_pics.length);
1454    var col_of_img = [];
1455    /*column of the current image*/
1456    col_of_img[0] = 0;
1457    var imgs_by_cols = [];
1458    /*number of images in each column*/
1459    /*zero points*/
1460    var min_top = [];
1461    for (var x = 0; x < col_number; x++) {
1462      min_top[x] = 0;
1463      imgs_by_cols[x] = 0;
1464    }
1465    var img_wrap_left = 0;
1466    /*create masonry vertical*/
1467    mosaic_pics.each(function (index) {
1468      var col = 0;
1469      var min = min_top[0];
1470      for (var x = 0; x < col_number; x++) {
1471        if (min > min_top[x]) {
1472          min = min_top[x];
1473          col = x;
1474        }
1475      }
1476      col_of_img[index] = col;
1477      /*store in which col is arranged*/
1478      imgs_by_cols[col]++;
1479      img_container_top = min;
1480      img_container_left = img_wrap_left + col * (col_width + 2 * border_and_padding);
1481      mosaic_pics.eq(index).parent().css({top: img_container_top, left: img_container_left});
1482      min_top[col] += mosaic_pics.eq(index).height() + 2 * border_and_padding;
1483    });
1484    /*create mosaics*/
1485    var stretch = [];
1486    stretch[0] = 1;
1487    var sum_col_width = 0;
1488    var sum_col_height = [];
1489    /*array to store height of every column*/
1490    /*solve equations to calculate stretch[col] factors*/
1491    var axbx = 0;
1492    var axpxbx = 0;
1493    for (var x = 0; x < col_number; x++) {
1494      sum_col_width += col_width;
1495      sum_col_height[x] = 0;
1496      mosaic_pics.each(function (index) {
1497        if (col_of_img[index] == x) {
1498          sum_col_height[x] += mosaic_pics.eq(index).height();
1499        }
1500      });
1501      if (sum_col_height[x] != 0) {
1502        axbx += col_width / sum_col_height[x];
1503        axpxbx += col_width * imgs_by_cols[x] * 2 * border_and_padding / sum_col_height[x];
1504      }
1505    }
1506    var common_height = 0;
1507    if (axbx != 0) {
1508      common_height = (sum_col_width + axpxbx) / axbx;
1509    }
1510    for (var x = 0; x < col_number; x++) {
1511      if (sum_col_height[x] != 0) {
1512        stretch[x] = (common_height - imgs_by_cols[x] * 2 * border_and_padding) / sum_col_height[x];
1513      }
1514    }
1515    var img_container_left = [];
1516    /*position.left of every column*/
1517    img_container_left[0] = img_wrap_left;
1518    for (var x = 1; x <= col_number; x++) {
1519      img_container_left[x] = img_container_left[x - 1] + col_width * stretch[x - 1] + 2 * border_and_padding;
1520    }
1521    /*reset min_top array to the position.top of #wrap container*/
1522    var img_container_top = [];
1523    for (var x = 0; x < col_number; x++) {
1524      img_container_top[x] = 0;
1525    }
1526    /*stretch and shift to create mosaic verical*/
1527    var last_img_index = [];
1528    /* last image in column*/
1529    last_img_index[0] = 0;
1530    mosaic_pics.each(function (index) {
1531      var thumb_w = mosaic_pics.eq(index).width();
1532      var thumb_h = mosaic_pics.eq(index).height();
1533      var pic_width = (thumb_w * stretch[col_of_img[index]]);
1534      var pic_height = (thumb_h * stretch[col_of_img[index]]);
1535      mosaic_pics.eq(index).css({ cssText: 'width:' + pic_width + 'px !important; height:' + pic_height + 'px !important;' });
1536      mosaic_pics.eq(index).parent().css({
1537        top: img_container_top[col_of_img[index]],
1538        left: img_container_left[col_of_img[index]]
1539      });
1540      img_container_top[col_of_img[index]] += thumb_h * stretch[col_of_img[index]] + 2 * border_and_padding;
1541      last_img_index[col_of_img[index]] = index;
1542    });
1543    jQuery("#" + block_id).width(img_container_left[col_number]).height(img_container_top[0]);
1544  }
1545}
1546
1547function bwg_thumbnail_mosaic(that) {
1548  var container = jQuery(that);
1549  var dfd = jQuery.Deferred();
1550  dfd.done( [bwg_thumbnail_mosaic_logic] )
1551     .done( function(container) {
1552       if ( container.data('mosaic-thumb-transition') != '1' ) {
1553         jQuery('.bwg_mosaic_thumb_spun_' + bwg).css({
1554           'transition': 'all 0.3s ease 0s',
1555           '-webkit-transition': 'all 0.3s ease 0s'
1556         });
1557       }
1558       /*IMPORTANT!*/
1559       var bwg = container.data('bwg');
1560       jQuery(".bwg_mosaic_thumbnails_" + bwg).css({visibility: 'visible'});
1561       jQuery(".tablenav-pages_" + bwg).css({visibility: 'visible'});
1562       bwg_container_loaded(bwg);
1563       jQuery(".bwg_mosaic_thumb_"+bwg).removeClass("bwg-hidden");
1564       jQuery("#bwg_mosaic_thumbnails_div_"+bwg).removeClass("bwg-hidden");
1565     });
1566
1567  dfd.resolve(container);
1568
1569  if (container.attr('data-image-title') == 'hover') {
1570    var padding_px = parseInt(container.attr('data-thumb-padding')) / 2;
1571    var border_px = parseInt(container.attr('data-thumb-border'));
1572    var border_and_padding = border_px + padding_px;
1573    bwg_mosaic_title_on_hover(container.data('bwg'), container, border_and_padding);
1574  }
1575  if (container.attr('data-ecommerce-icon') == 'hover') {
1576    jQuery(".bwg_mosaic_thumb_spun_" + bwg).on("mouseenter", function() {
1577      var img_w = jQuery(this).parents(".bwg-mosaic-thumb-span").children(".bwg_mosaic_thumb_" + bwg).width();
1578      var img_h = jQuery(this).parents(".bwg-mosaic-thumb-span").children(".bwg_mosaic_thumb_" + bwg).height();
1579      jQuery(this).children(".bwg_ecommerce_spun1_" + bwg).width(img_w);
1580      var title_w = jQuery(this).children(".bwg_ecommerce_spun1_" + bwg).width();
1581      var title_h = jQuery(this).children(".bwg_ecommerce_spun1_" + bwg).height();
1582      jQuery(this).children(".bwg_ecommerce_spun1_" + bwg).css({
1583        top: border_and_padding + 0.5 * img_h - 0.5 * title_h,
1584        left: border_and_padding +  0.5 * img_w - 0.5 * title_w,
1585        'opacity': 1
1586      });
1587    });
1588    jQuery(".bwg_mosaic_thumb_spun_" + bwg).on("mouseleave", function() {
1589      jQuery(this).children(".bwg_ecommerce_spun1_" + bwg).css({ top: 0, left: -10000,'opacity': 0,'padding': container.attr('data-title-margin')});
1590    });
1591  }
1592}
1593
1594function bwg_mosaic_title_on_hover(bwg, container, border_and_padding) {
1595  jQuery(".bwg-mosaic-thumb-span").on("mouseenter", function() {
1596    var img_w = jQuery(this).children(".bwg_mosaic_thumb_" + bwg).width();
1597    jQuery(this).find(".bwg_mosaic_title_spun1_" + bwg).width(img_w);
1598    jQuery(this).find(".bwg_mosaic_title_spun1_" + bwg).css({
1599      'opacity': 1,
1600      'max-height' : 'calc(100% - ' + 2 * border_and_padding + 'px)',
1601      'overflow' : 'hidden'
1602    });
1603  });
1604  jQuery(".bwg-mosaic-thumb-span").on("mouseleave", function() {
1605    jQuery(this).find(".bwg_mosaic_title_spun1_" + bwg).css({
1606      'opacity' : 0,
1607      'padding' : container.attr('data-title-margin'),
1608      'max-height' : 'calc(100% - ' + 2 * border_and_padding + 'px)',
1609      'overflow' : 'hidden'
1610    });
1611  });
1612}
1613
1614function bwg_mosaic_ajax(bwg, tot_cccount_mosaic_ajax) {
1615  var cccount_mosaic_ajax = 0;
1616  jQuery(".bwg_mosaic_thumb_spun_" + bwg + " img").on("load", function() {
1617    if (++cccount_mosaic_ajax >= tot_cccount_mosaic_ajax) {
1618      bwg_thumbnail_mosaic(jQuery('.bwg-mosaic-thumbnails[data-bwg=' + bwg + ']'));
1619    }
1620  });
1621  jQuery(".bwg_mosaic_thumb_spun_" + bwg + " img").on("error", function() {
1622    jQuery(this).height(100);
1623    jQuery(this).width(100);
1624    if (++cccount_mosaic_ajax >= tot_cccount_mosaic_ajax) {
1625      bwg_thumbnail_mosaic(jQuery('.bwg-mosaic-thumbnails[data-bwg=' + bwg + ']'));
1626    }
1627  });
1628  /* If there is error (empty gallery, "No Images found."). Show Load Icon before load gallery. */
1629  jQuery(".bwg_container").each(function () {
1630    var bwg = jQuery(this).data('bwg');
1631    if ( jQuery(this).find(".wd_error").length > 0 ) {
1632      bwg_container_loaded(bwg);
1633    }
1634  });
1635}
1636
1637function bwg_add_album() {
1638  var bwg_touch_flag = false;
1639  if ( bwg_objectsL10n.front_ajax != "1" ) {
1640    jQuery(document).off("click",".bwg-album").on("click", ".bwg-album", function () {
1641      if (!bwg_touch_flag) {
1642        var bwg = jQuery(this).attr("data-bwg");
1643        bwg_touch_flag = true;
1644        setTimeout(function () {
1645          bwg_touch_flag = false;
1646        }, 100);
1647        bwg_ajax('gal_front_form_' + bwg, bwg, jQuery(this).attr("data-container_id"), jQuery(this).attr("data-alb_gal_id"), jQuery(this).attr("data-album_gallery_id"), jQuery(this).attr("data-def_type"), '', jQuery(this).attr("data-title"));
1648        return false;
1649      }
1650    });
1651  }
1652  /* Add description more button event.*/
1653  jQuery( ".bwg_description_more" ).on("click", function () {
1654    if ( jQuery(this).hasClass("bwg_more") ) {
1655      jQuery(this).parent().find(".bwg_description_full").show();
1656      jQuery(this).addClass("bwg_hide").removeClass("bwg_more");
1657      jQuery(this).html(jQuery(this).data("hide-msg"));
1658    }
1659    else {
1660      jQuery(this).parent().find(".bwg_description_full").hide();
1661      jQuery(this).addClass("bwg_more").removeClass("bwg_hide");
1662      jQuery(this).html(jQuery(this).data("more-msg"));
1663    }
1664  });
1665}
1666
1667function bwg_add_lightbox() {
1668  var bwg_touch_flag = false;
1669  jQuery(document).on("click", ".bwg_lightbox .bwg-item0, .bwg_lightbox .bwg_slide, .bwg_lightbox .bwg-carousel-image, .bwg_lightbox .bwg-title1" ,function ( event ) {
1670    event.stopPropagation();
1671    event.preventDefault();
1672    var that = jQuery(this).closest('a');
1673    if ( !bwg_touch_flag ) {
1674      bwg_touch_flag = true;
1675      setTimeout( function () {
1676        bwg_touch_flag = false;
1677      }, 100 );
1678      bwg_gallery_box( jQuery( that ).attr( "data-image-id" ), jQuery( that ).closest( '.bwg_container' ) );
1679      return false;
1680    }
1681  });
1682
1683  jQuery( ".bwg_lightbox .bwg_ecommerce" ).on("click", function ( event ) {
1684    event.stopPropagation();
1685    if ( !bwg_touch_flag ) {
1686      bwg_touch_flag = true;
1687      setTimeout( function () {
1688        bwg_touch_flag = false;
1689      }, 100 );
1690      var image_id = jQuery( this ).closest( ".bwg_lightbox" ).attr( "data-image-id" );
1691      bwg_gallery_box( image_id, jQuery( this ).closest( '.bwg_container' ), true );
1692      return false;
1693    }
1694  });
1695}
1696
1697function bwg_filter_by_tag(that) {
1698  var newTags = '';
1699  var curCont = '';
1700  if( jQuery(that).parent().parent().hasClass("bwg_tag_buttons_view") ){
1701    curCont = jQuery(that).parent().parent();
1702  }
1703  else {
1704    curCont = jQuery(that).parent().parent().parent();
1705  }
1706  var current_view = curCont.find('.current_view').val();
1707  var form_id = curCont.find('.form_id').val();
1708  var cur_gal_id = curCont.find('.cur_gal_id').val();
1709  var album_gallery_id = curCont.find('.album_gallery_id').val();
1710  var type = curCont.find('.type').val();
1711
1712  jQuery(that).parent().find('.opt.selected').each( function () {
1713    newTags = newTags + jQuery(that).text() + ',';
1714  });
1715  newTags = newTags.slice(0, -1);
1716  if ( newTags == '' ) {
1717    newTags = bwg_objectsL10n.bwg_select_tag;
1718  }
1719
1720  jQuery(that).parent().find('.CaptionCont').attr('title', newTags);
1721  jQuery(that).parent().find('.CaptionCont .placeholder').html(newTags);
1722
1723  var bwg_tags_array_data;
1724  var hiddenInputForTagsID = jQuery('.bwg_tags_container_' + current_view + ' #bwg_tag_id_' + cur_gal_id).val();
1725  if ( typeof hiddenInputForTagsID == "string" && hiddenInputForTagsID !== "" ) {
1726    bwg_tags_array_data = hiddenInputForTagsID.split(',');
1727  } else {
1728    bwg_tags_array_data = [];
1729  }
1730  if ( typeof hiddenInputForTagsID == "object" ){
1731    bwg_tags_array_data = hiddenInputForTagsID;
1732  }
1733  jQuery('.bwg_tags_container_' + current_view + ' #bwg_tag_id_' + current_view).val(bwg_tags_array_data);
1734  bwg_select_tag(current_view, form_id, cur_gal_id, album_gallery_id, type, false);
1735}
1736
1737/**
1738 * @param {object} container gallery main container.
1739 */
1740function bwg_document_ready(container) {
1741  bwg_add_lightbox();
1742  if ( container.data( 'right-click-protection' ) ) {
1743    bwg_disable_right_click( container );
1744  }
1745  var search_tags = container.find('.search_tags');
1746  if ( bwg_objectsL10n.front_ajax == "1" ) {
1747    if ( search_tags.length ) {
1748      for (var i = 0; i < search_tags[0].length; i++) {
1749        if ( typeof search_tags[0][i].attributes.selected === "undefined" ) {
1750          search_tags[0][i].selected = false;
1751        }
1752      }
1753    }
1754  }
1755  if ( search_tags.length ) {
1756    search_tags.SumoSelect({
1757      triggerChangeCombined: true,
1758      placeholder: bwg_objectsL10n.bwg_select_tag,
1759      search: true,
1760      searchText : bwg_objectsL10n.bwg_search,
1761      forceCustomRendering: true,
1762      noMatch: bwg_objectsL10n.bwg_tag_no_match,
1763      captionFormatAllSelected : bwg_objectsL10n.bwg_all_tags_selected,
1764      captionFormat: '{0} '+ bwg_objectsL10n.bwg_tags_selected,
1765      okCancelInMulti: true,
1766      locale: [bwg_objectsL10n.ok, bwg_objectsL10n.cancel, bwg_objectsL10n.select_all]
1767    } );
1768    search_tags.off("change").on("change", function () {
1769      bwg_filter_by_tag(this);
1770    });
1771  }
1772  bwg_search_tag_init(container);
1773  /* Tag filter - Buttons View */
1774  var cur_gal_id = container.find('.cur_gal_id').val();
1775  var current_view = container.find('.current_view').val();
1776  var tags_button_filter = container.find('.bwg_tags_container_' + current_view + ' .bwg_tag_button_view_container');
1777  var hiddenInputForTagsID = container.find('#bwg_tag_id_' + cur_gal_id);
1778  var visible_buttons_maxheight = parseInt( tags_button_filter.find('.bwg_tags_filter_buttons').outerHeight(true) * 2 );
1779
1780  if ( tags_button_filter.length ) {
1781    tags_button_filter.find('.bwg_tags_filter_buttons').off('click').on('click', function () {
1782      if ( !jQuery(this).hasClass('active') ) {
1783        /* Show all tags section, if selected tags position is under than 2-rd line */
1784        var getButtonPosition = jQuery(this).position().top;
1785        if ( getButtonPosition > visible_buttons_maxheight ) {
1786          container.find('.show_bottom_tag').val('1');
1787        }
1788
1789        if ( hiddenInputForTagsID.val() == "" ) {
1790          hiddenInputForTagsID.val(jQuery(this).val());
1791        }
1792        else {
1793          hiddenInputForTagsID.val(hiddenInputForTagsID.val() + ',' + jQuery(this).val());
1794        }
1795        bwg_filter_by_tag(this);
1796      }
1797      return false;
1798    });
1799
1800    tags_button_filter.find('.bwg_all_tags').off('click').on('click', function () {
1801      if ( !jQuery(this).hasClass('active') ) {
1802        hiddenInputForTagsID.val('');
1803        bwg_filter_by_tag(this);
1804      }
1805      return false;
1806    });
1807
1808    if ( hiddenInputForTagsID.val() != "" ){
1809      tags_button_filter.find('.bwg_all_tags').removeClass('active');
1810    }
1811
1812    /* Show all tags section, if selected tags position is under than 2-rd line */
1813    var get_filter_ids = hiddenInputForTagsID.val().split(',');
1814    get_filter_ids.forEach( function ( item ) {
1815      tags_button_filter.find('.bwg_tags_filter_buttons').each( function () {
1816        if ( jQuery(this).val() == item ) {
1817          var getButtonPosition = jQuery(this).position().top;
1818          if ( getButtonPosition > visible_buttons_maxheight ) {
1819            container.find('.show_bottom_tag').val('1');
1820          }
1821        }
1822      });
1823    })
1824
1825    /* Tag Filter - Buttons View FrontEnd Design */
1826    bwg_tags_button_section_visibility();
1827  }
1828  /* Ordering filter - Select View */
1829  var bwg_order = container.find('.bwg_order');
1830  if (bwg_order.length) {
1831    bwg_order.SumoSelect({
1832      triggerChangeCombined: true,
1833      forceCustomRendering: true,
1834    });
1835  }
1836  /* Add bwg-icon to select container. */
1837  jQuery(".SumoSelect > .CaptionCont > label > i").addClass("bwg-icon-angle-down closed");
1838  /* Show/Hide search_placeholder_title class container */
1839  jQuery(this).find('search_placeholder_title').hide();
1840  if (jQuery(this).find('.bwg_search_input').val() == '') {
1841    jQuery(this).find('search_placeholder_title').show();
1842  }
1843
1844  /* Show search_placeholder_title class container on focusout and hide reset, search icons*/
1845  jQuery(".bwg_thumbnail .bwg_search_container_2").focusout(function (e) {
1846    if (jQuery(this).find('.bwg_search_input').val() == '') {
1847      jQuery(this).find('.search_placeholder_title').show();
1848      jQuery(this).find('.bwg_search_loupe_container1').addClass('bwg-hidden');
1849      jQuery(this).find('.bwg_search_reset_container').addClass('bwg-hidden');
1850    }
1851  });
1852
1853  /* Show No tags text if tags empty. */
1854  jQuery('.search_tags').on('sumo:opened', function () {
1855    var cont_height = jQuery(this).parents('.bwg_container').height();
1856    var wd_error = jQuery(this).parents('.bwg_container').find('.wd_error').length;
1857    var select = jQuery(this).parent('.SumoSelect').find('.optWrapper>.options');
1858    if( typeof select !== 'undefined' ) {
1859      var sumoHeight = select.height();
1860      if ( sumoHeight > (cont_height - 50) ) {
1861        select.css('max-height', (cont_height - 50));
1862      }
1863    } 
1864    if ( jQuery(this).parent().find('ul li').length == 0 ) {
1865      jQuery('.no-match').html(bwg_objectsL10n.bwg_tag_no_match);
1866      jQuery('.no-match').show();
1867    }
1868  });
1869
1870  /* Change dashicon from up arrow to down arrow when select box is close. */
1871  jQuery('.bwg_thumbnail .SumoSelect').on('sumo:closed', function(){
1872    jQuery(this).find('label i').removeClass('bwg-icon-angle-up opened');
1873    jQuery(this).find('label i').addClass('bwg-icon-angle-down closed');
1874  });
1875
1876  /* Change dashicon from down arrow to up arrow when select box is open. */
1877  jQuery('.bwg_thumbnail .SumoSelect').on('sumo:opened', function() {
1878    jQuery(this).find('label i').removeClass('bwg-icon-angle-down closed');
1879    jQuery(this).find('label i').addClass('bwg-icon-angle-up opened');
1880  });
1881
1882  bwg_add_album();
1883
1884  var bwg_hash = window.location.hash.substring( 1 );
1885  if ( bwg_hash ) {
1886    if ( bwg_hash.indexOf( "bwg" ) != "-1" ) {
1887      bwg_hash_array = bwg_hash.replace( "bwg", "" ).split( "/" );
1888      var bwg_container = jQuery( '.bwg_container' );
1889
1890      if ( bwg_container ) {
1891        bwg_gallery_box( bwg_hash_array[1], bwg_container, false, bwg_hash_array[0] );
1892      }
1893    }
1894  }
1895  bwg_resize_search_line();
1896}
1897
1898/**
1899 * Search tag init.
1900 *
1901 * @param container
1902 */
1903function bwg_search_tag_init(container) {
1904  /* Tag filter - Select View */
1905  var search_tags = container.find('.search_tags');
1906  if ( bwg_objectsL10n.front_ajax == "1" ) {
1907    if ( search_tags.length ) {
1908      for (var i = 0; i < search_tags[0].length; i++) {
1909        if ( typeof search_tags[0][i].attributes.selected === "undefined" ) {
1910          search_tags[0][i].selected = false;
1911        }
1912      }
1913    }
1914  }
1915  if ( search_tags.length ) {
1916    search_tags.SumoSelect({
1917      triggerChangeCombined: true,
1918      placeholder: bwg_objectsL10n.bwg_select_tag,
1919      search: true,
1920      searchText : bwg_objectsL10n.bwg_search,
1921      forceCustomRendering: true,
1922      noMatch: bwg_objectsL10n.bwg_tag_no_match,
1923      captionFormatAllSelected : bwg_objectsL10n.bwg_all_tags_selected,
1924      captionFormat: '{0} '+ bwg_objectsL10n.bwg_tags_selected,
1925      okCancelInMulti: true,
1926      locale: [bwg_objectsL10n.ok, bwg_objectsL10n.cancel, bwg_objectsL10n.select_all]
1927    } );
1928    search_tags.off("change").on("change", function () {
1929      bwg_filter_by_tag(this);
1930    });
1931  }
1932}
1933
1934function bwg_clear_search_input (current_view) {
1935  if ( bwg_objectsL10n.front_ajax == "1" ) {
1936    var current_url = window.location.href;
1937    var redirect_url = bwg_remove_url_parameter("bwg_search_"+current_view,current_url, current_url);
1938    window.location.replace(redirect_url);
1939    return;
1940  }
1941  jQuery("#bwg_search_input_" + current_view).val('');
1942  jQuery("#bwg_search_container_1_" + current_view + " .bwg_search_loupe_container1").addClass("bwg-hidden");
1943  jQuery("#bwg_search_container_1_" + current_view + " .bwg_search_reset_container").addClass("bwg-hidden");
1944}
1945
1946function bwg_check_search_input_enter(that, e) {
1947  if (  e.key == 'Enter' ) {
1948    jQuery(that).closest('.bwg_search_container_1').find('.bwg_search').trigger('click');
1949    return false;
1950  }
1951  return true;
1952}
1953
1954/* Ajax call for filters and pagination.*/
1955function bwg_ajax(form_id, current_view, id, album_gallery_id, cur_album_id, type, srch_btn, title, sortByParam, load_more, description, scroll_to_top) {
1956  if ( bwg_objectsL10n.front_ajax == "1"  && load_more!==true ) {
1957    if (album_gallery_id === "back") {
1958      if (document.referrer.indexOf(window.location.host) == -1) {
1959        str = jQuery(location).attr('href');
1960        window.location.replace(str.substring(0,str.indexOf("type_0")));
1961        return;
1962      }
1963      else {
1964        window.history.back();
1965        return;
1966      }
1967    }
1968    var search_input_val = jQuery("#bwg_search_input_" + current_view).val();
1969    var cur_gal_id = jQuery('.bwg_tags_container_' + current_view + ' .cur_gal_id').val();
1970    var current_url = window.location.href;
1971    var redirect_url = "";
1972    var filter_tag = jQuery('.bwg_tags_container_' + current_view + ' #bwg_tag_id_' + cur_gal_id).val();
1973
1974    if ( current_url.substr(-1) == '#' ) {
1975      current_url = current_url.slice(0, -1);
1976    }
1977    if ( search_input_val !== "" &&  typeof search_input_val !== "undefined" ) {
1978      redirect_url = bwg_remove_url_parameter("page_number_" + current_view, current_url);
1979      redirect_url = bwg_add_url_parameter(redirect_url, "bwg_search_" + current_view, search_input_val);
1980      if ( redirect_url !== false ) {
1981        current_url = redirect_url;
1982      }
1983    }
1984    else {
1985      /* Delete search. */
1986      redirect_url = bwg_remove_url_parameter("bwg_search_" + current_view, current_url);
1987      if ( redirect_url !== false ) {
1988        current_url = redirect_url;
1989      }
1990    }
1991    if ( typeof sortByParam !== "undefined" && sortByParam !== "" ) {
1992      redirect_url = bwg_add_url_parameter(current_url, "sort_by_" + current_view, sortByParam);
1993      if ( redirect_url !== false ) {
1994        current_url = redirect_url;
1995      }
1996    }
1997    if ( typeof filter_tag !== "undefined" && filter_tag !== null && filter_tag.length > 0 ) {
1998      var tag_ides = "";
1999      /* Tag filter - Select View*/
2000      if ( jQuery('.bwg_tags_container_' + current_view).parent().hasClass("bwg_tag_select_view") ) {
2001        filter_tag = filter_tag.toString();
2002      }
2003      var filter_tags = filter_tag.split(',');
2004      jQuery.each(filter_tags, function (key) {
2005        var flag = ",";
2006        if (key === filter_tags.length - 1) {
2007          flag = "";
2008        }
2009        tag_ides += filter_tags[key] + flag;
2010      });
2011      if ( tag_ides !== "" ) {
2012        redirect_url = bwg_add_url_parameter(current_url, "filter_tag_" + current_view, tag_ides
2012);
2013        if (redirect_url !== false) {
2014          current_url = redirect_url;
2015        }
2016      }
2017    }
2018    else {
2019      redirect_url = bwg_remove_url_parameter("filter_tag_" + current_view, redirect_url);
2020      if ( redirect_url !== false ) {
2021        current_url = redirect_url;
2022      }
2023    }
2024    if ( srch_btn ) {
2025      redirect_url = bwg_remove_url_parameter("page_number_" + current_view, redirect_url);
2026      if ( redirect_url !== false ) {
2027        current_url = redirect_url;
2028      }
2029    }
2030    window.location.href = current_url;
2031    return;
2032  }
2033
2034  /* The loading container should be small on clicking load more button,
2035   but should cover whole container on entering gallery group.*/
2036  if ( load_more ) {
2037    jQuery(".bwg_loading_div_1").addClass("bwg_load_more_ajax_loading").removeClass("bwg_loading_div_1");
2038    jQuery(".bwg_load_more_ajax_loading").css({top: jQuery('#bwg_container1_' + bwg).height() - jQuery(".bwg_load_more_ajax_loading").height() });
2039  }
2040  else {
2041    jQuery(".bwg_load_more_ajax_loading").addClass("bwg_loading_div_1").removeClass("bwg_load_more_ajax_loading").removeAttr("style");
2042  }
2043  /* Show loading.*/
2044  jQuery("#ajax_loading_" + current_view).removeClass('bwg-hidden');
2045
2046  /* Disable scroll to prevent bugs with load more.*/
2047  if (typeof bwg_scroll_load_action === "function") {
2048    jQuery(window).off("scroll", bwg_scroll_load_action);
2049  }
2050
2051  /* To prevent bugs with filters.*/
2052  jQuery(".bwg_thumbnail .search_tags").off("sumo:closed");
2053
2054  var ajax_url = jQuery('#' + form_id).data("ajax-url");
2055
2056  var masonry_loaded = 0;
2057  var mosaic_loaded = 0;
2058  if (typeof load_more == "undefined") {
2059    var load_more = false;
2060  }
2061  var page_number = jQuery("#page_number_" + current_view).val();
2062  var search = jQuery("#bwg_search_input_" + current_view).val();
2063  var post_data = {};
2064
2065  var breadcrumb_str = jQuery('#bwg_album_breadcrumb_' + current_view).val();
2066  if ( breadcrumb_str && load_more !== true ) { /* For album views.*/
2067    var breadcrumb = JSON.parse(breadcrumb_str);
2068    if ( album_gallery_id == 'back' ) {
2069      /* Remove last element of array.*/
2070      breadcrumb.splice(-1, 1);
2071      var last_el = breadcrumb.slice(-1)[0];
2072      album_gallery_id = last_el["id"];
2073      page_number = last_el["page"];
2074      post_data["action_" + current_view] = 'back';
2075    }
2076    else if ( load_more === 'numeric' || srch_btn ) {/* From numeric pagination.*/
2077      breadcrumb.splice(-1, 1);
2078      breadcrumb.push({ id: album_gallery_id, page: page_number, search: search });
2079    }
2080    else {
2081      breadcrumb.push({id: album_gallery_id, page: 1});
2082      page_number = 1;
2083    }
2084    post_data["bwg_album_breadcrumb_" + current_view] = JSON.stringify(breadcrumb);
2085  }
2086  post_data['bwg-preview-type'] = jQuery('#' + form_id).data("gallery-type");
2087  /** Set values for elementor widget.*/
2088  post_data['gallery_type'] = jQuery('#' + form_id).data("gallery-type");
2089  post_data['gallery_id'] = jQuery('#' + form_id).data("gallery-id");
2090  post_data['tag'] = jQuery('#' + form_id).data("tag");
2091  post_data['album_id'] = jQuery('#' + form_id).data("album-id");
2092  post_data['theme_id'] = jQuery('#' + form_id).data("theme-id");
2093
2094  post_data['shortcode_id'] = jQuery('#' + form_id).data("shortcode-id");
2095  post_data['bwg'] = current_view;
2096  post_data['current_url'] = encodeURI(jQuery('#bwg_container1_' + current_view).data("current-url"));
2097
2098  if ( srch_btn ) { /* Start search. */
2099    page_number = 1;
2100  }
2101  if (typeof title == "undefined" || title == '') {
2102    var title = "";
2103  }
2104  if (typeof description == "undefined" || description == '') {
2105    var description = "";
2106  }
2107  if (typeof sortByParam == "undefined" || sortByParam == '') {
2108    var sortByParam = jQuery(".bwg_order_" + current_view).val();
2109  }
2110  if (typeof scroll_to_top == "undefined") {
2111    var scroll_to_top = true;
2112  }
2113  if (scroll_to_top == true) {
2114    jQuery("html, body").animate({scrollTop: jQuery('#' + form_id).offset().top - 150}, 500);
2115  }
2116
2117  post_data["page_number_" + current_view] = page_number;
2118  post_data["bwg_load_more_" + current_view] = jQuery("#bwg_load_more_" + current_view).val();
2119  post_data["album_gallery_id_" + current_view] = album_gallery_id;
2120  post_data["type_" + current_view] = type;
2121  post_data["title_" + current_view] = title;
2122  post_data["description_" + current_view] = description;
2123  post_data["sortImagesByValue_" + current_view] = sortByParam;
2124  post_data["bwg_random_seed_" + current_view] = parseInt(jQuery("#bwg_random_seed_" + current_view).val());
2125
2126  if (jQuery("#bwg_search_input_" + current_view).length > 0) { /* Search box exists.*/
2127    post_data["bwg_search_" + current_view] = jQuery("#bwg_search_input_" + current_view).val();
2128  }
2129
2130  if ( typeof post_data["bwg_album_breadcrumb_" + current_view] != "undefined" ) {
2131    var breadcrumbObj = JSON.parse(post_data["bwg_album_breadcrumb_" + current_view]);
2132    jQuery.each(breadcrumbObj, function (index, value) {
2133      post_data["bwg_search_" + current_view] = '';
2134      if (album_gallery_id == value.id) {
2135        post_data["bwg_search_" + current_view] = value.search;
2136      }
2137    });
2138  }
2139
2140  var bwg_tags_array_data;
2141  var hiddenInputForTagsID = jQuery('.bwg_tags_container_' + current_view + ' #bwg_tag_id_' + id).val();
2142  if ( typeof hiddenInputForTagsID == "string" && hiddenInputForTagsID !== "" ) {
2143    bwg_tags_array_data = hiddenInputForTagsID.split(',');
2144  } else {
2145    bwg_tags_array_data = [];
2146  }
2147  if ( typeof hiddenInputForTagsID == "object" ) {
2148    bwg_tags_array_data = hiddenInputForTagsID;
2149  }
2150  post_data["bwg_tag_id_" + id] = bwg_tags_array_data;
2151
2152  /* The loading container should be small on clicking load more button,
2153   but should cover whole container on entering gallery group.*/
2154  if ( load_more ) {
2155    jQuery(".bwg_loading_div_1").addClass("bwg_load_more_ajax_loading").removeClass("bwg_loading_div_1");
2156    jQuery(".bwg_load_more_ajax_loading").css({top: jQuery('#bwg_container1_' + bwg).height() - jQuery(".bwg_load_more_ajax_loading").height()});
2157  }
2158  else {
2159    jQuery(".bwg_load_more_ajax_loading").addClass("bwg_loading_div_1").removeClass("bwg_load_more_ajax_loading").removeAttr("style");
2160  }
2161  /* Loading.*/
2162  jQuery("#ajax_loading_" + current_view).removeClass('bwg-hidden');
2163
2164  jQuery.ajax({
2165    type: 'POST',
2166    url: ajax_url,
2167    data: post_data,
2168    success: function (data) {
2169      masonry_loaded = jQuery(data).find(".bwg_masonry_thumb_spun_" + current_view + " img").length;
2170      mosaic_loaded = jQuery(data).find(".bwg_mosaic_thumb_spun_" + current_view + " img").length;
2171
2172      if ( load_more === true ) {
2173        /* Add next page images after current ones instead of change all container.*/
2174        if ( id == "bwg_thumbnails_mosaic_" + current_view ) {
2175          /* ToDo: Remove after changing mosaic view.*/
2176          jQuery('#' + id).append(jQuery(data).closest(".bwg-container-" + current_view).find("#" + id).html());
2177        }
2178        else if ( id == "bwg_album_compact_" + current_view ) {
2179          jQuery('#' + id).append(jQuery(data).closest(".bwg-album-thumbnails").html());
2180        }
2181        else if ( id == "bwg_thumbnails_masonry_" + current_view ) {
2182          jQuery('.bwg-container-temp' + current_view).append(jQuery(data).closest(".bwg-container-" + current_view).html());
2183        }
2184        else {
2185          jQuery('#' + id).append(jQuery(data).closest(".bwg-container-" + current_view).html());
2186        }
2187        /* Change load more button container withe new one.*/
2188        jQuery('.bwg_nav_cont_' + current_view).html(jQuery(data).closest('.bwg_nav_cont_' + current_view).html());
2189      }
2190      else {
2191        /* Change all container with new data.*/
2192        jQuery('#bwg_container3_' + current_view).html(data);
2193      }
2194      bwg_remove_lazy_loader_icon();
2195    },
2196    complete: function() {
2197      /* To prevent conflict with lazy load.*/
2198      jQuery("div[id^='bwg_container1_'] img").each(function () {
2199        if (jQuery(this).attr("data-lazy-src") != undefined && jQuery(this).attr("data-lazy-src") != '') {
2200          jQuery(this).attr("src", jQuery(this).attr("data-lazy-src"));
2201        }
2202        else if (jQuery(this).attr("data-src") != undefined && jQuery(this).attr("data-src") != '') {
2203          jQuery(this).attr("src", jQuery(this).attr("data-src"));
2204        }
2205      });
2206      jQuery(".blog_style_image_buttons_conteiner_" + current_view).find(jQuery(".bwg_blog_style_img_" + current_view)).on("load", function() {
2207        jQuery(".bwg_blog_style_img_" + current_view).closest(jQuery(".blog_style_image_buttons_conteiner_" + current_view)).show();
2208      });
2209      if ( bwg_tags_array_data == '' || bwg_tags_array_data === null ) {
2210        bwg_tags_array_data = [];
2211      }
2212
2213      jQuery('.bwg_tags_container_' + current_view + ' #bwg_tag_id_' + id).val(bwg_tags_array_data);
2214      bwg_tags_array_data.forEach( function ( item ) {
2215        jQuery('.bwg_tags_container_' + current_view + ' .bwg_tags_filter_buttons').each(function () {
2216          var visible_buttons_maxheight = parseInt( jQuery(this).outerHeight(true) * 2 );
2217          if ( jQuery(this).val() == item ) {
2218            jQuery(this).addClass("active");
2219              /* Show all tags section, if selected tags position is under than 2-rd line */
2220              var getButtonPosition = jQuery(this).position().top;
2221              if ( getButtonPosition > visible_buttons_maxheight ) {
2222                jQuery('.bwg_tags_container_' + current_view + ' .show_bottom_tag').val("1");
2223              }
2224            jQuery('.bwg_tags_container_' + current_view + ' .bwg_all_tags').removeClass( "active" );
2225          }
2226        });
2227      });
2228      if ( jQuery(".pagination-links_" + current_view).length ) {
2229        jQuery("html, body").animate({scrollTop: jQuery('#' + form_id).offset().top - 150}, 500);
2230      }
2231      /* For all views. */
2232      bwg_document_ready(jQuery("#bwg_container1_" + current_view));
2233      var gallery_view_type = jQuery("#bwg_container1_" + current_view).data('gallery-view-type');
2234      if ( !jQuery("#bwg_container1_" + current_view + " .bwg-album-thumbnails").length ) {
2235        switch ( gallery_view_type ) {
2236          case "thumbnails":
2237          case "thumbnail":
2238          case "masonry":
2239          case "mosaic":
2240          case "thumbnails_masonry":
2241          case "album_compact_preview":
2242          case "album_masonry_preview":
2243          case "album_extended_preview":
2244            bwg_all_thumnails_loaded(".bwg-container-" + current_view);
2245            break;
2246          case "slideshow":
2247            bwg_slideshow_ready(current_view);
2248            break;
2249          case "carousel":
2250            bwg_carousel_ready(current_view);
2251            bwg_carousel_onload(jQuery("#bwg_container1_" + current_view));
2252            break;
2253          case "image_browser":
2254            bwg_image_browser_ready(jQuery("#bwg_container1_" + current_view));
2255            break;
2256          case "blog_style":
2257            bwg_blog_style_ready(jQuery("#bwg_container1_" + current_view));
2258            break;
2259        }
2260        bwg_mosaic_ajax(current_view, mosaic_loaded);
2261      }
2262      else {
2263        var no_data = bwg_all_thumnails_loaded(".bwg-container-" + current_view);
2264        if ( no_data ) {
2265          /* If there where no data after after ajax request.*/
2266          bwg_container_loaded(current_view);
2267        }
2268      }
2269      /* For Blog style view.*/
2270      jQuery(".blog_style_images_conteiner_" + current_view + " .bwg_embed_frame_16x9_" + current_view).each(function (e) {
2271        jQuery(this).width(jQuery(this).parent().width());
2272        jQuery(this).height(jQuery(this).width() * 0.5625);
2273      });
2274      jQuery(".blog_style_images_conteiner_" + current_view + " .bwg_embed_frame_instapost_" + current_view).each(function (e) {
2275        jQuery(this).width(jQuery(this).parent().width());
2276        /* 16 is 2*padding inside iframe */
2277        /* 96 is 2*padding(top) + 1*padding(bottom) + 40(footer) + 32(header) */
2278        jQuery(this).height((jQuery(this).width() - 16) * jQuery(this).attr('data-height') / jQuery(this).attr('data-width') + 96);
2279      });
2280      /* For Image browser view.*/
2281      jQuery('#bwg_embed_frame_16x9_' + current_view).width(jQuery('#bwg_embed_frame_16x9_' + current_view).parent().width());
2282      jQuery('#bwg_embed_frame_16x9_' + current_view).height(jQuery('#bwg_embed_frame_16x9_' + current_view).width() * 0.5625);
2283      jQuery('#bwg_embed_frame_instapost_' + current_view).width(jQuery('#bwg_embed_frame_16x9_' + current_view).parent().width());
2284      /* 16 is 2*padding inside iframe */
2285      /* 96 is 2*padding(top) + 1*padding(bottom) + 40(footer) + 32(header) */
2286      jQuery('.bwg_embed_frame_instapost_' + current_view).height((jQuery('.bwg_embed_frame_instapost_' + current_view).width() - 16) * jQuery('.bwg_embed_frame_instapost_' + current_view).attr('data-height') / jQuery('.bwg_embed_frame_instapost_' + current_view).attr('data-width') + 96);
2287
2288      /* Return value to search input field. */
2289      jQuery("#bwg_search_input_" + current_view).val(post_data["bwg_search_" + current_view]);
2290
2291      if ( jQuery("#bwg_search_input_" + current_view).val() != '' ) {
2292        jQuery("#bwg_search_input_" + current_view).parent().find('.search_placeholder_title').hide();
2293        jQuery("#bwg_search_input_" + current_view).parent().parent().find('.bwg_search_reset_container').show();
2294        jQuery("#bwg_search_input_" + current_view).parent().parent().find('.bwg_search_loupe_container1').show();
2295      } else {
2296        jQuery("#bwg_search_input_" + current_view).parent().find('.search_placeholder_title').show();
2297      }
2298
2299      var cur_gal_id = jQuery("#bwg_container2_" + current_view + " .cur_gal_id").val();
2300      if ( bwg_tags_array_data == '' || bwg_tags_array_data === null ) {
2301        bwg_tags_array_data = [];
2302      }
2303      jQuery('.bwg_tags_container_' + current_view + ' #bwg_tag_id_' + current_view).val(bwg_tags_array_data);
2304    }
2305  });
2306
2307  return false;
2308}
2309
2310function bwg_add_url_parameter(uri, key, value) {
2311  var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
2312  var separator = uri.indexOf('?') !== -1 ? "&" : "?";
2313  if (uri.match(re)) {
2314    return uri.replace(re, '$1' + key + "=" + value + '$2');
2315  }
2316  else {
2317    return uri + separator + key + "=" + value;
2318  }
2319}
2320
2321function bwg_remove_url_parameter(sParam , link)
2322{
2323  var url_split = link.split('?');
2324  var url = url_split[0]+'?';
2325
2326  var window_loc_search = "";
2327  if(typeof url_split[1] !== "undefined"){
2328    window_loc_search = url_split[1];
2329  }
2330  if(window_loc_search === ""){
2331    return link;
2332  }
2333  var sPageURL = decodeURIComponent(window_loc_search),
2334    sURLVariables = sPageURL.split('&'),
2335    sParameterName,
2336    i;
2337
2338  for (i = 0; i < sURLVariables.length; i++) {
2339    sParameterName = sURLVariables[i].split('=');
2340    if (sParameterName[0] != sParam) {
2341      url = url + sParameterName[0] + '=' + sParameterName[1] + '&'
2342    }
2343  }
2344  return url.substring(0,url.length-1);
2345}
2346
2347function bwg_select_tag(current_view, form_id, cur_gal_id, album_gallery_id, type, reset) {
2348  if ( reset ) {
2349    jQuery('.bwg_tags_container_' + current_view + ' #bwg_tag_id_' + cur_gal_id).val('');
2350  }
2351  bwg_ajax(form_id, current_view, cur_gal_id, album_gallery_id, '', type, 1, '');
2352}
2353
2354function bwg_cube(tz, ntx, nty, nrx, nry, wrx, wry, current_image_class, next_image_class, direction, bwg) {
2355  var type_slideshow = false;
2356  var bwg_prefix = "";
2357  var bwg_transition_dur;
2358  if ( typeof bwg !== 'undefined' && bwg !== '' ) {
2359    type_slideshow = true;
2360    bwg_params[bwg]['bwg_trans_in_progress'] = true;
2361    bwg_prefix = "_"+bwg;
2362    bwg_transition_dur = bwg_params[bwg]['bwg_transition_duration'];
2363    var event_stack = bwg_params[bwg]['event_stack']
2364  } else {
2365    bwg_transition_dur = bwg_transition_duration;
2366  }
2367  /* If browser does not support 3d transforms/CSS transitions.*/
2368  if (!bwg_testBrowser_cssTransitions( bwg )) {
2369    return bwg_fallback(current_image_class, next_image_class, direction, bwg);
2370  }
2371  if (!bwg_testBrowser_cssTransforms3d( bwg )) {
2372    return bwg_fallback3d(current_image_class, next_image_class, direction, bwg);
2373  }
2374  if( !type_slideshow) { /* from lightbox */
2375    gallery_box_data['bwg_trans_in_progress'] = true;
2376    /* Set active thumbnail.*/
2377    jQuery(".bwg_filmstrip_thumbnail").removeClass("bwg_thumb_active").addClass("bwg_thumb_deactive");
2378    jQuery("#bwg_filmstrip_thumbnail_" + gallery_box_data['bwg_current_key']).removeClass("bwg_thumb_deactive").addClass("bwg_thumb_active");
2379    jQuery(".bwg_slide_bg").css('perspective', 1000);
2380  } else { /* from slideshow */
2381    /* Set active thumbnail.*/
2382    jQuery(".bwg_slideshow_filmstrip_thumbnail_"+bwg).removeClass("bwg_slideshow_thumb_active_"+bwg).addClass("bwg_slideshow_thumb_deactive_"+bwg);
2383    jQuery("#bwg_filmstrip_thumbnail_" + bwg_params[bwg]['bwg_current_key']+ "_"+bwg).removeClass("bwg_slideshow_thumb_deactive_"+bwg).addClass("bwg_slideshow_thumb_active_"+bwg);
2384    jQuery(".bwg_slideshow_dots_"+bwg).removeClass("bwg_slideshow_dots_active_"+bwg).addClass("bwg_slideshow_dots_deactive_"+bwg);
2385    jQuery("#bwg_dots_" + bwg_params[bwg]['bwg_current_key'] + "_" + bwg).removeClass("bwg_slideshow_dots_deactive_"+bwg).addClass("bwg_slideshow_dots_active_"+bwg);
2386    jQuery(".bwg_slide_bg_"+bwg).css('perspective', 1000);
2387  }
2388  jQuery(current_image_class).css({
2389    transform : 'translateZ(' + tz + 'px)',
2390    backfaceVisibility : 'hidden'
2391  });
2392  jQuery(next_image_class).css({
2393    opacity : 1,
2394    backfaceVisibility : 'hidden',
2395    transform : 'translateY(' + nty + 'px) translateX(' + ntx + 'px) rotateY('+ nry +'deg) rotateX('+ nrx +'deg)'
2396  });
2397  jQuery(".bwg_slider"+bwg_prefix).css({
2398    transform: 'translateZ(-' + tz + 'px)',
2399    transformStyle: 'preserve-3d'
2400  });
2401  /* Execution steps.*/
2402  setTimeout(function () {
2403    jQuery(".bwg_slider"+bwg_prefix).css({
2404      transition: 'all ' + bwg_transition_dur + 'ms ease-in-out',
2405      transform: 'translateZ(-' + tz + 'px) rotateX('+ wrx +'deg) rotateY('+ wry +'deg)'
2406    });
2407  }, 20);
2408  /* After transition.*/
2409  jQuery(".bwg_slider"+bwg_prefix).one('webkitTransitionEnd transitionend otransitionend oTransitionEnd mstransitionend', jQuery.proxy(bwg_after_trans));
2410  function bwg_after_trans() {
2411    jQuery(current_image_class).removeAttr('style');
2412    jQuery(next_image_class).removeAttr('style');
2413    jQuery(".bwg_slider"+bwg_prefix).removeAttr('style');
2414    jQuery(current_image_class).css({'opacity' : 0, 'z-index': 1});
2415    jQuery(next_image_class).css({'opacity' : 1, 'z-index' : 2});
2416    jQuery(".bwg_image_info").show();
2417
2418    jQuery(current_image_class).html('');
2419
2420    if ( type_slideshow ) {  /*check if cube works from slideshow*/
2421      bwg_change_watermark_container( bwg );
2422      bwg_params[bwg]['bwg_trans_in_progress'] = false;
2423      var data = bwg_params[bwg]['data'];
2424      var event_stack = bwg_params[bwg]['event_stack'];
2425    }
2426    else {
2427      var data = '';
2428      gallery_box_data['bwg_trans_in_progress'] = false;
2429      var event_stack = gallery_box_data['event_stack'];
2430    }
2431    if (typeof event_stack !== 'undefined') {
2432      if (event_stack.length > 0) {
2433        var key = event_stack[0].split("-");
2434        event_stack.shift();
2435        bwg_change_image(key[0], key[1], data, true, bwg);
2436      }
2437    }
2438    bwg_change_watermark_container();
2439  }
2440  if (bwg_transition_dur == 0) {
2441    bwg_after_trans();
2442  }
2443}
2444
2445function bwg_cubeH(current_image_class, next_image_class, direction, bwg) {
2446  /* Set to half of image width.*/
2447  var dimension = jQuery(current_image_class).width() / 2;
2448  if (direction == 'right') {
2449    bwg_cube(dimension, dimension, 0, 0, 90, 0, -90, current_image_class, next_image_class, direction, bwg);
2450  }
2451  else if (direction == 'left') {
2452    bwg_cube(dimension, -dimension, 0, 0, -90, 0, 90, current_image_class, next_image_class, direction, bwg);
2453  }
2454}
2455
2456function bwg_cubeV(current_image_class, next_image_class, direction, bwg) {
2457  /* Set to half of image height.*/
2458  var dimension = jQuery(current_image_class).height() / 2;
2459  /* If next slide.*/
2460  if (direction == 'right') {
2461    bwg_cube(dimension, 0, -dimension, 90, 0, -90, 0, current_image_class, next_image_class, direction, bwg);
2462  }
2463  else if (direction == 'left') {
2464    bwg_cube(dimension, 0, dimension, -90, 0, 90, 0, current_image_class, next_image_class, direction, bwg);
2465  }
2466}
2467
2468function bwg_fade(current_image_class, next_image_class, direction, bwg) {
2469  var type_slideshow = false;
2470  var bwg_transition_dur;
2471  if( typeof bwg !== 'undefined' && bwg !== '' ) {
2472    type_slideshow = true;
2473    bwg_params[bwg]['bwg_trans_in_progress'] = true;
2474    bwg_transition_dur = bwg_params[bwg]['bwg_transition_duration'];
2475  } else {
2476    gallery_box_data['bwg_trans_in_progress'] = true;
2477    bwg_transition_dur = gallery_box_data['bwg_transition_duration'];
2478  }
2479  if(type_slideshow) {
2480    /* Set active thumbnail.*/
2481    jQuery(".bwg_slideshow_filmstrip_thumbnail_"+bwg).removeClass("bwg_slideshow_thumb_active_"+bwg).addClass("bwg_slideshow_thumb_deactive_"+bwg);
2482    jQuery("#bwg_filmstrip_thumbnail_" + bwg_params[bwg]['bwg_current_key'] + "_"+bwg).removeClass("bwg_slideshow_thumb_deactive_"+bwg).addClass("bwg_slideshow_thumb_active_"+bwg);
2483    jQuery(".bwg_slideshow_dots_"+bwg).removeClass("bwg_slideshow_dots_active_"+bwg).addClass("bwg_slideshow_dots_deactive_"+bwg);
2484    jQuery("#bwg_dots_" + bwg_params[bwg]['bwg_current_key'] + "_"+bwg).removeClass("bwg_slideshow_dots_deactive_"+bwg).addClass("bwg_slideshow_dots_active_"+bwg);
2485  } else {
2486    /* Set active thumbnail.*/
2487    jQuery(".bwg_filmstrip_thumbnail").removeClass("bwg_thumb_active").addClass("bwg_thumb_deactive");
2488    jQuery("#bwg_filmstrip_thumbnail_" + gallery_box_data['bwg_current_key']).removeClass("bwg_thumb_deactive").addClass("bwg_thumb_active");
2489  }
2490  function bwg_after_trans() {
2491    jQuery(".bwg_image_info").show();
2492    bwg_change_watermark_container( bwg );
2493    if ( type_slideshow ) {
2494      bwg_params[bwg]['bwg_trans_in_progress'] = false;
2495    }
2496    else {
2497      gallery_box_data['bwg_trans_in_progress'] = false;
2498    }
2499  }
2500  if (bwg_testBrowser_cssTransitions()) {
2501    jQuery(next_image_class).css('transition', 'opacity ' + bwg_transition_dur + 'ms linear');
2502    jQuery(current_image_class).css('transition', 'opacity ' + bwg_transition_dur + 'ms linear');
2503    jQuery(current_image_class).css({'opacity' : 0, 'z-index': 1});
2504    jQuery(next_image_class).css({'opacity' : 1, 'z-index' : 2});
2505    jQuery(next_image_class).one('webkitTransitionEnd transitionend otransitionend oTransitionEnd mstransitionend', jQuery.proxy(bwg_after_trans));
2506  }
2507  else {
2508    jQuery(current_image_class).animate({'opacity' : 0, 'z-index' : 1}, bwg_transition_dur);
2509    jQuery(next_image_class).animate({
2510      'opacity' : 1,
2511      'z-index': 2
2512    }, {
2513      duration: bwg_transition_dur,
2514      complete: function () {
2515        if( type_slideshow ) {
2516          bwg_params[bwg]['bwg_trans_in_progress'] = false;
2517        } else {
2518          gallery_box_data['bwg_trans_in_progress'] = false;
2519        }
2520        jQuery(current_image_class).html('');
2521        bwg_after_trans();
2522      }
2523    });
2524    /* For IE.*/
2525    jQuery(current_image_class).fadeTo(bwg_transition_dur, 0);
2526    jQuery(next_image_class).fadeTo(bwg_transition_dur, 1);
2527  }
2528  if (bwg_transition_dur == 0) {
2529    bwg_after_trans();
2530  }
2531}
2532
2533function bwg_grid(cols, rows, ro, tx, ty, sc, op, current_image_class, next_image_class, direction, bwg) {
2534  var type_slideshow = false;
2535  var bwg_prefix = "";
2536  var bwg_transition_dur;
2537  if ( typeof bwg !== 'undefined' && bwg !== '' ) {
2538    type_slideshow = true;
2539    bwg_params[bwg]['bwg_trans_in_progress'] = true;
2540    bwg_prefix = "_"+bwg;
2541    bwg_transition_dur = bwg_params[bwg]['bwg_transition_duration'];
2542    event_stack = bwg_params[bwg]['event_stack'];
2543  }
2544  else {
2545    bwg_transition_dur = bwg_transition_duration;
2546    gallery_box_data['bwg_trans_in_progress'] = true;
2547    event_stack = gallery_box_data['event_stack'];
2548  }
2549  /* If browser does not support CSS transitions.*/
2550  if (!bwg_testBrowser_cssTransitions()) {
2551    return bwg_fallback(current_image_class, next_image_class, direction);
2552  }
2553
2554  if (type_slideshow) {
2555    /* Set active thumbnail.*/
2556    jQuery(".bwg_slideshow_filmstrip_thumbnail_"+bwg).removeClass("bwg_slideshow_thumb_active_"+bwg).addClass("bwg_slideshow_thumb_deactive_"+bwg);
2557    jQuery("#bwg_filmstrip_thumbnail_" + bwg_params[bwg]['bwg_current_key'] + bwg_prefix).removeClass("bwg_slideshow_thumb_deactive_"+bwg).addClass("bwg_slideshow_thumb_active_"+bwg);
2558    jQuery(".bwg_slideshow_dots_"+bwg).removeClass("bwg_slideshow_dots_active_"+bwg).addClass("bwg_slideshow_dots_deactive_"+bwg);
2559    jQuery("#bwg_dots_" + bwg_params[bwg]['bwg_current_key'] + bwg_prefix).removeClass("bwg_slideshow_dots_deactive_"+bwg).addClass("bwg_slideshow_dots_active_"+bwg);
2560  } else {
2561    /* Set active thumbnail.*/
2562    jQuery(".bwg_filmstrip_thumbnail").removeClass("bwg_thumb_active").addClass("bwg_thumb_deactive");
2563    jQuery("#bwg_filmstrip_thumbnail_" + gallery_box_data['bwg_current_key']).removeClass("bwg_thumb_deactive").addClass("bwg_thumb_active");
2564  }
2565  /* The time (in ms) added to/subtracted from the delay total for each new gridlet.*/
2566  var count = (bwg_transition_dur) / (cols + rows);
2567  /* Gridlet creator (divisions of the image grid, positioned with background-images to replicate the look of an entire slide image when assembled)*/
2568  function bwg_gridlet(width, height, top, img_top, left, img_left, src, imgWidth, imgHeight, c, r, bwg) {
2569    var delay = (c + r) * count;
2570    /* Return a gridlet elem with styles for specific transition.*/
2571    return jQuery('<span class="bwg_gridlet'+bwg_prefix+'" />').css({
2572      display : "block",
2573      width : width,
2574      height : height,
2575      top : top,
2576      left : left,
2577      backgroundImage : 'url("' + src + '")',
2578      backgroundColor: (type_slideshow) ? jQuery(".bwg_slideshow_image_wrap_"+bwg).css("background-color") : jQuery(".spider_popup_wrap").css("background-color"),
2579      /*backgroundColor: 'rgba(0, 0, 0, 0)',*/
2580      backgroundRepeat: 'no-repeat',
2581      backgroundPosition : img_left + 'px ' + img_top + 'px',
2582      backgroundSize : imgWidth + 'px ' + imgHeight + 'px',
2583      transition : 'all ' + bwg_transition_dur + 'ms ease-in-out ' + delay + 'ms',
2584      transform : 'none'
2585    });
2586  }
2587  /* Get the current slide's image.*/
2588  var cur_img = jQuery(current_image_class).find('img');
2589  var cur_figure = jQuery(current_image_class).find('figure');
2590  var cur_ifrem = jQuery(current_image_class).find('iframe').css('opacity', 0);
2591  /* Create a grid to hold the gridlets.*/
2592  var grid = jQuery('<span style="display: block;" />').addClass('bwg_grid' + bwg_prefix);
2593
2594  /* Prepend the grid to the next slide (i.e. so it's above the slide image).*/
2595  jQuery(current_image_class).prepend(grid);
2596  /* Vars to calculate positioning/size of gridlets.*/
2597  var cont = jQuery(".bwg_slide_bg" + bwg_prefix);
2598  var imgWidth = cur_img.width();
2599  var imgHeight = cur_img.height();
2600  var contWidth = cont.width(),
2601    contHeight = cont.height(),
2602    colWidth = Math.floor(contWidth / cols),
2603    rowHeight = Math.floor(contHeight / rows),
2604    colRemainder = contWidth - (cols * colWidth),
2605    colAdd = Math.ceil(colRemainder / cols),
2606    rowRemainder = contHeight - (rows * rowHeight),
2607    rowAdd = Math.ceil(rowRemainder / rows),
2608    leftDist = 0,
2609    img_leftDist = Math.ceil((jQuery(".bwg_slide_bg"+bwg_prefix).width() - cur_img.width()) / 2);
2610  var imgSrc = typeof cur_img.attr('src')=='undefined' ? '' :cur_img.attr('src');
2611  /* tx/ty args can be passed as 'auto'/'min-auto' (meaning use slide width/height or negative slide width/height).*/
2612  tx = tx === 'auto' ? contWidth : tx;
2613  tx = tx === 'min-auto' ? - contWidth : tx;
2614  ty = ty === 'auto' ? contHeight : ty;
2615  ty = ty === 'min-auto' ? - contHeight : ty;
2616  /* Loop through cols.*/
2617  for (var i = 0; i < cols; i++) {
2618    var topDist = 0,
2619      img_topDst = Math.floor((jQuery(".bwg_slide_bg"+bwg_prefix).height() - cur_img.height()) / 2),
2620      newColWidth = colWidth;
2621    /* If imgWidth (px) does not divide cleanly into the specified number of cols, adjust individual col widths to create correct total.*/
2622    if (colRemainder > 0) {
2623      var add = colRemainder >= colAdd ? colAdd : colRemainder;
2624      newColWidth += add;
2625      colRemainder -= add;
2626    }
2627    /* Nested loop to create row gridlets for each col.*/
2628    for (var j = 0; j < rows; j++)  {
2629      var newRowHeight = rowHeight,
2630        newRowRemainder = rowRemainder;
2631      /* If contHeight (px) does not divide cleanly into the specified number of rows, adju
2631st individual row heights to create correct total.*/
2632      if (newRowRemainder > 0) {
2633        add = newRowRemainder >= rowAdd ? rowAdd : rowRemainder;
2634        newRowHeight += add;
2635        newRowRemainder -= add;
2636      }
2637      /* Create & append gridlet to grid.*/
2638      grid.append(bwg_gridlet(newColWidth, newRowHeight, topDist, img_topDst, leftDist, img_leftDist, imgSrc, imgWidth, imgHeight, i, j, bwg));
2639      topDist += newRowHeight;
2640      img_topDst -= newRowHeight;
2641    }
2642    img_leftDist -= newColWidth;
2643    leftDist += newColWidth;
2644  }
2645  /* Set event listener on last gridlet to finish transitioning.*/
2646  var last_gridlet = grid.children().last();
2647  /* Show grid & hide the image it replaces.*/
2648  grid.show();
2649  cur_img.css('opacity', 0);
2650  cur_figure.css('opacity', 0);
2651  /* Add identifying classes to corner gridlets (useful if applying border radius).*/
2652  grid.children().first().addClass('rs-top-left');
2653  grid.children().last().addClass('rs-bottom-right');
2654  grid.children().eq(rows - 1).addClass('rs-bottom-left');
2655  grid.children().eq(- rows).addClass('rs-top-right');
2656
2657  /* Execution steps.*/
2658  setTimeout(function () {
2659    grid.children().css({
2660      opacity: op,
2661      transform: 'rotate('+ ro +'deg) translateX('+ tx +'px) translateY('+ ty +'px) scale('+ sc +')'
2662    });
2663  }, 1);
2664  jQuery(next_image_class).css('opacity', 1);
2665  /* After transition.*/
2666  jQuery(last_gridlet).one('webkitTransitionEnd transitionend otransitionend oTransitionEnd mstransitionend', jQuery.proxy(bwg_after_trans));
2667  function bwg_after_trans() {
2668    jQuery(current_image_class).css({'opacity' : 0, 'z-index': 1});
2669    jQuery(next_image_class).css({'opacity' : 1, 'z-index' : 2});
2670    cur_img.css('opacity', 1);
2671    cur_figure.css('opacity', 1);
2672    grid.remove();
2673
2674    if ( type_slideshow ) {
2675      bwg_params[bwg]['bwg_trans_in_progress'] = false;
2676      var event_stack = bwg_params[bwg]['event_stack'];
2677      var data = bwg_params[bwg]['data'];
2678    }
2679    else {
2680      gallery_box_data['bwg_trans_in_progress'] = false;
2681      var event_stack = gallery_box_data['event_stack'];
2682      var data = '';
2683    }
2684    jQuery(".bwg_image_info").show();
2685    jQuery(current_image_class).html('');
2686
2687    if (typeof event_stack !== 'undefined') {
2688      if (event_stack.length > 0) {
2689        var key = event_stack[0].split("-");
2690        event_stack.shift();
2691        bwg_change_image(key[0], key[1], data, true, bwg);
2692      }
2693    }
2694    if(type_slideshow) {
2695      bwg_change_watermark_container(bwg);
2696    } else {
2697      bwg_change_watermark_container();
2698    }
2699  }
2700  if (bwg_transition_dur == 0) {
2701    bwg_after_trans();
2702  }
2703}
2704
2705function bwg_sliceH(current_image_class, next_image_class, direction, bwg) {
2706  if (direction == 'right') {
2707    var translateX = 'min-auto';
2708  }
2709  else if (direction == 'left') {
2710    var translateX = 'auto';
2711  }
2712  bwg_grid(1, 8, 0, translateX, 0, 1, 0, current_image_class, next_image_class, direction, bwg);
2713}
2714
2715function bwg_sliceV(current_image_class, next_image_class, direction, bwg) {
2716  if (direction == 'right') {
2717    var translateY = 'min-auto';
2718  }
2719  else if (direction == 'left') {
2720    var translateY = 'auto';
2721  }
2722
2723  bwg_grid(10, 1, 0, 0, translateY, 1, 0, current_image_class, next_image_class, direction, bwg);
2724}
2725
2726function bwg_slideV(current_image_class, next_image_class, direction, bwg) {
2727  if (direction == 'right') {
2728    var translateY = 'auto';
2729  }
2730  else if (direction == 'left') {
2731    var translateY = 'min-auto';
2732  }
2733  bwg_grid(1, 1, 0, 0, translateY, 1, 1, current_image_class, next_image_class, direction, bwg);
2734}
2735
2736function bwg_slideH(current_image_class, next_image_class, direction, bwg) {
2737  if (direction == 'right') {
2738    var translateX = 'min-auto';
2739  }
2740  else if (direction == 'left') {
2741    var translateX = 'auto';
2742  }
2743  bwg_grid(1, 1, 0, translateX, 0, 1, 1, current_image_class, next_image_class, direction, bwg);
2744}
2745
2746function bwg_scaleOut(current_image_class, next_image_class, direction, bwg) {
2747  bwg_grid(1, 1, 0, 0, 0, 1.5, 0, current_image_class, next_image_class, direction, bwg);
2748}
2749
2750function bwg_scaleIn(current_image_class, next_image_class, direction, bwg) {
2751  bwg_grid(1, 1, 0, 0, 0, 0.5, 0, current_image_class, next_image_class, direction, bwg);
2752}
2753
2754function bwg_blockScale(current_image_class, next_image_class, direction, bwg) {
2755  bwg_grid(8, 6, 0, 0, 0, .6, 0, current_image_class, next_image_class, direction, bwg);
2756}
2757
2758function bwg_kaleidoscope(current_image_class, next_image_class, direction, bwg) {
2759  bwg_grid(10, 8, 0, 0, 0, 1, 0, current_image_class, next_image_class, direction, bwg);
2760}
2761
2762function bwg_fan(current_image_class, next_image_class, direction, bwg) {
2763  if (direction == 'right') {
2764    var rotate = 45;
2765    var translateX = 100;
2766  }
2767  else if (direction == 'left') {
2768    var rotate = -45;
2769    var translateX = -100;
2770  }
2771  bwg_grid(1, 10, rotate, translateX, 0, 1, 0, current_image_class, next_image_class, direction, bwg);
2772}
2773
2774function bwg_blindV(current_image_class, next_image_class, direction, bwg) {
2775  bwg_grid(1, 8, 0, 0, 0, .7, 0, current_image_class, next_image_class, '', bwg);
2776}
2777
2778function bwg_blindH(current_image_class, next_image_class, direction, bwg) {
2779  bwg_grid(10, 1, 0, 0, 0, .7, 0, current_image_class, next_image_class, '', bwg);
2780}
2781
2782function bwg_random(current_image_class, next_image_class, direction, bwg) {
2783  var anims = ['sliceH', 'sliceV', 'slideH', 'slideV', 'scaleOut', 'scaleIn', 'blockScale', 'kaleidoscope', 'fan', 'blindH', 'blindV'];
2784  /* Pick a random transition from the anims array.*/
2785  var rand_effect = anims[Math.floor(Math.random() * anims.length)];
2786  this["bwg_" + rand_effect](current_image_class, next_image_class, direction, bwg);
2787}
2788
2789/* Set watermark container size.*/
2790function bwg_change_watermark_container( bwg ) {
2791  var defix = ( typeof bwg !== 'undefined' && bwg !== '' ) ? '_'+bwg : '';
2792  jQuery(".bwg_slider"+defix).children().each(function() {
2793    if (jQuery(this).css("zIndex") == 2) {
2794      /* For images.*/
2795      var bwg_current_image_span = jQuery(this).find("img");
2796      if (bwg_current_image_span.length) {
2797        if (bwg_current_image_span.prop('complete')) {
2798          var width = bwg_current_image_span.width();
2799          var height = bwg_current_image_span.height();
2800          bwg_change_each_watermark_container(width, height, bwg);
2801        }
2802        else {
2803          bwg_current_image_span.on("load", function () {
2804            var width = bwg_current_image_span.width();
2805            var height = bwg_current_image_span.height();
2806            bwg_change_each_watermark_container(width, height, bwg);
2807          });
2808        }
2809      }
2810      else {
2811        /* For embeds and videos.*/
2812        bwg_current_image_span = jQuery(this).find("iframe");
2813        if (!bwg_current_image_span.length) {
2814          bwg_current_image_span = jQuery(this).find("video");
2815        }
2816        var width = bwg_current_image_span.width();
2817        var height = bwg_current_image_span.height();
2818        bwg_change_each_watermark_container(width, height, bwg);
2819      }
2820    }
2821  });
2822}
2823
2824/* Set each watermark container size.*/
2825function bwg_change_each_watermark_container(width, height, bwg) {
2826  var defix = ( typeof bwg !== 'undefined' && bwg !== '' ) ? '_'+bwg : '';
2827  var source = ( typeof bwg !== 'undefined' && bwg !== '' ) ? '_slideshow' : '';
2828
2829  jQuery(".bwg"+source+"_watermark_spun" + defix).width(width);
2830  jQuery(".bwg"+source+"_watermark_spun" + defix).height(height);
2831  jQuery(".bwg"+source+"_watermark" + defix).css({display: ''});
2832
2833  if( typeof bwg === 'undefined' || bwg === '' ) {
2834    /* Set watermark image size.*/
2835    var comment_container_width = 0;
2836    if (jQuery(".bwg_comment_container").hasClass("bwg_open") || jQuery(".bwg_ecommerce_container").hasClass("bwg_open")) {
2837      comment_container_width = gallery_box_data['lightbox_comment_width'];
2838    }
2839    if (width <= (jQuery(window).width() - comment_container_width)) {
2840      jQuery(".bwg_watermark_image").css({
2841        width: ((jQuery(".spider_popup_wrap").width() - comment_container_width) * gallery_box_data['watermark_font_size'] / gallery_box_data['image_width'])
2842      });
2843      jQuery(".bwg_watermark_text, .bwg_watermark_text:hover").css({
2844        fontSize: ((jQuery(".spider_popup_wrap").width() - comment_container_width) * gallery_box_data['watermark_font_size'] / gallery_box_data['image_width'])
2845      });
2846    }
2847  } else {
2848    jQuery(".bwg" + source + "_title_spun" + defix).width(width);
2849    jQuery(".bwg" + source + "_title_spun" + defix).height(height);
2850    jQuery(".bwg" + source + "_description_spun" + defix).width(width);
2851    jQuery(".bwg" + source + "_description_spun" + defix).height(height);
2852  }
2853  if (jQuery.trim(jQuery(".bwg"+source+"_title_text" + defix).text())) {
2854    jQuery(".bwg_slideshow_title_text" + defix).css({display: ''});
2855  }
2856  if (jQuery.trim(jQuery(".bwg"+source+"_description_text" + defix).text())) {
2857    jQuery(".bwg"+source+"_description_text" + defix).css({display: ''});
2858  }
2859}
2860
2861/* Set filmstrip initial position.*/
2862function bwg_set_filmstrip_pos( filmStripWidth, bwg, data ) {
2863  var defix = ( typeof bwg !== 'undefined' && bwg !== '' ) ? '_'+bwg : '';
2864  var source = ( typeof bwg !== 'undefined' && bwg !== '' ) ? '_slideshow' : '';
2865
2866  var left_or_top;
2867  if ( typeof bwg !== 'undefined' && bwg !== '' ) {
2868    left_or_top = bwg_params[bwg]['left_or_top'];
2869  }
2870  else {
2871    left_or_top = gallery_box_data['left_or_top'];
2872  }
2873  var top_bottom_space = parseInt(jQuery(".bwg_filmstrip_thumbnails").attr('data-all-images-top-bottom-space'));
2874  var right_left_space = parseInt(jQuery(".bwg_filmstrip_thumbnails").attr('data-all-images-right-left-space'));
2875  if( typeof bwg === 'undefined' || bwg === '' ) {  /* for lightbox */
2876    if ( gallery_box_data['outerWidth_or_outerHeight'] == 'outerWidth' ) {
2877      var selectedImagePos = -bwg_current_filmstrip_pos - (jQuery(".bwg_filmstrip_thumbnail").outerWidth(true)) / 2;
2878    } else if ( gallery_box_data['outerWidth_or_outerHeight'] == 'outerHeight' ) {
2879      var selectedImagePos = -bwg_current_filmstrip_pos - (jQuery(".bwg_filmstrip_thumbnail").outerHeight(true)) / 2;
2880    }
2881    if ( gallery_box_data['width_or_height'] == 'width' ) {
2882      var imagesContainerLeft = Math.min(0, Math.max(filmStripWidth - jQuery(".bwg_filmstrip_thumbnails").width(), selectedImagePos + filmStripWidth / 2));
2883    } else if (gallery_box_data['width_or_height'] == 'height') {
2884      var imagesContainerLeft = Math.min(0, Math.max(filmStripWidth - jQuery(".bwg_filmstrip_thumbnails").height(), selectedImagePos + filmStripWidth / 2));
2885    }
2886  }
2887  else { /* for slideshow */
2888    if (bwg_params[bwg]['width_or_height'] == 'width') {
2889      var selectedImagePos = -bwg_params[bwg]['bwg_current_filmstrip_pos'] - (jQuery(".bwg_slideshow_filmstrip_thumbnail" + defix).width() + bwg_params[bwg]['filmstrip_thumb_margin_hor']) / 2;
2890      var imagesContainerLeft = Math.min(0, Math.max(filmStripWidth - jQuery(".bwg_slideshow_filmstrip_thumbnails" + defix).width(), selectedImagePos + filmStripWidth / 2));
2891    }
2892    else {
2893      var selectedImagePos = -bwg_params[bwg]['bwg_current_filmstrip_pos'] - (jQuery(".bwg_slideshow_filmstrip_thumbnail" + defix).height() + bwg_params[bwg]['filmstrip_thumb_margin_hor']) / 2;
2894      var imagesContainerLeft = Math.min(0, Math.max(filmStripWidth - jQuery(".bwg_slideshow_filmstrip_thumbnails" + defix).height(), selectedImagePos + filmStripWidth / 2));
2895    }
2896  }
2897
2898  if ( imagesContainerLeft + right_left_space > 0 ) {
2899    right_left_space = 0;
2900  }
2901  if ( imagesContainerLeft + top_bottom_space > 0 ) {
2902    top_bottom_space = 0;
2903  }
2904
2905  if( left_or_top == 'left' ) {
2906    jQuery(".bwg"+source+"_filmstrip_thumbnails" + defix).animate({
2907      left: imagesContainerLeft + right_left_space
2908    }, {
2909      duration: 500,
2910      complete: function () {
2911        if ( typeof  data != 'undefined' ) {
2912          bwg_disable_lightbox_filmstrip_left_right_arrow( data );
2913        }
2914      }
2915    });
2916  }
2917  else {
2918    jQuery(".bwg"+source+"_filmstrip_thumbnails" + defix).animate({
2919      top: imagesContainerLeft + top_bottom_space
2920    },
2921    {
2922      duration: 500,
2923      complete: function () {
2924        if ( typeof  data != 'undefined' ) {
2925          bwg_disable_lightbox_filmstrip_left_right_arrow( data );
2926        }
2927      }
2928    });
2929  }
2930}
2931
2932/**
2933 * Slideshow filmstrip fix dimension.
2934 *
2935 * @param bwg
2936 */
2937function bwg_slideshow_filmstrip_fix_dimension( bwg ) {
2938  var bwg_filmstrip_width;
2939  var bwg_filmstrip_thumbnails_width;
2940  var image_left;
2941  var image_right;
2942  var long_filmstrip_cont_left;
2943  var long_filmstrip_cont_right;
2944
2945  var defix = ( typeof bwg !== 'undefined' && bwg !== '' ) ? '_' + bwg : '';
2946  var source = ( typeof bwg !== 'undefined' && bwg !== '' ) ? '_slideshow' : '';
2947  var outerWidth_or_outerHeight = ( typeof bwg !== 'undefined' && bwg !== '' && typeof bwg_params[bwg]['outerWidth_or_outerHeight'] != 'undefined' ) ? bwg_params[bwg]['outerWidth_or_outerHeight'] : gallery_box_data['outerWidth_or_outerHeight'];
2948  var left_or_top = ( typeof bwg !== 'undefined' && bwg !== '' && typeof bwg_params[bwg]['left_or_top'] != 'undefined' ) ? bwg_params[bwg]['left_or_top'] : gallery_box_data['left_or_top'];
2949
2950  if(outerWidth_or_outerHeight == 'outerWidth') {
2951    bwg_filmstrip_width = jQuery(".bwg" + source + "_filmstrip" + defix).outerWidth(true);
2952    bwg_filmstrip_thumbnails_width = jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).outerWidth(true);
2953  } else {
2954    bwg_filmstrip_width = jQuery(".bwg" + source + "_filmstrip" + defix).outerHeight(true);
2955    bwg_filmstrip_thumbnails_width = jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).outerHeight(true);
2956  }
2957  if( left_or_top == 'left' ) {
2958    image_left = jQuery(".bwg" + source + "_thumb_active" + defix).position().left;
2959    if( outerWidth_or_outerHeight == 'outerWidth' ) {
2960      image_right = jQuery(".bwg" + source + "_thumb_active" + defix).position().left + jQuery(".bwg" + source + "_thumb_active" + defix).outerWidth(true);
2961    } else {
2962      image_right = jQuery(".bwg" + source + "_thumb_active" + defix).position().left + jQuery(".bwg" + source + "_thumb_active" + defix).outerHeight(true);
2963    }
2964    long_filmstrip_cont_left = jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).position().left;
2965    long_filmstrip_cont_right = Math.abs(jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).position().left) + bwg_filmstrip_width;
2966  }
2967  else {
2968    image_left = jQuery(".bwg" + source + "_thumb_active" + defix).position().top;
2969    if( outerWidth_or_outerHeight == 'outerWidth' ) {
2970      image_right = jQuery(".bwg" + source + "_thumb_active" + defix).position().top + jQuery(".bwg" + source + "_thumb_active" + defix).outerWidth(true);
2971    } else {
2972      image_right = jQuery(".bwg" + source + "_thumb_active" + defix).position().top + jQuery(".bwg" + source + "_thumb_active" + defix).outerHeight(true);
2973    }
2974    long_filmstrip_cont_left = jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).position().top;
2975    long_filmstrip_cont_right = Math.abs(jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).position().top) + bwg_filmstrip_width;
2976  }
2977  if (bwg_filmstrip_width > bwg_filmstrip_thumbnails_width) {
2978    return;
2979  }
2980  if (image_left < Math.abs(long_filmstrip_cont_left)) {
2981    if ( left_or_top == 'left' ) {
2982      jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).animate({
2983        left: -image_left
2984      }, {
2985        duration: 500
2986      });
2987    } else {
2988      jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).animate({
2989        top: -image_left
2990      }, {
2991        duration: 500
2992      });
2993    }
2994  }
2995  else if (image_right > long_filmstrip_cont_right) {
2996    if ( left_or_top == 'left' ) {
2997      jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).animate({
2998        left: -(image_right - bwg_filmstrip_width)
2999      }, {
3000        duration: 500
3001      });
3002    } else {
3003      jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).animate({
3004        top: -(image_right - bwg_filmstrip_width)
3005      }, {
3006        duration: 500
3007      });
3008    }
3009  }
3010}
3011
3012/**
3013 * Slideshow filmstrip fix count.
3014 *
3015 * @param bwg
3016 */
3017function bwg_slideshow_filmstrip_fix_count( bwg ) {
3018  var bwg_filmstrip_width;
3019  var bwg_filmstrip_thumbnails_width;
3020  var image_left;
3021  var image_right;
3022  var long_filmstrip_cont_left;
3023  var long_filmstrip_cont_right;
3024  var defix = (typeof bwg !== 'undefined' && bwg !== '') ? '_' + bwg : '';
3025  var source = (typeof bwg !== 'undefined' && bwg !== '') ? '_slideshow' : '';
3026  var outerWidth_or_outerHeight = (typeof bwg !== 'undefined' && bwg !== '') ? bwg_params[bwg]['outerWidth_or_outerHeight'] : gallery_box_data['outerWidth_or_outerHeight'];
3027  var left_or_top = (typeof bwg !== 'undefined' && bwg !== '') ? bwg_params[bwg]['left_or_top'] : gallery_box_data['left_or_top'];
3028  if ( outerWidth_or_outerHeight == 'outerWidth' ) {
3029    bwg_filmstrip_width = jQuery('.bwg' + source + '_filmstrip_fix_count' + defix).outerWidth(true);
3030    bwg_filmstrip_thumbnails_width = jQuery('.bwg' + source + '_filmstrip_thumbnails' + defix).outerWidth(true);
3031  }
3032  else {
3033    bwg_filmstrip_width = jQuery(".bwg" + source + "_filmstrip_fix_count" + defix).outerHeight(true);
3034    bwg_filmstrip_thumbnails_width = jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).outerHeight(true);
3035  }
3036  if ( left_or_top == 'left' ) {
3037    image_left = jQuery(".bwg" + source + "_thumb_active" + defix).position().left;
3038    if ( outerWidth_or_outerHeight == 'outerWidth' ) {
3039      image_right = jQuery(".bwg" + source + "_thumb_active" + defix).position().left + jQuery(".bwg" + source + "_thumb_active" + defix).outerWidth(true);
3040    }
3041    else {
3042      image_right = jQuery(".bwg" + source + "_thumb_active" + defix).position().left + jQuery(".bwg" + source + "_thumb_active" + defix).outerHeight(true);
3043    }
3044    long_filmstrip_cont_left = jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).position().left;
3045    long_filmstrip_cont_right = Math.abs(jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).position().left) + bwg_filmstrip_width;
3046  }
3047  else {
3048    image_left = jQuery(".bwg" + source + "_thumb_active" + defix).position().top;
3049    if ( outerWidth_or_outerHeight == 'outerWidth' ) {
3050      image_right = jQuery(".bwg" + source + "_thumb_active" + defix).position().top + jQuery(".bwg" + source + "_thumb_active" + defix).outerWidth(true);
3051    }
3052    else {
3053      image_right = jQuery(".bwg" + source + "_thumb_active" + defix).position().top + jQuery(".bwg" + source + "_thumb_active" + defix).outerHeight(true);
3054    }
3055    long_filmstrip_cont_left = jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).position().top;
3056    long_filmstrip_cont_right = Math.abs(jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).position().top) + bwg_filmstrip_width;
3057  }
3058  if ( bwg_filmstrip_width > bwg_filmstrip_thumbnails_width ) {
3059    return;
3060  }
3061  if ( image_left < Math.abs(long_filmstrip_cont_left) ) {
3062    if ( left_or_top == 'left' ) {
3063      jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).animate({
3064          left: -image_left
3065        },
3066        {
3067          duration: 500
3068        });
3069    }
3070    else {
3071      jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).animate({
3072          top: -image_left
3073        },
3074        {
3075          duration: 500
3076        });
3077    }
3078  }
3079  else if ( image_right > long_filmstrip_cont_right ) {
3080    if ( left_or_top == 'left' ) {
3081      jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).animate({
3082          left: -(image_right - bwg_filmstrip_width)
3083        },
3084        {
3085          duration: 500
3086        });
3087    }
3088    else {
3089      jQuery(".bwg" + source + "_filmstrip_thumbnails" + defix).animate({
3090          top: -(image_right - bwg_filmstrip_width)
3091        },
3092        {
3093          duration: 500
3094        });
3095    }
3096  }
3097}
3098
3099/**
3100 * Resize slideshow filmstrip fix count.
3101 *
3102 * @param args
3103 */
3104function bwg_resize_slideshow_filmstrip_fix_count( args ) {
3105  var bwg = args['bwg'];
3106  var parent_width = args['parent_width'];
3107  var params = args['params'];
3108  var filmstrip_direction = params['filmstrip_direction'];
3109  var images = params['data'];
3110  var filmstrip_thumb_margin_hor = params['filmstrip_thumb_margin_hor'];
3111  var filmstrip_thumbnail_key = 'bwg_slideshow_filmstrip_thumbnail_' + bwg;
3112  // After size 767 we set the number of images to 5.
3113  var is_change_size = ( jQuery(window).width() <= 767 && params['slideshow_thumbnails_count'] > 5 ) ? true : false;
3114  var slideshow_thumbnails_count = ( is_change_size ) ? 5 : params['slideshow_thumbnails_count'];
3115
3116  var filmstrip_thumbnail_key = 'bwg_slideshow_filmstrip_thumbnail_' + bwg;
3117  var filmstrip_container = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_container_' + bwg;
3118  var filmstrip_fix_count = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_fix_count_' + bwg;
3119  var filmstrip_thumbnails = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_fix_count_' + bwg + ' .bwg_slideshow_filmstrip_thumbnails_' + bwg;
3120  var filmstrip_thumbnail = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_fix_count_' + bwg + ' .bwg_slideshow_filmstrip_thumbnails_' + bwg + ' .bwg_slideshow_filmstrip_thumbnail_' + bwg;
3121  var slideshow_image_container = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_image_container_' + bwg;
3122
3123  var filmstrip_position = jQuery(slideshow_image_container).data('filmstrip-position');
3124  var filmstrip_size = jQuery(slideshow_image_container).data('filmstrip-size');
3125  var filmstrip_rl_btn_size = params['slideshow_filmstrip_rl_btn_size'];
3126  jQuery('#bwg_container1_' + bwg).css({ width: '100%' });
3127  jQuery('#bwg_container1_' + bwg + ' #bwg_container2_' + bwg).css({
3128    width: parent_width
3129  });
3130
3131  if ( typeof resize_in_progress == 'undefined' || resize_in_progress === false ) {
3132    window.resize_in_progress = true;
3133    if ( typeof resize_timer != 'undefined' ) {
3134      clearTimeout(resize_timer);
3135    }
3136    var resize_timer = setTimeout(function(){
3137      resize_in_progress = false;
3138      var filmstrip_thumbnails_css = {};
3139      if ( filmstrip_position == 'bottom' || filmstrip_position == 'top' ) {
3140        filmstrip_thumbnails_css.left = 0;
3141      }
3142      else {
3143        filmstrip_thumbnails_css.top = 0;
3144      }
3145      jQuery(filmstrip_thumbnails).css(filmstrip_thumbnails_css);
3146      // Changes next / previous icon to active or passive.
3147      var slideshow_filmstrip_angle_display_value = (filmstrip_direction == 'horizontal') ? 'table-cell' : 'block';
3148      jQuery(filmstrip_container).find('.bwg_slideshow_filmstrip_left_' + bwg).css({ display: 'none' });
3149      jQuery(filmstrip_container).find('.bwg_slideshow_filmstrip_left_disabled_' + bwg).css({ display: slideshow_filmstrip_angle_display_value });
3150      jQuery(filmstrip_container).find('.bwg_slideshow_filmstrip_right_' + bwg).css({ display: slideshow_filmstrip_angle_display_value });
3151      jQuery(filmstrip_container).find('.bwg_slideshow_filmstrip_right_disabled_' + bwg).css({ display: 'none' });
3152    }, 500);
3153  }
3154
3155  bwg_resize_instagram_post(bwg);
3156  /* Set watermark container size.*/
3157  bwg_change_watermark_container(bwg);
3158  if ( filmstrip_direction == 'horizontal' ) {
3159    var thumb_ratio = params['image_height'] / params['image_width'];
3160    // set filmstrip block width height.
3161    var slideshow_filmstrip_block_width = parent_width - 40;
3162    var slideshow_filmstrip_block_height = Math.round(thumb_ratio * slideshow_filmstrip_block_width);
3163    // set filmstrip thumb width height.
3164    var slideshow_filmstrip_width = ( slideshow_filmstrip_block_width - (filmstrip_thumb_margin_hor * slideshow_thumbnails_count) ) / slideshow_thumbnails_count;
3165    var slideshow_filmstrip_height = Math.round(thumb_ratio * slideshow_filmstrip_width);
3166
3167    jQuery(filmstrip_container).css({
3168      'width': parent_width,
3169      'height': slideshow_filmstrip_height
3170    });
3171
3172    jQuery(filmstrip_fix_count).css({
3173      'width': slideshow_filmstrip_block_width,
3174      'height': slideshow_filmstrip_height
3175    });
3176
3177    jQuery(filmstrip_thumbnail).css({
3178      'width': slideshow_filmstrip_width,
3179      'height': slideshow_filmstrip_height
3180    });
3181
3182    jQuery.each(images, function ( key, image ) {
3183      var image_thumb_width = slideshow_filmstrip_width;
3184      var image_thumb_height = slideshow_filmstrip_height;
3185      if ( image['image_width'] != '' && image['image_height'] != '' ) {
3186        var scale = Math.max(slideshow_filmstrip_width / image['image_width'], slideshow_filmstrip_he
3186ight / image['image_height']);
3187        image_thumb_width = image['image_width'] * scale;
3188        image_thumb_height = image['thumb_height'] * scale;
3189      }
3190      if ( image['thumb_width'] != '' && image['thumb_height'] != '' ) {
3191        image_thumb_width = image['thumb_width'];
3192        image_thumb_height = image['thumb_height'];
3193      }
3194      var scale = Math.max(slideshow_filmstrip_width / image_thumb_width, slideshow_filmstrip_height / image_thumb_height);
3195      var image_thumb_width = image_thumb_width * scale;
3196      var image_thumb_height = image_thumb_height * scale;
3197      //var image_thumb_left = (slideshow_filmstrip_width - image_thumb_width) / 2;
3198      //var image_thumb_top = (slideshow_filmstrip_height - image_thumb_height) / 2;
3199      var fix_count_thumbnail_img = '.bwg_slideshow_filmstrip_fix_count_' + bwg + ' .bwg_slideshow_filmstrip_thumbnail_' + bwg + ' .bwg_slideshow_filmstrip_thumbnail_img_' + bwg;
3200      jQuery(fix_count_thumbnail_img).css({
3201        'width': slideshow_filmstrip_width,
3202        'height': slideshow_filmstrip_height,
3203        'margin-left': 0,
3204        'margin-top': 0
3205      });
3206    });
3207
3208    jQuery(filmstrip_thumbnails).css({
3209      width: ( (slideshow_filmstrip_width * images.length) + (filmstrip_thumb_margin_hor * images.length) ),
3210      height: slideshow_filmstrip_height,
3211    });
3212
3213    jQuery(".bwg_slideshow_image_wrap_" + bwg).css({
3214      width: parent_width,
3215      height: (parent_width * params['image_height'] / params['image_width'])
3216    });
3217    var slideshow_image_css = {
3218      width: parent_width,
3219      height: ((parent_width * (params['image_height'] / params['image_width'])) - slideshow_filmstrip_height),
3220    };
3221    slideshow_image_css[filmstrip_position] = slideshow_filmstrip_height;
3222    jQuery(".bwg_slideshow_image_container_" + bwg).css(slideshow_image_css);
3223
3224    jQuery(".bwg_slideshow_image_" + bwg).css({
3225      cssText: "max-width:" + parent_width + "px !important; max-height:" + ( (parent_width * (params['image_height'] / params['image_width']) ) - slideshow_filmstrip_height) + "px !important;"
3226    });
3227    jQuery(".bwg_slideshow_embed_" + bwg).css({
3228      cssText: "width:" + parent_width + "px !important; height:" + ( (parent_width * (params['image_height'] / params['image_width']) ) - slideshow_filmstrip_height) + "px !important;"
3229    });
3230    jQuery(".bwg_embed_frame_" + bwg).css({
3231      'max-width': parent_width + 'px',
3232      'max-height': ( (parent_width * (params['image_height'] / params['image_width']) ) - slideshow_filmstrip_height) + 'px'
3233    });
3234    jQuery(".bwg_embed_frame_" + bwg).attr('data-width', parent_width);
3235    jQuery(".bwg_embed_frame_" + bwg).attr('data-height', ( (parent_width * (params['image_height'] / params['image_width']) ) - slideshow_filmstrip_height));
3236    if ( filmstrip_rl_btn_size > slideshow_filmstrip_height ) {
3237      filmstrip_rl_btn_size = slideshow_filmstrip_height;
3238    }
3239    // If we show a lot of pictures in "filmstrip", we reduce the font-size of bwg-icon-angle to the appropriate size of filmstrip.
3240    jQuery(filmstrip_container).find('.bwg-icon-angle-left').css({ 'font-size': filmstrip_rl_btn_size });
3241    jQuery(filmstrip_container).find('.bwg-icon-angle-right').css({ 'font-size': filmstrip_rl_btn_size });
3242  }
3243  else {
3244    var parent_height = (parent_width * params['image_height'] / params['image_width']);
3245    var thumb_ratio = params['image_width'] / params['image_height'];
3246    // set filmstrip block width height.
3247    var slideshow_filmstrip_block_height = parent_height - 40;
3248    var slideshow_filmstrip_block_width = Math.round(thumb_ratio * slideshow_filmstrip_block_height);
3249    // set filmstrip thumb width height.
3250    var slideshow_filmstrip_height = (slideshow_filmstrip_block_height - (filmstrip_thumb_margin_hor * slideshow_thumbnails_count)) / slideshow_thumbnails_count;
3251    var slideshow_filmstrip_width  = Math.round(thumb_ratio * slideshow_filmstrip_height);
3252
3253    jQuery.each(images, function ( key, image ) {
3254      var image_thumb_width = slideshow_filmstrip_width;
3255      var image_thumb_height = slideshow_filmstrip_height;
3256      if ( image['image_width'] != '' && image['image_height'] != '' ) {
3257        var scale = Math.max(slideshow_filmstrip_width / image['image_width'], slideshow_filmstrip_he
3257ight / image['image_height']);
3258        image_thumb_width = image['image_width'] * scale;
3259        image_thumb_height = image['thumb_height'] * scale;
3260      }
3261      if ( image['thumb_width'] != '' && image['thumb_height'] != '' ) {
3262        image_thumb_width = image['thumb_width'];
3263        image_thumb_height = image['thumb_height'];
3264      }
3265      var scale = Math.max(slideshow_filmstrip_width / image_thumb_width, slideshow_filmstrip_height / image_thumb_height);
3266      var image_thumb_width = image_thumb_width * scale;
3267      var image_thumb_height = image_thumb_height * scale;
3268      var image_thumb_left = (slideshow_filmstrip_width - image_thumb_width) / 2;
3269      var image_thumb_top = (slideshow_filmstrip_height - image_thumb_height) / 2;
3270      var fix_count_thumbnail_img = '.bwg_slideshow_filmstrip_fix_count_' + bwg + ' .bwg_slideshow_filmstrip_thumbnail_' + bwg + ' .bwg_slideshow_filmstrip_thumbnail_img_' + bwg;
3271      jQuery(fix_count_thumbnail_img).css({
3272        'width': slideshow_filmstrip_width,
3273        'height': slideshow_filmstrip_height,
3274        'margin-left': 0,
3275        'margin-top': 0
3276      });
3277    });
3278
3279    jQuery(filmstrip_container).css({
3280      width: slideshow_filmstrip_width,
3281      height: parent_height
3282    });
3283
3284    jQuery(filmstrip_fix_count).css({
3285      width: slideshow_filmstrip_width,
3286      height: slideshow_filmstrip_block_height
3287    });
3288
3289    jQuery(filmstrip_thumbnails).css({
3290      width: slideshow_filmstrip_width,
3291      height: ( (slideshow_filmstrip_height * images.length) + (filmstrip_thumb_margin_hor * images.length) )
3292    });
3293
3294    jQuery(filmstrip_thumbnail).css({
3295      width: slideshow_filmstrip_width,
3296      height: slideshow_filmstrip_height
3297    });
3298
3299    jQuery('.bwg_slideshow_image_wrap_' + bwg).css({
3300      width: parent_width,
3301      height: parent_height
3302    });
3303    var slideshow_image_css = {
3304      width: parent_width - slideshow_filmstrip_width,
3305      height: parent_height,
3306    };
3307    slideshow_image_css[filmstrip_position] = slideshow_filmstrip_width;
3308    jQuery(slideshow_image_container).css(slideshow_image_css);
3309
3310    jQuery(".bwg_slideshow_image_" + bwg).css({
3311      cssText: "max-width:" + (parent_width - slideshow_filmstrip_width) + "px !important; max-height:" + parent_height + "px !important;"
3312    });
3313
3314    jQuery(".bwg_slideshow_embed_" + bwg).css({
3315      cssText: "width:" + (parent_width - slideshow_filmstrip_width) + "px !important; height:" + parent_height + "px !important;"
3316    });
3317
3318    jQuery(".bwg_embed_frame_" + bwg).css({
3319      'max-width': (parent_width - slideshow_filmstrip_width) + 'px',
3320      'max-height': parent_height + 'px'
3321    });
3322    jQuery(".bwg_embed_frame_" + bwg).attr('data-width', (parent_width - slideshow_filmstrip_width) );
3323    jQuery(".bwg_embed_frame_" + bwg).attr('data-height', parent_height);
3324
3325    if ( filmstrip_rl_btn_size > slideshow_filmstrip_width ) {
3326      filmstrip_rl_btn_size = slideshow_filmstrip_width;
3327    }
3328    // If we show a lot of pictures in "filmstrip", we reduce the font-size of bwg-icon-angle to the appropriate size of filmstrip.
3329    jQuery(filmstrip_container).find('.bwg-icon-angle-up').css({ 'font-size': filmstrip_rl_btn_size });
3330    jQuery(filmstrip_container).find('.bwg-icon-angle-down').css({ 'font-size': filmstrip_rl_btn_size });
3331  }
3332  if ( is_change_size ) {
3333    jQuery(filmstrip_container).find('.bwg-icon-angle-left').removeAttr('style');
3334    jQuery(filmstrip_container).find('.bwg-icon-angle-right').removeAttr('style');
3335    jQuery(filmstrip_container).find('.bwg-icon-angle-up').removeAttr('style');
3336    jQuery(filmstrip_container).find('.bwg-icon-angle-down').removeAttr('style');
3337  }
3338}
3339
3340/**
3341 * Resize slideshow filmstrip fix dimension.
3342 *
3343 * @param args
3344 */
3345function bwg_resize_slideshow_filmstrip_fix_dimension( args ) {
3346  var bwg = args['bwg'];
3347  var parent_width = args['parent_width'];
3348  var params = args['params'];
3349  var filmstrip_direction = params['filmstrip_direction'];
3350  var filmstrip_width = params['slideshow_filmstrip_width'];
3351  var filmstrip_height = params['slideshow_filmstrip_height'];
3352
3353  var bwg_container1_class_name = '#bwg_container1_' + bwg;
3354  var bwg_container2_class_name = bwg_container1_class_name + ' #bwg_container2_' + bwg;
3355  var bwg_slideshow_image_wrap_class_name = bwg_container2_class_name + ' .bwg_slideshow_image_wrap_' + bwg;
3356  var bwg_slideshow_image_container_class_name = bwg_container2_class_name + ' .bwg_slideshow_image_container_' + bwg;
3357  var bwg_slideshow_image_class_name = bwg_container2_class_name + ' .bwg_slideshow_image_' + bwg;
3358  var bwg_slideshow_embed_class_name = bwg_container2_class_name + ' .bwg_slideshow_embed_' + bwg;
3359
3360  var bwg_slideshow_filmstrip_container_class_name = bwg_slideshow_image_wrap_class_name + ' .bwg_slideshow_filmstrip_container_' + bwg;
3361  var bwg_slideshow_filmstrip_class_name = bwg_slideshow_filmstrip_container_class_name + ' .bwg_slideshow_filmstrip_' + bwg;
3362
3363	var slideshow_width = parent_width;
3364	var slideshow_height = slideshow_width * (params['image_height'] / params['image_width']);
3365
3366  jQuery(bwg_slideshow_image_wrap_class_name).css({
3367    width: slideshow_width,
3368    height: slideshow_height
3369  });
3370  jQuery(bwg_slideshow_image_container_class_name).css({
3371    width: (slideshow_width - (filmstrip_direction == 'horizontal' ? 0 : filmstrip_width)),
3372    height: (slideshow_height - (filmstrip_direction == 'horizontal' ? filmstrip_height : 0))
3373  });
3374  jQuery(bwg_slideshow_image_class_name).css({
3375    'display': 'inline-block',
3376    'max-width': (slideshow_width - (filmstrip_direction == 'horizontal' ? 0 : filmstrip_width)),
3377    'max-height': (slideshow_height - (filmstrip_direction == 'horizontal' ? filmstrip_height : 0))
3378  });
3379  jQuery(bwg_slideshow_embed_class_name).css({
3380    cssText: "width: " + (slideshow_width - (filmstrip_direction == 'horizontal' ? 0 : filmstrip_width)) + "px !important; height: " + (slideshow_height - (filmstrip_direction == 'horizontal' ? filmstrip_height : 0) - 1) + "px !important;"
3381  });
3382
3383  bwg_resize_instagram_post(bwg);
3384  /* Set watermark container size.*/
3385  bwg_change_watermark_container(bwg);
3386
3387  if ( filmstrip_direction == 'horizontal' ) {
3388    jQuery(bwg_slideshow_filmstrip_container_class_name).css({ width: slideshow_width });
3389    jQuery(bwg_slideshow_filmstrip_class_name).css({ width: slideshow_width - 40 });
3390  }
3391  else {
3392    jQuery(bwg_slideshow_filmstrip_container_class_name).css({ height: slideshow_height });
3393    jQuery(bwg_slideshow_filmstrip_class_name).css({ height: slideshow_height - 40 });
3394  }
3395}
3396
3397/**
3398 * Calculate slideshow filmstrip thumbnail width.
3399 *
3400 * @param args
3401 * @returns {number}
3402 */
3403function bwg_calculate_slideshow_filmstrip_thumbnail_size( args ) {
3404  var bwg = args['bwg'];
3405  var params = args['params'];
3406  var size = params['slideshow_filmstrip_width'];
3407  if ( params['slideshow_filmstrip_type'] == 2 ) {
3408    var selector = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_fix_count_' + bwg + ' .bwg_slideshow_filmstrip_thumbnail_' + bwg;
3409    if ( params['left_or_top'] == 'left' ) {
3410      if ( params['width_or_height'] == 'width' ) {
3411        size = jQuery(selector).width();
3412      }
3413      else {
3414        size = jQuery(selector).height();
3415      }
3416    }
3417    else {
3418      if ( params['width_or_height'] == 'width' ) {
3419        size = jQuery(selector).width();
3420      }
3421      else {
3422        size = jQuery(selector).height();
3423      }
3424    }
3425  }
3426  return parseFloat(size);
3427}
3428
3429function bwg_move_dots( bwg ) {
3430  var image_left = jQuery(".bwg_slideshow_dots_active_" + bwg).position().left;
3431  var image_right = jQuery(".bwg_slideshow_dots_active_" + bwg).position().left + jQuery(".bwg_slideshow_dots_active_" + bwg).outerWidth(true);
3432  var bwg_dots_width = jQuery(".bwg_slideshow_dots_container_" + bwg).outerWidth(true);
3433  var bwg_dots_thumbnails_width = jQuery(".bwg_slideshow_dots_thumbnails_" + bwg).outerWidth(false);
3434  var long_filmstrip_cont_left = jQuery(".bwg_slideshow_dots_thumbnails_" + bwg).position().left;
3435  var long_filmstrip_cont_right = Math.abs(jQuery(".bwg_slideshow_dots_thumbnails_" + bwg).position().left) + bwg_dots_width;
3436  if (bwg_dots_width > bwg_dots_thumbnails_width) {
3437    return;
3438  }
3439  if (image_left < Math.abs(long_filmstrip_cont_left)) {
3440    jQuery(".bwg_slideshow_dots_thumbnails_" + bwg).animate({
3441      left: -image_left
3442    }, {
3443      duration: 500
3444    });
3445  }
3446  else if (image_right > long_filmstrip_cont_right) {
3447    jQuery(".bwg_slideshow_dots_thumbnails_" + bwg).animate({
3448      left: -(image_right - bwg_dots_width)
3449    }, {
3450      duration: 500
3451    });
3452  }
3453}
3454
3455function bwg_testBrowser_cssTransitions( bwg ) {
3456  return bwg_testDom('Transition', bwg);
3457}
3458
3459function bwg_testBrowser_cssTransforms3d( bwg ) {
3460  return bwg_testDom('Perspective', bwg);
3461}
3462
3463function bwg_testDom(prop, bwg) {
3464  /* Browser vendor CSS prefixes.*/
3465  var browserVendors = ['', '-webkit-', '-moz-', '-ms-', '-o-', '-khtml-'];
3466  /* Browser vendor DOM prefixes.*/
3467  var domPrefixes = ['', 'Webkit', 'Moz', 'ms', 'O', 'Khtml'];
3468  var i = domPrefixes.length;
3469  while (i--) {
3470    if (typeof document.body.style[domPrefixes[i] + prop] !== 'undefined') {
3471      return true;
3472    }
3473  }
3474  return false;
3475}
3476
3477/* For browsers that does not support transitions.*/
3478function bwg_fallback(current_image_class, next_image_class, direction, bwg) {
3479  bwg_fade(current_image_class, next_image_class, direction, bwg);
3480}
3481
3482/* For browsers that support transitions, but not 3d transforms (only used if primary transition makes use of 3d-transforms).*/
3483function bwg_fallback3d(current_image_class, next_image_class, direction, bwg) {
3484  bwg_sliceV(current_image_class, next_image_class, direction, bwg);
3485}
3486
3487function bwg_none(current_image_class, next_image_class, direction, bwg) {
3488  var defix = ( typeof bwg !== 'undefined' && bwg !== '' ) ? '_'+bwg : '';
3489  jQuery(current_image_class).css({'opacity' : 0, 'z-index': 1});
3490  jQuery(next_image_class).css({'opacity' : 1, 'z-index' : 2});
3491
3492  if ( typeof bwg !== 'undefined' && bwg !== '' ) {
3493    var bwg_current_key = bwg_params[bwg]['bwg_current_key'];
3494    bwg_change_watermark_container(bwg);
3495    /* Set active thumbnail.*/
3496    jQuery(".bwg_slideshow_filmstrip_thumbnail" + defix).removeClass("bwg_slideshow_thumb_active" + defix).addClass("bwg_slideshow_thumb_deactive" + defix);
3497    jQuery("#bwg_filmstrip_thumbnail_" + bwg_current_key + defix).removeClass("bwg_slideshow_thumb_deactive" + defix).addClass("bwg_slideshow_thumb_active" + defix);
3498    jQuery(".bwg_slideshow_dots" + defix).removeClass("bwg_slideshow_dots_active" + defix).addClass("bwg_slideshow_dots_deactive" + defix);
3499    jQuery("#bwg_dots_" + bwg_current_key + defix).removeClass("bwg_slideshow_dots_deactive" + defix).addClass("bwg_slideshow_dots_active" + defix);
3500  }
3501  else {
3502    /* Lightbox */
3503    jQuery(".bwg_image_info").show();
3504    gallery_box_data['bwg_trans_in_progress'] = false;
3505    jQuery(current_image_class).html('');
3506    bwg_change_watermark_container();
3507  }
3508}
3509
3510function bwg_iterator( bwg ) {
3511  var iterator = 1;
3512  if ( typeof bwg !== 'undefined' && bwg !== '' && typeof bwg_params[bwg] != 'undefined' && bwg_params[bwg]['enable_slideshow_shuffle'] == 1 ) {
3513    iterator = Math.floor((bwg_params[bwg]['data'].length - 1) * Math.random() + 1);
3514  }
3515  return iterator;
3516}
3517
3518function bwg_change_image_slideshow(current_key, key, data, from_effect, bwg) {
3519  var data = bwg_params[bwg]['data'];
3520  /* Pause videos.*/
3521  jQuery('#bwg_slideshow_image_container_' + bwg).find('iframe').each(function () {
3522    jQuery(this)[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
3523    jQuery(this)[0].contentWindow.postMessage('{ "method": "pause" }', "*");
3524    jQuery(this)[0].contentWindow.postMessage('pause', '*');
3525  });
3526  /* Pause videos facebook video.*/
3527  jQuery('#image_id_' + bwg + '_' + data[current_key]['id']).find('.bwg_fb_video').each(function () {
3528    jQuery(this).attr('src', jQuery(this).attr('src'));
3529  });
3530  if (data[key]) {
3531    if (jQuery('.bwg_ctrl_btn_' + bwg).hasClass('bwg-icon-pause')) {
3532      bwg_play( bwg_params[bwg]['data'], bwg );
3533    }
3534    if (!from_effect) {
3535      /* Change image key.*/
3536      jQuery("#bwg_current_image_key_" + bwg).val(key);
3537      if (current_key == '-1') { /* Filmstrip.*/
3538        current_key = jQuery(".bwg_slideshow_thumb_active_" + bwg).children("img").attr("image_key");
3539      }
3540      else if (current_key == '-2') { /* Dots.*/
3541        current_key = jQuery(".bwg_slideshow_dots_active_" + bwg).attr("image_key");
3542      }
3543    }
3544    if ( bwg_params[bwg]['bwg_trans_in_progress'] ) {
3545      bwg_params[bwg]['event_stack'].push(current_key + '-' + key);
3546      return;
3547    }
3548    var direction = 'right';
3549    if (current_key > key) {
3550      var direction = 'left';
3551    } else if (current_key == key) {
3552      return;
3553    }
3554
3555    jQuery(".bwg_slideshow_watermark_" + bwg).css({display: 'none'});
3556    jQuery(".bwg_slideshow_title_text_" + bwg).css({display: 'none'});
3557    jQuery(".bwg_slideshow_description_text_" + bwg).css({display: 'none'});
3558    /* Set active thumbnail position.*/
3559    if ( bwg_params[bwg]['width_or_height'] == 'width' ) {
3560      bwg_params[bwg]['bwg_current_filmstrip_pos'] = key * (jQuery(".bwg_slideshow_filmstrip_thumbnail_" + bwg).width() + 2 + 2 * bwg_params[bwg]['lightbox_filmstrip_thumb_border_width']);
3561    } else {
3562      bwg_params[bwg]['bwg_current_filmstrip_pos'] = key * (jQuery(".bwg_slideshow_filmstrip_thumbnail_" + bwg).height() + 2 + 2 * bwg_params[bwg]['lightbox_filmstrip_thumb_border_width']);
3563    }
3564
3565    current_key = key;
3566    bwg_params[bwg]['bwg_current_key'] = current_key;
3567    /* Change image id, title, description.*/
3568    jQuery("#bwg_slideshow_image_" + bwg).attr('image_id', data[key]["id"]);
3569    jQuery(".bwg_slideshow_title_text_" + bwg).html(jQuery('<span style="display: block;" />').html(data[key]["alt"]).text());
3570    jQuery(".bwg_slideshow_description_text_" + bwg).html(jQuery('<span style="display: block;" />').html(data[key]["description"]).text());
3571    var current_image_class = jQuery(".bwg_slideshow_image_spun_" + bwg).css("zIndex") == 2 ? ".bwg_slideshow_image_spun_" + bwg : ".bwg_slideshow_image_second_spun_" + bwg;
3572    var next_image_class = current_image_class == ".bwg_slideshow_image_second_spun_" + bwg ? ".bwg_slideshow_image_spun_" + bwg : ".bwg_slideshow_image_second_spun_" + bwg;
3573    var is_embed = data[key]['filetype'].indexOf("EMBED_") > -1 ? true : false;
3574    var is_embed_instagram_post = data[key]['filetype'].indexOf('INSTAGRAM_POST') > -1 ? true :false;
3575    var is_embed_instagram_video = data[key]['filetype'].indexOf('INSTAGRAM_VIDEO') > -1 ? true :false;
3576    var cur_height = jQuery(current_image_class).height();
3577    var cur_width = jQuery(current_image_class).width();
3578    var innhtml = '<span class="bwg_slideshow_image_spun1_' + bwg +'" style="display:  ' + (!is_embed ? 'table' : 'block') + ' ;width: inherit; height: inherit;"><span class="bwg_slideshow_image_spun2_' + bwg + '" style="display: ' + (!is_embed ? 'table-cell' : 'block') + '; vertical-align: middle; text-align: center; ">';
3579    if ( !is_embed ) {
3580      if (bwg_params[bwg]['thumb_click_action'] != 'do_nothing' ) {
3581        var argument = '';
3582        if (bwg_params[bwg]['thumb_click_action'] == 'open_lightbox')
3583        {
3584          argument += ' class="bwg_lightbox" data-image-id="' + data[key]["id"] + '" data-elementor-open-lightbox="no"';
3585        } else {
3586          if ( bwg_params[bwg]["thumb_click_action"] == "redirect_to_url" && data[key]["redirect_url"] ) {
3587            argument += 'href="' + data[key]["redirect_url"] + '"' + ( (bwg_params[bwg]['thumb_link_target'] && bwg_params[bwg]['thumb_link_target'] == 1) ? ' target="_blank"' : '' );
3588          }
3589        }
3590        innhtml += '<a ' + argument + '>';
3591      }
3592      innhtml += '<img style="max-height: ' + cur_height + 'px !important; max-width: ' + cur_width + 'px !important; display:inline-block;" ';
3593      innhtml +=   ' class="bwg_slide bwg_slideshow_image_'+bwg+'" ';
3594      innhtml +=   ' id="bwg_slideshow_image_' + bwg + '" ';
3595      innhtml +=   ' src="' + bwg_params[bwg]['upload_url'] + jQuery("<sp
3595an style=\'display: block;\' />").html(decodeURIComponent(data[key]["image_url"])).text() + '" alt="' + data[key]["alt"] + '" image_id="' + data[key]["id"] + '" /></a>';
3596    }
3597    else { /*is_embed*/
3598      innhtml += '<span style="height: ' + cur_height + 'px; width: ' + cur_width + 'px;" class="bwg_popup_embed bwg_popup_watermark">';
3599      if (is_embed_instagram_video ) {
3600        innhtml += '<span class="bwg_inst_play_btn_cont" onclick="bwg_play_instagram_video(this)"><span class="bwg_inst_play"></span></span>';
3601      }
3602      if ( is_embed_instagram_post ) {
3603        var embed_frame = jQuery('.bwg_embed_frame');
3604        /* HoverCard, Feedback, SocialProof height from Instagram */
3605        var feedback_social_proof_height = 109;
3606        var maxWidth = jQuery('.bwg_slideshow_image_container_' + bwg).width();
3607        var maxHeight = jQuery('.bwg_slideshow_image_container_'+ bwg).height();
3608        var srcWidth = data[key].image_width;
3609        var srcHeight = data[key].image_height;
3610        // Add the resizing logic
3611        var instagram_resizing = bwg_resizing_ratio(srcWidth, srcHeight, maxWidth, maxHeight);
3612        embed_frame.attr('data-width', maxWidth);
3613        embed_frame.attr('data-height', maxHeight);
3614        var instagram_width = instagram_resizing.width;
3615        var instagram_height = instagram_resizing.height;
3616        if ( instagram_height > instagram_width ) {
3617          instagram_width = instagram_width - feedback_social_proof_height;
3618        }
3619        else {
3620          instagram_width = instagram_width + feedback_social_proof_height;
3621        }
3622        innhtml += spider_display_embed(data[key]['filetype'], decodeURIComponent(data[key]['image_url']), data[key]['filename'], {
3623          class:'bwg_embed_frame',
3624          'data-width': maxWidth,
3625          'data-height': maxHeight,
3626          'data-instagram-width': srcWidth,
3627          'data-instagram-height': srcHeight,
3628          style: 'width: 100%; height: 100%; max-width: 100%; max-height: 100%; vertical-align:middle; display:inline-block; position:relative;'
3629        });
3630      }
3631      else {
3632        innhtml += spider_display_embed(data[key]['filetype'], decodeURIComponent(data[key]['image_url']), data[key]['filename'], {
3633          class:'bwg_embed_frame',
3634          frameborder:'0',
3635          allowfullscreen:'allowfullscreen',
3636          "data-max-width": cur_width,
3637          "data-max-height": cur_height,
3638          style:'width:inherit; height:inherit; vertical-align:middle; display:table-cell;'
3639        });
3640      }
3641      innhtml += "</span>";
3642    }
3643    innhtml += '</span></span>';
3644    jQuery(next_image_class).html(innhtml);
3645    if (bwg_params[bwg]['preload_images']) {
3646      bwg_preload_images(key, bwg);
3647    }
3648    window["bwg_" + bwg_params[bwg]['slideshow_effect']](current_image_class, next_image_class, direction, bwg);
3649    // Slideshow filmstrip type is Fix dimension.
3650    if ( bwg_params[bwg]['slideshow_filmstrip_type'] == 1 ) {
3651      bwg_slideshow_filmstrip_fix_dimension( bwg );
3652    }
3653    // Slideshow filmstrip type is Fix count.
3654    else if ( bwg_params[bwg]['slideshow_filmstrip_type'] == 2 ) {
3655      bwg_slideshow_filmstrip_fix_count( bwg );
3656    }
3657    // Slideshow filmstrip type is None.
3658    else {
3659      bwg_move_dots( bwg);
3660    }
3661    if (data[key]["is_embed_video"]) {
3662      jQuery("#bwg_slideshow_play_pause_" + bwg).css({display: 'none'});
3663    }
3664    else {
3665      jQuery("#bwg_slideshow_play_pause_" + bwg).css({display: ''});
3666    }
3667  }
3668  bwg_add_lightbox();
3669
3670  var display_value = (bwg_params[bwg]['filmstrip_direction'] == 'horizontal') ? 'table-cell' : 'block';
3671  var active_prev = jQuery('.bwg_slideshow_filmstrip_thumbnails_' + bwg + ' .bwg_slideshow_thumb_active_' + bwg).prev();
3672  var active_next = jQuery('.bwg_slideshow_filmstrip_thumbnails_' + bwg + ' .bwg_slideshow_thumb_active_'+ bwg).next();
3673  var arrow_filmstrip_left = jQuery('.bwg_slideshow_filmstrip_container_' + bwg + ' .bwg_slideshow_filmstrip_left_'+ bwg);
3674  var arrow_filmstrip_left_disabled = jQuery('.bwg_slideshow_filmstrip_container_' + bwg + ' .bwg_slideshow_filmstrip_left_disabled_'+ bwg);
3675  var arrow_filmstrip_right = jQuery('.bwg_slideshow_filmstrip_container_' + bwg + ' .bwg_slideshow_filmstrip_right_'+ b
3675wg);
3676  var arrow_filmstrip_right_disabled = jQuery('.bwg_slideshow_filmstrip_container_' + bwg + ' .bwg_slideshow_filmstrip_right_disabled_'+ bwg);
3677
3678  if ( ! active_prev.length ) {
3679    arrow_filmstrip_left.css({'display': 'none'});
3680    arrow_filmstrip_left_disabled.css({'display': display_value});
3681    arrow_filmstrip_right.css({'display': display_value});
3682    arrow_filmstrip_right_disabled.css({'display': 'none'});
3683  }
3684  else {
3685    arrow_filmstrip_left.css({'display': display_value});
3686    arrow_filmstrip_left_disabled.css({'display': 'none'});
3687  }
3688  if ( ! active_next.length ) {
3689    arrow_filmstrip_right.css({'display': 'none'});
3690    arrow_filmstrip_right_disabled.css({'display': display_value});
3691    arrow_filmstrip_left.css({'display': display_value});
3692    arrow_filmstrip_left_disabled.css({'display': 'none'});
3693  }
3694  else {
3695    arrow_filmstrip_right.css({'display': display_value});
3696    arrow_filmstrip_right_disabled.css({'display': 'none'});
3697  }
3698  if ( typeof data[key] != 'undefined' && data[key].filetype == 'EMBED_OEMBED_INSTAGRAM_POST' ) {
3699    /* Uses Instagram oEmbed data to create iframe tag. */
3700    if ( typeof instgrm !== 'undefined' && typeof instgrm.Embeds !== 'undefined' ) {
3701      jQuery('.instagram-media').hide();
3702      instgrm.Embeds.process();
3703      jQuery('.instagram-media').css({
3704        'max-height': instagram_height + 'px',
3705        'min-width': instagram_width + 'px !important'
3706      });
3707      jQuery('.instagram-media').show();
3708    }
3709  }
3710}
3711
3712function bwg_preload_images_slideshow( key, bwg ) {
3713  var data = bwg_params[bwg]['data'];
3714  count = bwg_params[bwg]['preload_images_count'] / 2;
3715  var count_all = data.length;
3716  if (count_all < bwg_params[bwg]['preload_images_count']) {
3717    count = 0;
3718  }
3719  if (count != 0) {
3720    for (var i = key - count; i < key + count; i++) {
3721      var index = parseInt((i + count_all) % count_all);
3722      var is_embed = data[index]['filetype'].indexOf("EMBED_") > -1 ? true : false;
3723      if (typeof data[index] != "undefined") {
3724        if (!is_embed) {
3725          jQuery("<img/>").attr("src", bwg_params[bwg]['upload_url'] + jQuery('<span style="display: block;" />').html(decodeURIComponent(data[index]["image_url"])).text());
3726        }
3727      }
3728    }
3729  } else {
3730    for (var i = 0; i < data.length; i++) {
3731      var is_embed = data[i]['filetype'].indexOf("EMBED_") > -1 ? true : false;
3732      if (typeof data[i] != "undefined") {
3733        if (!is_embed) {
3734          jQuery("<img/>").attr("src", bwg_params[bwg]['upload_url'] + jQuery('<span style="display: block;" />').html(decodeURIComponent(data[i]["image_url"])).text());
3735        }
3736      }
3737    }
3738  }
3739}
3740
3741function bwg_preload_images( key, bwg ) {
3742  if ( typeof bwg !== 'undefined' && bwg !== '' ) { /* SLIDESHOW */
3743    bwg_preload_images_slideshow( key, bwg );
3744  } else {  /* LIGHTBOX */
3745    bwg_preload_images_lightbox( key );
3746  }
3747}
3748
3749function bwg_popup_resize_slidshow( bwg ) {
3750  var slideshow_filmstrip_class_name = ".bwg_slideshow_filmstrip_" + bwg;
3751  /* Slideshow filmstrip type is Fix count. */
3752  if ( bwg_params[bwg]['slideshow_filmstrip_type'] == 2 ) {
3753    slideshow_filmstrip_class_name = ".bwg_slideshow_filmstrip_fix_count_" + bwg;
3754  }
3755  var parentt = jQuery("#bwg_container1_" + bwg).parent();
3756  /* Trick to set parent's width to wordpress content area. */
3757  if ( parentt.hasClass('content-area') ) {
3758    parentt.width(parentt.closest('.content-area').width());
3759  }
3760  /* Trick to set parent's width to elementor tab. */
3761  if ( parentt.hasClass('elementor-tab-content') ) {
3762    parentt.width(parentt.closest('.elementor-widget-wrap').width());
3763  }
3764  var parent_width = parentt.width();
3765  var data = bwg_params[bwg]['data'];
3766  if ( parent_width >= bwg_params[bwg]['image_width'] ) {
3767    jQuery(".bwg_slideshow_image_wrap_" + bwg).css({ width: bwg_params[bwg]['image_width'] });
3768    jQuery(".bwg_slideshow_image_wrap_" + bwg).css({ height: bwg_params[bwg]['image_height'] });
3769    jQuery(".bwg_slideshow_image_container_" + bwg).css({ width: (bwg_params[bwg]['filmstrip_direction'] == 'horizontal') ? bwg_params[bwg]['image_width'] : (bwg_params[bwg]['image_width'] - bwg_params[bwg]['slideshow_filmstrip_width']) });
3770    jQuery(".bwg_slideshow_image_container_" + bwg).css({ height: (bwg_params[bwg]['filmstrip_direction'] == 'horizontal') ? bwg_params[bwg]['image_height'] - bwg_params[bwg]['slideshow_filmstrip_he
3770ight'] : bwg_params[bwg]['image_height'] });
3771    jQuery(".bwg_slideshow_image_" + bwg).css({
3772      cssText: "max-width:" + (bwg_params[bwg]['filmstrip_direction'] == 'horizontal ') ? bwg_params[bwg]['image_width'] : (bwg_params[bwg]['image_width'] - bwg_params[bwg]['slideshow_filmstrip_width']) + "px !important; max-height: " + (bwg_params[bwg]['filmstrip_direction'] == 'horizontal') ? (bwg_params[bwg]['image_height'] - bwg_params[bwg]['slideshow_filmstrip_height']) : bwg_params[bwg]['image_height'] + "px !important;"
3773    });
3774    jQuery(".bwg_slideshow_embed_" + bwg).css({
3775      cssText: "width:" + (bwg_params[bwg]['filmstrip_direction'] == 'horizontal') ? bwg_params[bwg]['image_width'] : (bwg_params[bwg]['image_width'] - bwg_params[bwg]['slideshow_filmstrip_width']) + "px !important; height:" + (bwg_params[bwg]['filmstrip_direction'] == 'horizontal') ? (bwg_params[bwg]['image_height'] - bwg_params[bwg]['slideshow_filmstrip_height']) : bwg_params[bwg]['image_height'] + "px !important;"
3776    });
3777    bwg_resize_instagram_post(bwg);
3778    /* Set watermark container size. */
3779    bwg_change_watermark_container(bwg);
3780    var filmstrip_container_css = (bwg_params[bwg]['filmstrip_direction'] == 'horizontal') ? 'width: ' + bwg_params[bwg]['image_width'] : 'height: ' + bwg_params[bwg]['image_height'];
3781    var filmstrip_css = (bwg_params[bwg]['filmstrip_direction'] == 'horizontal') ? 'width: ' + (bwg_params[bwg]['image_width'] - 40) : 'height: ' + (bwg_params[bwg]['image_height'] - 40);
3782    jQuery(".bwg_slideshow_filmstrip_container_" + bwg).css({ cssText: filmstrip_container_css });
3783    jQuery(slideshow_filmstrip_class_name).css({ cssText: filmstrip_css });
3784    jQuery(".bwg_slideshow_dots_container_" + bwg).css({ width: bwg_params[bwg]['image_width'] });
3785    jQuery("#bwg_slideshow_play_pause-ico_" + bwg).css({ fontSize: (bwg_params[bwg]['slideshow_play_pause_btn_size']) });
3786    if ( bwg_params[bwg]['watermark_type'] == 'image' ) {
3787      jQuery(".bwg_slideshow_watermark_image_" + bwg).css({
3788        maxWidth: bwg_params[bwg]['watermark_width'],
3789        maxHeight: bwg_params[bwg]['watermark_height']
3790      });
3791    }
3792    if ( bwg_params[bwg]['watermark_type'] == 'text' ) {
3793      jQuery(".bwg_slideshow_watermark_text_" + bwg + ", .bwg_slideshow_watermark_text_" + bwg + " :hover").css({
3794        fontSize: (bwg_params[bwg]['watermark_font_size'])
3795      });
3796    }
3797    jQuery(".bwg_slideshow_title_text_" + bwg).css({ fontSize: (bwg_params[bwg]['slideshow_title_font_size'] * 2) });
3798    jQuery(".bwg_slideshow_description_text_" + bwg).css({ fontSize: (bwg_params[bwg]['slideshow_description_font_size'] * 2) });
3799    /* Slideshow filmstrip type is Fix count. */
3800    if ( bwg_params[bwg]['slideshow_filmstrip_type'] == 2 ) {
3801      var filmstrip_direction = bwg_params[bwg]['filmstrip_direction'];
3802      var bwg_container2 = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg;
3803      jQuery(bwg_container2).removeAttr('style');
3804      var slideshow_filmstrip_container = bwg_container2 + ' .bwg_slideshow_filmstrip_container_' + bwg;
3805      var filmstrip_rl_btn_size = bwg_params[bwg].slideshow_filmstrip_rl_btn_size;
3806      var slideshow_filmstrip_size = jQuery('.bwg_slideshow_filmstrip_fix_count_' + bwg).width();
3807      if ( filmstrip_direction == 'horizontal' ) {
3808        slideshow_filmstrip_size = jQuery('.bwg_slideshow_filmstrip_fix_count_' + bwg).height();
3809      }
3810      var slideshow_filmstrip_angle_display_value = (filmstrip_direction == 'horizontal') ? 'table-cell' : 'block';
3811      // Changes next / previous icon to active or passive.
3812      jQuery(slideshow_filmstrip_container).find('.bwg_slideshow_filmstrip_left_' + bwg).css({ display: 'none' });
3813      jQuery(slideshow_filmstrip_container).find('.bwg_slideshow_filmstrip_left_disabled_' + bwg).css({ display: slideshow_filmstrip_angle_display_value });
3814      jQuery(slideshow_filmstrip_container).find('.bwg_slideshow_filmstrip_right_' + bwg).css({ display: slideshow_filmstrip_angle_display_value });
3815      jQuery(slideshow_filmstrip_container).find('.bwg_slideshow_filmstrip_right_disabled_' + bwg).css({ display: 'none' });
3816      // If we show a lot of pictures in "filmstrip", we reduce the font-size of bwg-icon-angle to the appropriate size of filmstrip.
3817      if ( filmstrip_rl_btn_size > slideshow_filmstrip_size ) {
3818        filmstrip_rl_btn_size = slideshow_filmstrip_size;
3819        jQuery(slideshow_filmstrip_container).find('.bwg-icon-angle-left').css({ 'font-size': filmstrip_rl_btn_size });
3820        jQuery(slideshow_filmstrip_container).find('.bwg-icon-angle-right').css({ 'font-size': filmstrip_rl_btn_size });
3821        jQuery(slideshow_filmstrip_container).find('.bwg-icon-angle-up').css({ 'font-size': filmstrip_rl_btn_size });
3822        jQuery(slideshow_filmstrip_container).find('.bwg-icon-angle-down').css({ 'font-size': filmstrip_rl_btn_size });
3823      }
3824      else {
3825        jQuery(slideshow_filmstrip_container).find('.bwg-icon-angle-left').removeAttr('style');
3826        jQuery(slideshow_filmstrip_container).find('.bwg-icon-angle-right').removeAttr('style');
3827        jQuery(slideshow_filmstrip_container).find('.bwg-icon-angle-up').removeAttr('style');
3828        jQuery(slideshow_filmstrip_container).find('.bwg-icon-angle-down').removeAttr('style');
3829      }
3830      var slideshow_filmstrip_thumbnails = bwg_container2 + ' .bwg_slideshow_filmstrip_thumbnails_' + bwg;
3831      jQuery(slideshow_filmstrip_thumbnails).removeAttr('style');
3832      var filmstrip_thumbnail = slideshow_filmstrip_thumbnails + ' .bwg_slideshow_filmstrip_thumbnail_' + bwg;
3833      jQuery(filmstrip_thumbnail).each(function ( i, val ) {
3834        jQuery(val).attr('style', jQuery(val).attr('data-style'));
3835        jQuery(val).find('img').attr('style', jQuery(val).attr('data-style'));
3836      });
3837      var slideshow_image_container = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_image_container_' + bwg;
3838      var filmstrip_position = jQuery(slideshow_image_container).data('filmstrip-position');
3839      var filmstrip_size = jQuery(slideshow_image_container).data('filmstrip-size');
3840      jQuery(slideshow_image_container).css({
3841        filmstrip_position: filmstrip_size
3842      });
3843      var filmstrip_thumbnail_key = 'bwg_slideshow_filmstrip_thumbnail_' + bwg;
3844      if ( window.bwg_slideshow_filmstrip_thumb[filmstrip_thumbnail_key]['next_prev_index'] ) {
3845        window.bwg_slideshow_filmstrip_thumb[filmstrip_thumbnail_key]['next_prev_index'] = 0;
3846      }
3847    }
3848  }
3849  else {
3850    /* Slideshow filmstrip type is Fix dimension. */
3851    if ( bwg_params[bwg]['slideshow_filmstrip_type'] == 1 ) {
3852      bwg_resize_slideshow_filmstrip_fix_dimension({ 'bwg': bwg, 'params': bwg_params[bwg], 'parent_width': parent_width });
3853    }
3854    /* Slideshow filmstrip type is Fix count. */
3855    if ( bwg_params[bwg]['slideshow_filmstrip_type'] == 2 ) {
3856      bwg_resize_slideshow_filmstrip_fix_count({ 'bwg': bwg, 'params': bwg_params[bwg], 'parent_width': parent_width });
3857    }
3858    /* Slideshow filmstrip type is None. */
3859    if ( bwg_params[bwg]['slideshow_filmstrip_type'] == 0 ) {
3860      jQuery(".bwg_slideshow_image_wrap_" + bwg).css({
3861        width: (parent_width),
3862        height: ((parent_width) * bwg_params[bwg]['image_height'] / bwg_params[bwg]['image_width'])
3863      });
3864      jQuery(".bwg_slideshow_image_container_" + bwg).css({
3865        width: (parent_width - (bwg_params[bwg]['filmstrip_direction'] == 'horizontal' ? 0 : bwg_params[bwg]['slideshow_filmstrip_width'])),
3866        height: ((parent_width) * bwg_params[bwg]['image_height'] / bwg_params[bwg]['image_width'] - (bwg_params[bwg]['filmstrip_direction'] == 'horizontal' ? bwg_params[bwg]['slideshow_filmstrip_he
3866ight'] : 0))
3867      });
3868      jQuery(".bwg_slideshow_image_" + bwg).css({
3869        cssText: "max-width: " + (parent_width - (bwg_params[bwg]['filmstrip_direction'] == 'horizontal' ? 0 : bwg_params[bwg]['slideshow_filmstrip_width'])) + "px !important; max-height: " + (parent_width * (bwg_params[bwg]['image_height'] / bwg_params[bwg]['image_width']) - (bwg_params[bwg]['filmstrip_direction'] == 'horizontal' ? bwg_params[bwg]['slideshow_filmstrip_height'] : 0) - 1) + "px !important;"
3870      });
3871      jQuery(".bwg_embed_frame_" + bwg + ", .bwg_slideshow_embed_" + bwg).css({
3872        'max-width':  parent_width + 'px',
3873        'max-height': (parent_width * (bwg_params[bwg]['image_height'] / bwg_params[bwg]['image_width']) - (bwg_params[bwg]['filmstrip_direction'] == 'horizontal' ? bwg_params[bwg]['slideshow_filmstrip_height'] : 0) - 1) + 'px'
3874      });
3875      jQuery(".bwg_embed_frame_" + bwg).attr('data-width', parent_width);
3876      jQuery(".bwg_embed_frame_" + bwg).attr('data-height', (parent_width * (bwg_params[bwg]['image_height'] / bwg_params[bwg]['image_width']) - (bwg_params[bwg]['filmstrip_direction'] == 'horizontal' ? bwg_params[bwg]['slideshow_filmstrip_height'] : 0) - 1));
3877    }
3878
3879    jQuery(".bwg_slideshow_dots_container_" + bwg).css({ width: parent_width });
3880    jQuery("#bwg_slideshow_play_pause-ico_" + bwg).css({ fontSize: (parent_width * (bwg_params[bwg]['slideshow_play_pause_btn_size'] / bwg_params[bwg]['image_width'])) });
3881    jQuery(".bwg_slideshow_watermark_image_" + bwg).css({
3882      maxWidth: (parent_width * (bwg_params[bwg]['watermark_width'] / bwg_params[bwg]['image_width'])),
3883      maxHeight: (parent_width * (bwg_params[bwg]['watermark_height'] / bwg_params[bwg]['image_width']))
3884    });
3885    jQuery(".bwg_slideshow_watermark_text_" + bwg + ", .bwg_slideshow_watermark_text_" + bwg + ":hover").css({ fontSize: (parent_width * (bwg_params[bwg]['watermark_font_size'] / bwg_params[bwg]['image_width'])) });
3886    jQuery(".bwg_slideshow_title_text_" + bwg).css({ fontSize: ((parent_width) * 2 * bwg_params[bwg]['slideshow_title_font_size'] / bwg_params[bwg]['image_width']) });
3887    jQuery(".bwg_slideshow_description_text_" + bwg).css({ fontSize: ((parent_width) * 2 * bwg_params[bwg]['slideshow_description_font_size'] / bwg_params[bwg]['image_width']) });
3888  }
3889  var bwg_slide_container = jQuery(".bwg_slide_container_" + bwg)
3890  var cur_width = bwg_slide_container.width();
3891  var cur_height = bwg_slide_container.height();
3892  jQuery(".bwg_popup_embed").css({"width":cur_width + "px", "height":cur_height + "px"});
3893
3894  if ( data[parseInt(jQuery("#bwg_current_image_key_" + bwg).val())]["is_embed_video"] ) {
3895    jQuery("#bwg_slideshow_play_pause_" + bwg).css({ display: 'none' });
3896  }
3897  else {
3898    jQuery("#bwg_slideshow_play_pause_" + bwg).css({ display: '' });
3899  }
3900}
3901
3902function bwg_popup_resize( bwg ) {
3903  if ( typeof bwg !== 'undefined' && bwg !== '' ) { /* SLIDESHOW */
3904    bwg_popup_resize_slidshow( bwg );
3905  }
3906  else {  /* LIGHTBOX */
3907    bwg_popup_resize_lightbox();
3908  }
3909}
3910
3911function bwg_change_image(current_key, key, data, from_effect, bwg) {
3912  if ( typeof bwg !== 'undefined' && bwg !== '' ) { /* SLIDESHOW */
3913    bwg_change_image_slideshow(current_key, key, data, from_effect, bwg);
3914  }
3915  else {  /* LIGHTBOX */
3916    data = gallery_box_data['data'];
3917    bwg_change_image_lightbox(current_key, key, data, from_effect);
3918  }
3919}
3920
3921function bwg_resize_instagram_post( bwg ) {
3922  var is_instagram_embed_iframe = false;
3923  if ( typeof bwg !== 'undefined' && bwg !== '' ) { /* SLIDESHOW */
3924    if ( jQuery('.inner_instagram_iframe_bwg_embed_frame_' + bwg).length ) {
3925      is_instagram_embed_iframe = true;
3926      var instagram_embed = jQuery('#instagram-embed-' + bwg);
3927      var slideshow_embed = jQuery('.bwg_slideshow_embed_' + bwg);
3928      var embed_frame = jQuery('.bwg_embed_frame_' + bwg);
3929      var maxWidth = (typeof slideshow_embed.width() !== 'undefined') ? slideshow_embed.width() : jQuery('.bwg_slideshow_embed_' + bwg).width();
3930      var maxHeight = (typeof slideshow_embed.height() !== 'undefined') ? slideshow_embed.height() : jQuery('.bwg_slideshow_embed_' + bwg).height();
3931      var srcWidth = embed_frame.data('instagram-width');
3932      var srcHeight = embed_frame.data('instagram-height');
3933
3934      bwg_change_watermark_container(bwg);
3935    }
3936  }
3937  else { /* LIGHTBOX */
3938    if ( jQuery('.inner_instagram_iframe_bwg_embed_frame').length ) {
3939      is_instagram_embed_iframe = true;
3940      var instagram_embed = jQuery('.instagram-media');
3941      var embed_frame = jQuery('.bwg_embed_frame');
3942      var maxWidth = jQuery('.bwg_image_container').width();
3943      var maxHeight = jQuery('.bwg_image_container').height();
3944      var srcWidth = embed_frame.data('instagram-width');
3945      var srcHeight = embed_frame.data('instagram-height');
3946
3947      bwg_change_watermark_container();
3948    }
3949  }
3950
3951  if ( is_instagram_embed_iframe === true ) {
3952    // HoverCard, Feedback, SocialProof height from Instagram
3953    var feedback_social_proof_height = 109;
3954    // Add the resizing logic
3955    var instagram_resizing = bwg_resizing_ratio(srcWidth, srcHeight, maxWidth, maxHeight);
3956    embed_frame.attr('data-width', maxWidth);
3957    embed_frame.attr('data-height', maxHeight);
3958    var instagram_width = instagram_resizing.width;
3959    var instagram_height = instagram_resizing.height;
3960    if ( instagram_height > instagram_width ) {
3961      instagram_width = instagram_width - feedback_social_proof_height;
3962    }
3963    else {
3964      instagram_width = instagram_width + feedback_social_proof_height;
3965    }
3966    embed_frame.css({
3967      'width': '100%',
3968      'height': '100%',
3969      'max-width': maxWidth,
3970      'max-height': maxHeight
3971    });
3972    instagram_embed.css({
3973      'min-width': instagram_width + 'px !important',
3974      'max-height': maxHeight + 'px'
3975    });
3976  }
3977}
3978
3979function bwg_play( data, bwg  ) {
3980  if ( typeof bwg !== 'undefined' && bwg !== '' ) {
3981    var data = bwg_params[bwg]['data'];
3982  }
3983  /* Play.*/
3984  if ( typeof bwg !== 'undefined' && bwg !== '' ) { /* SLIDESHOW */
3985    window.clearInterval(window['bwg_playInterval' + bwg]);
3986    window['bwg_playInterval' + bwg] = setInterval(function () {
3987      var iterator = 1;
3988      if (bwg_params[bwg]['enable_slideshow_shuffle'] == 1) {
3989        iterator = Math.floor((data.length - 1) * Math.random() + 1);
3990      }
3991      bwg_change_image( parseInt(jQuery("#bwg_current_image_key_"+bwg).val()), (parseInt(jQuery("#bwg_current_image_key_"+bwg).val()) + iterator) % data.length, data, '', bwg )
3992    }, bwg_params[bwg]['slideshow_interval'] * 1000);
3993  } else {
3994    window.clearInterval(gallery_box_data['bwg_playInterval']);
3995    gallery_box_data['bwg_playInterval'] = setInterval(function () {
3996      /* Stop play of lightbox if comment was opened*/
3997      if ( jQuery(".bwg_comment_container").hasClass("bwg_open") || (jQuery(".bwg_play_pause").length && jQuery(".bwg_play_pause").hasClass("bwg-icon-play"))) {
3998        return;
3999      }
4000
4001      if (typeof data != 'undefined' && typeof data[(parseInt(jQuery('#bwg_current_image_key').val()) + 1)] == 'undefined') {
4002        if (gallery_box_data['enable_loop'] == 1) {
4003          /* Wrap around.*/
4004          bwg_change_image(parseInt(jQuery('#bwg_current_image_key').val()), 0);
4005        }
4006        return;
4007      }
4008      bwg_change_image(parseInt(jQuery('#bwg_current_image_key').val()), parseInt(jQuery('#bwg_current_image_key').val()) + 1)
4009    }, gallery_box_data['slideshow_interval'] * 1000);
4010  }
4011}
4012
4013/*------------------ Image Browser Functions ---------------------------*/
4014function bwg_image_browser( bwg ) {
4015  jQuery('#bwg_embed_frame_16x9_' + bwg).width(jQuery('#bwg_embed_frame_16x9_' + bwg).parents('.image_browser_image_buttons_' + bwg).width());
4016  jQuery('#bwg_embed_frame_16x9_' + bwg).height(jQuery('#bwg_embed_frame_16x9_' + bwg).width() * 0.5625);
4017  jQuery('#bwg_embed_frame_instapost_' + bwg).width(jQuery('#bwg_embed_frame_16x9_' + bwg).parents('.image_browser_image_buttons_' + bwg).width());
4018  /* Conflict with Sydney Theme */
4019  if ( jQuery('.image_browser_images_conteiner_' + bwg).find('.fluid-width-video-wrapper').length ) {
4020    var content = jQuery('.image_browser_images_conteiner_' + bwg).find('.fluid-width-video-wrapper').contents();
4021    jQuery('.image_browser_images_conteiner_' + bwg).find('.fluid-width-video-wrapper').replaceWith(content);
4022  }
4023  /* 16 is 2*padding inside iframe */
4024  /* 96 is 2*padding(top) + 1*padding(bottom) + 40(footer) + 32(header) */
4025  var height = (jQuery('.bwg_embed_frame_instapost_' + bwg).width() - 16) * jQuery('.bwg_embed_frame_instapost_' + bwg).attr('data-height') / jQuery('.bwg_embed_frame_instapost_' + bwg).attr('data-width') + 96;
4026  jQuery('.bwg_embed_frame_instapost_' + bwg).height(height);
4027  jQuery('.inner_instagram_iframe_bwg_embed_frame_instapost_' + bwg).find('iframe[id^="instagram-embed-"]').css({
4028    'max-height': height + 'px',
4029  });
4030
4031  var bwg_image_browser_width = jQuery('.image_browser_images_' + bwg).width();
4032  if (bwg_image_browser_width <= 108) {
4033    jQuery('.paging-input_' + bwg).css('display', 'none');
4034  }
4035  else if (bwg_image_browser_width <= 200) {
4036    jQuery('.paging-input_' + bwg).css('margin', '0% 0% 0% 0%');
4037    jQuery('.paging-input_' + bwg).css('display', 'inline');
4038    jQuery('.tablenav-pages_' + bwg + ' .next-page').css('margin', '0% 0% 0% 0%');
4039    jQuery('.tablenav-pages_' + bwg + ' .prev-page').css('margin', '0% 0% 0% 0%');
4040  }
4041  else if (bwg_image_browser_width <= 580) {
4042    jQuery('.paging-input_' + bwg).css('display', 'inline');
4043    jQuery('.tablenav-pages_' + bwg + ' a').css('font-size', '13px');
4044    jQuery('.paging-input_' + bwg).css('margin', '0% 7% 0% 7%');
4045    jQuery('.tablenav-pages_' + bwg + ' .next-page').css('margin', '0% 0% 0% 0%');
4046    jQuery('.tablenav-pages_' + bwg + ' .prev-page').css('margin', '0% 0% 0% 0%');
4047  }
4048  else {
4049    jQuery('.tablenav-pages_' + bwg + ' a').css('font-size', '15px');
4050    jQuery('.paging-input_' + bwg).css('margin', '0%  14% 0%  14%');
4051    jQuery('.paging-input_' + bwg).css('display', 'inline');
4052    jQuery('.tablenav-pages_' + bwg + ' .next-page').css('margin', '0% 0% 0% 0%');
4053    jQuery('.tablenav-pages_' + bwg + ' .prev-page').css('margin', '0% 0% 0% 0%');
4054  }
4055}
4056
4057/**
4058 * Disable right click.
4059 *
4060 * @param container
4061 */
4062function bwg_disable_right_click( container ) {
4063  container.bind( "contextmenu", function () {
4064    return false;
4065  });
4066  container.css( 'webkitTouchCallout', 'none' );
4067}
4068
4069/**
4070 * Resizing ratio.
4071 *
4072 * @param srcWidth
4073 * @param srcHeight
4074 * @param maxWidth
4075 * @param maxHeight
4076 * @returns {{width: number, height: number}}
4077 */
4078function bwg_resizing_ratio( srcWidth, srcHeight, maxWidth, maxHeight ) {
4079  var ratio = [maxWidth / srcWidth, maxHeight / srcHeight];
4080  ratio = Math.min(ratio[0], ratio[1]);
4081  return { width: srcWidth * ratio, height: srcHeight * ratio };
4082}
4083
4084/**
4085 * Slideshow filmstrip next.
4086 *
4087 * @param args
4088 */
4089function bwg_slideshow_filmstrip_next( args ) {
4090  var bwg = args['bwg'];
4091  var params = args['params'];
4092  var slideshow_filmstrip_class_name = args['slideshow_filmstrip_class_name'];
4093  var slideshow_filmstrip_thumbnail_size = bwg_calculate_slideshow_filmstrip_thumbnail_size( {
4094    'bwg': bwg,
4095    'params': params
4096  });
4097  var filmstrip_thumbnail_key = 'bwg_slideshow_filmstrip_thumbnail_' + bwg;
4098
4099  var slideshow_filmstrip_left = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_left_' + bwg;
4100  var slideshow_filmstrip_left_disabled ='#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_left_disabled_' + bwg;
4101  var slideshow_filmstrip_right = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_right_' + bwg;
4102  var slideshow_filmstrip_right_disabled ='#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_right_disabled_' + bwg;
4103  var slideshow_filmstrip_angle_display_value = (params['filmstrip_direction'] == 'horizontal') ? 'table-cell' : 'block';
4104  if ( params['left_or_top'] == 'left' ) { /* For left, width */
4105    if ( params['width_or_height'] == 'width' ) {
4106      if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left >= -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).width() - jQuery(slideshow_filmstrip_class_name).width()) ) {
4107        jQuery(slideshow_filmstrip_left).css({ display: slideshow_filmstrip_angle_display_value });
4108        jQuery(slideshow_filmstrip_left_disabled).css({ display: 'none' });
4109
4110        if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left < -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).width() - jQuery(slideshow_filmstrip_class_name).width() - ( parseInt(params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size )) ) {
4111          jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ left: -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).width() - jQuery(slideshow_filmstrip_class_name).width()) }, 500, 'linear');
4112        }
4113        else {
4114          jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ left: (jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left - ( parseInt(params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size )) }, 500, 'linear');
4115        }
4116      }
4117      /* Disable right arrow.*/
4118      window.setTimeout(function () {
4119        if ( parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left) == -parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).width() - jQuery(slideshow_filmstrip_class_name).width()) ) {
4120          jQuery(slideshow_filmstrip_right).css({ display: 'none' });
4121          jQuery(slideshow_filmstrip_right_disabled).css({ display: slideshow_filmstrip_angle_display_value });
4122        }
4123        else {
4124          jQuery(slideshow_filmstrip_right).css({ display: slideshow_filmstrip_angle_display_value });
4125          jQuery(slideshow_filmstrip_right_disabled).css({ display: 'none' });
4126        }
4127      }, 510);
4128    }
4129    else { /* For left, height */
4130      if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left >= -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).height() - jQuery(slideshow_filmstrip_class_name).height()) ) {
4131        jQuery(slideshow_filmstrip_left).css({ display: slideshow_filmstrip_angle_display_value });
4132        jQuery(slideshow_filmstrip_left_disabled).css({ display: 'none' });
4133        if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left < -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).height() - jQuery(slideshow_filmstrip_class_name).height() - ( parseInt(params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size )) ) {
4134          jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ left: -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).height() - jQuery(slideshow_filmstrip_class_name).height()) }, 500, 'linear');
4135        }
4136        else {
4137          jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ left: (jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left - ( parseInt(params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size )) }, 500, 'linear');
4138        }
4139      }
4140      /* Disable right arrow.*/
4141      window.setTimeout(function () {
4142        if ( parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left) == -parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).height() - jQuery(slideshow_filmstrip_class_name).height()) ) {
4143          jQuery(slideshow_filmstrip_right).css({ display: 'none' });
4144          jQuery(slideshow_filmstrip_right_disabled).css({ display: slideshow_filmstrip_angle_display_value });
4145        }
4146        else {
4147          jQuery(slideshow_filmstrip_right).css({ display: slideshow_filmstrip_angle_display_value });
4148          jQuery(slideshow_filmstrip_right_disabled).css({ display: 'none' });
4149        }
4150      }, 510);
4151    }
4152  }
4153  else {
4154    if ( params['width_or_height'] == 'width' ) { /* For top, width */
4155      if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top >= -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).width() - jQuery(slideshow_filmstrip_class_name).width()) ) {
4156        jQuery(slideshow_filmstrip_left).css({ display: slideshow_filmstrip_angle_display_value });
4157        jQuery(slideshow_filmstrip_left_disabled).css({ display: 'none' });
4158        if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top < -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).width() - jQuery(slideshow_filmstrip_class_name).width() - parseInt( params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size ) ) {
4159          jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ top: -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).width() - jQuery(slideshow_filmstrip_class_name).width()) }, 500, 'linear');
4160        }
4161        else {
4162          jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ top: (jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top - parseInt( params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size ) }, 500, 'linear');
4163        }
4164      }
4165      /* Disable right arrow.*/
4166      window.setTimeout(function () {
4167        if ( parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top) == -parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).width() - jQuery(slideshow_filmstrip_class_name).width()) ) {
4168          jQuery(slideshow_filmstrip_right).css({ display: 'none' });
4169          jQuery(slideshow_filmstrip_right_disabled).css({ display: slideshow_filmstrip_angle_display_value });
4170        }
4171        else {
4172          jQuery(slideshow_filmstrip_right).css({ display: slideshow_filmstrip_angle_display_value });
4173          jQuery(slideshow_filmstrip_right_disabled).css({ display: 'none' });
4174        }
4175      }, 510);
4176    }
4177    else { /* For top, height */
4178      if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top >= -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).height() - jQuery(slideshow_filmstrip_class_name).height()) ) {
4179        jQuery(slideshow_filmstrip_left).css({ display: slideshow_filmstrip_angle_display_value });
4180        jQuery(slideshow_filmstrip_left_disabled).css({ display: 'none' });
4181        if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top < -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).height() - jQuery(slideshow_filmstrip_class_name).height() - ( parseInt(params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size )) ) {
4182          jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ top: -(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).height() - jQuery(slideshow_filmstrip_class_name).height()) }, 500, 'linear');
4183        }
4184        else {
4185          jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ top: (jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top - ( parseInt(params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size )) }, 500, 'linear');
4186        }
4187      }
4188      /* Disable right arrow.*/
4189      window.setTimeout(function () {
4190        if ( parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top) == -parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).height() - jQuery(slideshow_filmstrip_class_name).height()) ) {
4191          jQuery(slideshow_filmstrip_right).css({ display: 'none' });
4192          jQuery(slideshow_filmstrip_right_disabled).css({ display: slideshow_filmstrip_angle_display_value });
4193        }
4194        else {
4195          jQuery(slideshow_filmstrip_right).css({ display: slideshow_filmstrip_angle_display_value });
4196          jQuery(slideshow_filmstrip_right_disabled).css({ display: 'none' });
4197        }
4198      }, 510);
4199    }
4200  }
4201  bwg_slideshow_filmstrip_thumb[filmstrip_thumbnail_key]['next_prev_index'] = bwg_slideshow_filmstrip_thumb[filmstrip_thumbnail_key]['next_prev_index'] + 1;
4202}
4203
4204/**
4205 * Slideshow filmstrip prev.
4206 *
4207 * @param args
4208 */
4209function bwg_slideshow_filmstrip_prev( args ) {
4210  var bwg = args['bwg'];
4211  var params = args['params'];
4212  var slideshow_filmstrip_thumbnail_size = bwg_calculate_slideshow_filmstrip_thumbnail_size( {
4213    'bwg': bwg,
4214    'params': params
4215  });
4216  var filmstrip_thumbnail_key = 'bwg_slideshow_filmstrip_thumbnail_' + bwg;
4217  var slideshow_filmstrip_left = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_left_' + bwg;
4218  var slideshow_filmstrip_left_disabled ='#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_left_disabled_' + bwg;
4219  var slideshow_filmstrip_right = '#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_right_' + bwg;
4220  var slideshow_filmstrip_right_disabled ='#bwg_container1_' + bwg + ' #bwg_container2_' + bwg + ' .bwg_slideshow_filmstrip_right_disabled_' + bwg;
4221  var slideshow_filmstrip_angle_display_value = (params['filmstrip_direction'] == 'horizontal') ? 'table-cell' : 'block';
4222
4223  if ( params['left_or_top'] == 'left' ) {
4224    if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left < 0 ) {
4225      jQuery(slideshow_filmstrip_right).css({ display: slideshow_filmstrip_angle_display_value });
4226      jQuery(slideshow_filmstrip_right_disabled).css({ display: 'none' });
4227      if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left > -(params['filmstrip_thumb_margin_hor'] + slideshow_filmstrip_thumbnail_size) ) {
4228        jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ left: 0 }, 500, 'linear');
4229      }
4230      else {
4231        jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ left: (jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left + parseInt( params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size ) }, 500, 'linear');
4232      }
4233    }
4234    /* Disable left arrow.*/
4235    window.setTimeout(function () {
4236      if ( parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().left) == 0 ) {
4237        jQuery(slideshow_filmstrip_left).css({ display: 'none' });
4238        jQuery(slideshow_filmstrip_left_disabled).css({ display: slideshow_filmstrip_angle_display_value });
4239      }
4240      else {
4241        jQuery(slideshow_filmstrip_left).css({ display: slideshow_filmstrip_angle_display_value });
4242        jQuery(slideshow_filmstrip_left_disabled).css({ display: 'none' });
4243      }
4244    }, 510);
4245  }
4246  else {
4247    if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top < 0 ) {
4248      jQuery(slideshow_filmstrip_right).css({ display: slideshow_filmstrip_angle_display_value });
4249      jQuery(slideshow_filmstrip_right_disabled).css({ display: 'none' });
4250      if ( jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top > -(params['filmstrip_thumb_margin_hor'] + slideshow_filmstrip_thumbnail_size) ) {
4251        jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ top: 0 }, 500, 'linear');
4252      }
4253      else {
4254        jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).animate({ top: (jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top + parseInt(params['filmstrip_thumb_margin_hor']) + slideshow_filmstrip_thumbnail_size) }, 500, 'linear');
4255      }
4256    }
4257    /* Disable top arrow.*/
4258    window.setTimeout(function () {
4259      if ( parseInt(jQuery(".bwg_slideshow_filmstrip_thumbnails_" + bwg).position().top) == 0 ) {
4260        jQuery(slideshow_filmstrip_left).css({ display: 'none' });
4261        jQuery(slideshow_filmstrip_left_disabled).css({ display: slideshow_filmstrip_angle_display_value });
4262      }
4263      else {
4264        jQuery(slideshow_filmstrip_left).css({ display: slideshow_filmstrip_angle_display_value });
4265        jQuery(slideshow_filmstrip_left_disabled).css({ display: 'none' });
4266      }
4267    }, 510);
4268  }
4269  bwg_slideshow_filmstrip_thumb[filmstrip_thumbnail_key]['next_prev_index'] = bwg_slideshow_filmstrip_thumb[filmstrip_thumbnail_key]['next_prev_index'] - 1;
4270}

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.