PageSourceSearch

https://www.pathein-u.edu.mm/wp-content/plugins/gallery-by-supsyst…/Galleries/assets/js/frontend.js?ver=1.14.9

js pathein-u.edu.mm collected 2026-10-09 17:10:30 UTC 106,525 bytes, 2,871 lines download raw bytes

1(function ($, undefined) {
2
3	// unknown reason for load this method
4	//function loadScript() {
5	//	if (typeof(YT) == 'undefined' || typeof(YT.Player) == 'undefined') {
6	//		var tag = document.createElement('script');
7	//		//tag.src = "https://www.youtube.com/iframe_api";
8	//		tag.src = "//www.youtube.com/iframe_api";
9	//		var firstScriptTag = document.getElementsByTagName('script')[0];
10	//		firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
11	//	}
12	//}
13	//loadScript();
14
15	var init = false;
16
17    function Gallery(selector, autoInit) {
18
19        autoInit = autoInit || false;
20        var $deferred = jQuery.Deferred(),
21			self = this;
22        this.loadedFonts = [];
23
24        this.$container  = $(selector);
25        if(window.sggIsMobile) {
26            this.$container.attr('data-is-mobile', window.sggIsMobile[0]);
27        }
28        this.$container.addClass('fitvidsignore');
29        this.$elements   = this.$container.find('figure.grid-gallery-caption').fadeIn();
30        this.initialMargin = this.$elements.first().css('margin-bottom');
31        this.$navigation = this.$container.find('nav.grid-gallery-nav');
32
33        this.selectedCategory="";
34
35        this.$qsData = null;
36        this.$qsDuration = '750';
37        this.$qsEnable = false;
38        this.areaPosition = this.$container.data('area-position');	// I think we wil need this in future
39
40        this.pagination = {
41            currentPage: 1,
42            limit: 0,
43            total: this.$elements.length,
44            pages: 1,
45            $wrapper: this.$container.find('.grid-gallery-pagination-wrap')
46        };
47
48        this.loadingText = this.$container.data('show-more-loading-text');
49
50        this.popupTranslates = this.$container.data('popup-i18n-words');
51		if(this.$container.data('exif-as-popup') == 1) {
52			this.popupTitleAttribute = 'data-exif-text';
53		} else {
54			this.popupTitleAttribute = this.$container.data('popup-image-text');
55		}
56        this.popupMaxHeight = '90%';
57        this.popupMaxWidth = '90%';
58        this.popup_opened_image = false;
59        this.popupImageDimension = function(){};
60        this.resizeColorbox = function(){};
61
62        this.socialSharing = this.$container.data('social-sharing');
63        this.socialSharingWrapperClass = 'supsystic-grid-gallery-image-sharing';
64        this.socialSharingImageOperators = {
65            'pinterest': 'media',
66        };
67        this.socialButtonsUrl = window.location.href.replace(window.location.hash,'');
68        this.socialButtonsUrl = this.removePopUpHashFromUrl(this.socialButtonsUrl);
69        if(this.socialButtonsUrl.indexOf('#') + 1 == this.socialButtonsUrl.length){
70            this.socialButtonsUrl = this.socialButtonsUrl.substr(0,this.socialButtonsUrl.length-1);
71        }
72
73		this.disablePopupHistory = !!this.$container.data('popup-disable-history');
74
75        if (this.isFluidHeight()) {
76            this.$elements.addClass('wookmarked');
77        }
78
79        $(document).trigger("GalleryExtend", this);
80
81        if (autoInit) {
82			// Interval check for init gallery when container becomes visible.
83			// This need to properly load gallery from tabs, accordions or any other hidden containers.
84			self.$container.data('isVisible', setInterval(function() {
85				if (self.$container.is(':visible') || self.$container.hasClass('hidden-item')) {
86					clearInterval(self.$container.data('isVisible'));
87					self.init();
88				}
89			}, 500));
90        }
91
92		//Add init flag
93        this.$container.addClass('initialized');
94        return $deferred.resolve();
95    }
96
97    Gallery.prototype.isFluidHeight = (function () {
98        return this.$container.is('.grid-gallery-fluid-height');
99    });
100
101    Gallery.prototype.isImageOverlay = (function () {
102        return this.$container.find('.crop').is('.image-overlay');
103    });
104
105    Gallery.prototype.isMouseShadowShow = (function () {
106        return this.$container.find('.grid-gallery-caption').is('.shadow-show');
107    });
108
109    Gallery.prototype.initQuicksand = (function () {
110        if(this.$container.data('quicksand') == 'enabled' && this.$container.data('caption-builder-icons') !== 1)  {
111            this.$qsEnable = true;
112            this.$qsDuration = this.$container.data('quicksand-duration');
113            this.$qsHolder = this.$container.find('.grid-gallery-photos:first');
114            this.$qsData = this.$container.find('.grid-gallery-photos > a');
115        }
116    });
117
118    Gallery.prototype.showCaption = (function () {
119		var isExifCaption = this.$container.data('exif-as-caption');
120        this.$container.find('.grid-gallery-figcaption-wrap').each(function() {
121            if ($.trim($(this).html()) === '' && !$(this).find('img').length && $(this).has('.hi-icon').length === 0) {
122                $(this).closest('figcaption').remove();
123            }
124        });
125
126        this.$container.find('.gg-image-caption').each(function() {
127			var $this = $(this)
128			,	captionHtmlEntry = '';
129			if(isExifCaption == 1) {
130				var $objExist = $this.find('object');
131				if($objExist.length) {
132					captionHtmlEntry = $this.find('object').html().replace(/<a(.*?)>(.*?)<\/a>/gi,"<object type='none'>$&</object>");
133				} else {
134					captionHtmlEntry = $this.html();
135				}
136
137			} else {
138				captionHtmlEntry = $this.text().replace(/<a(.*?)>(.*?)<\/a>/gi,"<object type='none'>$&</object>");
139			}
140			$this.html(captionHtmlEntry);
141            $this.find('a').on('click', function(event) {
142                event.stopPropagation();
143            });
144        });
145
146        $(document).on('click', '.sliphover-container object a', function(event) {
147             event.stopPropagation();
148        });
149    });
150
151    Gallery.prototype.initWookmark = (function () {
152
153        var self = this,
154			horizontalScroll = this.$container.data('horizontal-scroll'),
155			isMobile = parseInt($anyGallery.attr('data-is-mobile')),
156            width = this.$container.data('width'),
157            offset = 0,
158            outerOffset = 0,
159            spacing,
160            windowWidth = $(window).width(),
161            isFixedColumn = this.$container.data('gridType') == 3;
162		// if responsive mode = 'one by one' and mobile -> run this method
163		if (horizontalScroll && horizontalScroll.enabled) {
164			if(horizontalScroll.responsiveMode == 1 && isMobile) {} else {
165				return;
166			}
167		}
168		// not for Mosaic Gallery
169		if(this.$container.data('gridType') == 4) {
170			return;
171		}
172
173        if (this.$container.data('offset')) {
174            offset = this.$container.data('offset');
175        }
176
177        if (this.$container.data('padding')) {
178            outerOffset = parseInt(this.$container.data('padding'));
179        }
180
181        if (String(width).indexOf('%') > -1) {
182            var imagesPerRow = Math.floor(100 / parseInt(width));
183
184            spacing = (offset * (imagesPerRow - 1)) + outerOffset * 2;
185            width = (this.$container.width() - spacing) / 100 * parseInt(width);
186
187            $.each(this.$container.find('img'), function() {
188                aspectRatio = $(this).width() / $(this).height();
189                $(this).width(width);
190                $(this).height(width / aspectRatio);
191            });
192        }
193
194        if(isFixedColumn) {
195            var defaultWidth = parseInt(width),
196                defaultHeight = parseInt(this.$container.data('height')),
197                koefWidthHeigth = defaultWidth > 0 && defaultHeight > 0 ? defaultHeight/defaultWidth : 1;
198        }
199
200        function resizeColumns() {
201            var columnsNumber = self.getResponsiveColumnsNumber();
202
203            spacing = (offset * (columnsNumber - 1)) + outerOffset * 2;
204            width = Math.floor((self.$container.width() - spacing) / 100 * (100 / columnsNumber));
205
206            $.each(self.$elements, function(index, el) {
207
208                var $el = $(el),
209                    $img = $el.find('img');
210                if($img.length && !$el.hasClass('initialized')) {
211                    var imageOriginalSize = self.getOriginalImageSizes($img.get(0)),
212                        elWidth = imageOriginalSize.width,
213                        elHeight = imageOriginalSize.height,
214                        aspectRatio = elWidth / elHeight,
215                        height = width / aspectRatio;
216
217                    if(isFixedColumn && $img.attr('data-gg-remote-image') == 1) {
218                        height = width * koefWidthHeigth;
219                    }
220
221                    $el.css({
222                        width: width,
223                        height: height,
224                    });
225                    if(!$img.hasClass('ggLazyImg')) {
226                        $img.removeClass('ggNotInitImg');
227                        self.polaroidCaptionCalculate($el);
228                        if($el.hasClass('initialized')) {
229                            setTimeout(function() {
230                                $el.trigger('refreshWookmark');
231                            }, 350);
232                        }
233                    }
234                }
235            });
236            self.$container.find('.grid-gallery-photos').removeAttr('data-min-height');
237            return width;
238        }
239
240
241        if (this.$container.data('columns-number')) {
242
243            self.$container.find('figure:not(.initialized) img').css({
244                maxWidth: '100%',
245                width: '100%',
246                height: 'auto'
247            });
248
249            resizeColumns();
250        }
251
252        if (this.$container.data('width') !== 'auto' && !this.$qsEnable) {
253
254
255            this.wookmark = this.$elements.filter(':visible').wookmark({
256                autoResize:     true,
257                container:      this.$container.find('.grid-gallery-photos'),
258                direction:      this.areaPosition == 'right' ? 'right' : 'left',
259                fillEmptySpace: false,
260                flexibleWidth:  !this.$container.data('columns-number'),
261                itemWidth:      width,
262                offset:         offset,
263                align:          this.areaPosition,
264                outerOffset:    outerOffset,
265                onLayoutChanged: function() {
266                    setTimeout(function() {
267                        self.$container.trigger('wookmark.changed');
268                    }, 50);
269                },
270                onResize: function() {
271                    if ($(window).width() != windowWidth) { // Fix touchscreen resize event issue see #544
272                        windowWidth = $(window).width();
273
274                        clearTimeout(self.$container.data('resize.timer'));
275                        self.$container.data('resize.timer', setTimeout(function() {
276
277                            var overflow = self.$container.css('overflow');
278
279                            self.$container.removeData('resize.timer');
280                            self.$container.css('overflow', 'hidden');
281
282                            if (self.$container.data('columns-number')) {
283                                self.$elements.wookmark({
284                                    container: self.$container.find('.grid-gallery-photos'),
285                                    itemWidth: resizeColumns(),
286                                    offset: offset,
287                                });
288                            }
289
290                            self.$elements.last().one('transitionend webkitTransitionEnd oTransitionEnd', function() {
291                                self.$elements.filter(':visible').trigger('refreshWookmark');
292                            });
293                            self.$elements.filter(':visible').trigger('refreshWookmark');
294                            self.$container.css('overflow', overflow);
295                        }, 250));
296                    }
297                }
298            }).css({
299                'margin': '0',
300                'transition': 'all 0.4s linear',
301            });
302        }
303
304        this.$container.find('.grid-gallery-photos').css('text-align', this.$container.data('area-position'));
305		var minheight = this.$container.find('.grid-gallery-photos').data('min-height');
306		this.$container.find('.grid-gallery-photos').css({
307			'min-height': minheight,
308		});
309        this.$container.filter(':visible').find('.grid-gallery-photos > *').filter(':visible').css({
310            'float': 'none',
311            'display': 'inline-block',
312            'vertical-align': 'top'
313        });
314    });
315
316    Gallery.prototype.initControll = (function (){
317        $(document).on('click', "#cboxRight", function() {
318            $.colorbox.prev();
319        });
320        $(document).on('click', "#cboxLeft", function() {
321            $.colorbox.next();
322        });
323    });
324
325    Gallery.prototype.getPopupDimensions = (function(width, height){
326        var width = $(window).width() < width ? '90%' : width;
327        var height = $(window).height() < height ? '90%' : height;
328
329
330        if(width == '90%') { width = parseFloat(($(window).width() * parseFloat(width) / 100)); }
331        if(height == '90%') { height = parseFloat(($(window).height() * parseFloat(height) / 100));}
332
333        return {
334            width: width,
335            height: height
336        };
337    });
338
339    /**
340     * Get popup title depending on gallery settings
341     * @return string title for popup image
342     */
343    Gallery.prototype.getPopupTitle = (function($element){
344
345        var title,
346            $img;
347
348        if ($element.hasClass('hi-icon')) {
349            $img = $element.closest('.grid-gallery-caption').find('img')
350        } else {
351            $img = $element.find('img');
352        }
353
354        title = $img.attr(this.popupTitleAttribute);
355
356        if (!title) {
357            title = $img.attr('title');
358        }
359
360        return title;
361    });
362
363    Gallery.prototype.initPopup = (function() {
364        var popupType = this.popupType = this.$container.data('popup-type'),
365            popupMaxWidth = this.popupMaxWidth,
366            popupMaxHeight = this.popupMaxHeight,
367            sW = this.$container.data('popup-widthsize'),
368            sH = this.$container.data('popup-heightsize'),
369            popupOverlayTransper = this.$container.data('popup-transparency'),
370            popupBackground = this.$container.data('popup-background'),
371            slidePlay = this.$container.data('popup-slideshow') === true,
372            slidePlayAuto = slidePlay && this.$container.data('popup-slideshow-auto') === true,
373            popupHoverStop = slidePlay && this.$container.data('popup-hoverstop') === true,
374            slideshowSpeed = this.$container.data('popup-slideshow-speed'),
375			popupPlacementType = this.$container.data('popup-placement-type'),
376			isLazyLoad = this.$container.data('lazyload-enable') == '1',
377            self = this;
378
379        function generateOverlayColor(selector, background, opacity, optype) {
380            var style = selector + '{',
381                rgb = self.hex2rgb(background);
382            opacity = (100 - opacity) / 100;
383
384            if (background) {
385                color = 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ', '+ opacity + ')';
386                style += 'background-image:none!important; background-color:' + color + '!important;';
387            } else {
388                if(optype){
389                    style += 'opacity:' + opacity + '!important;';
390                } else {
391                    rgb = self.hex2rgb(self.rgb2hex($(selector).css('backgroundColor')));
392                    color = 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ', '+ opacity + ')';
393                    style += 'background-image:none!important; background-color:' + color + '!important;';
394                }
395            }
396            style += '}';
397            $('<style type="text/css"> ' + style + '</style>').appendTo("head");
398        }
399
400        if(!!sW && sW !== 'auto'){
401            popupMaxWidth = sW;
402        }else{
403            sW = '90%'
404        }
405        if(!!sH && sH !== 'auto'){
406            popupMaxHeight = sH;
407        }else{
408            sH = '90%';
409        }
410
411        var getImageDimension = function(){
412            return self.getPopupDimensions(sW,sH);
413        };
414
415        var getColorboxImageDimension = function(){
416            var response = self.getPopupDimensions(sW,sH);
417            if($(self.popup_opened_image).children('figure').attr('data-linked-images')
418                ||
419                $(self.popup_opened_image).hasClass('linked-element')
420            ){
421                response.width-=120;
422            }
423            return response;
424        };
425
426        var delayResize = (function(){
427            var timer = 0;
428            return function(callback, ms){
429                clearTimeout (timer);
430                timer = setTimeout(callback, ms);
431            };
432        })();
433
434        this.resizeColorbox = function(){
435            if(self.popup_opened_image === false) return;
436            var dimensions = getColorboxImageDimension();
437            if(self.popup_opened_image.attr && self.popup_opened_image.attr('rel') == 'video' && (dimensions.width >= 0.9*window.innerWidth)) {
438                return;
439            }
440
441            $(self.popup_opened_image).data('colorbox').maxWidth = dimensions.width;
442            $(self.popup_opened_image).data('colorbox').maxHeight = dimensions.height;
443
444            $(document).trigger("beforeResizeColorBoxResponsive", this);
445            delayResize(function(){
446                $.colorbox.resizeResponsive(self.popup_opened_image);
447            }, 500);
448        };
449
450        //Responsive popup if width or height > window.width
451        popupMaxWidth = $(window).width() < popupMaxWidth ? '90%' : popupMaxWidth;
452        popupMaxHeight = $(window).height() < popupMaxHeight ? '90%' : popupMaxHeight;
453
454        this.popupMaxWidth = popupMaxWidth;
455        this.popupMaxHeight = popupMaxHeight;
456        this.popupImageDimension = getImageDimension;
457
458        if (popupType && popupType !== 'disable') {
459            this.$container.parentsUntil('body').each(function() {
460                var events = $._data(this, "events"),
461                    el = this;
462
463                if (events && events.click) {
464                    $.each(events.click, function(index, ev) {
465                       if (ev.selector && self.$container.has($(ev.selector)).length) {
466                            $(el).off('click', ev.selector);
467                       }
468                    });
469                }
470            });
471        }
472
473		var hideLongTooltipTitles = this.$container.data('hide-long-tltp-title');
474
475        //===========|Popup gallery scripts|===========//
476        if(popupType == 'colorbox') {
477            var $this = this.$container;
478			// simple selector
479			var colorBoxItemSelector = '.grid-gallery-photos > .gg-colorbox:visible,'
480				// mosaic selector
481				+ ' .grid-gallery-photos .gg-mosaic-wrapper .gg-colorbox,'
482				// icon selector
483				+ ' .hi-icon.gg-colorbox:visible';
484            // for popup "Display only first image"
485            if($this.hasClass('one-photo') || $this.hasClass('hidden-item')) {
486                colorBoxItemSelector = '.grid-gallery-photos > .gg-colorbox, .hi-icon.gg-colorbox';
487            }
488
489            if(this.initColorbox) {
490				this.$container.find(colorBoxItemSelector).colorbox.remove('#'+this.$container.attr('id'));
491            } else {
492
493				if(hideLongTooltipTitles == 0) {
494					var $colorboxtooltip = $('<div id="sggCboxTooltip">');
495					$(document).on({
496						mouseenter: function () {
497							$colorboxtooltip.addClass('active');
498						},
499						mouseleave: function () {
500							setTimeout(function() {
501								$colorboxtooltip.removeClass('active');
502							}, 400);
503						}
504					}, '#colorbox.' + $this.data('popup-theme') + ' #cboxTitle');
505
506					$(document).one('cbox_complete', function(event){
507						if (!$('#sggCboxTooltip').length) {
508							$("#cboxWrapper").append($colorboxtooltip);
509						}
510					});
511
512					$(document).on('cbox_complete', function(event) {
513						$colorboxtooltip.html($("#cboxTitle").html());
514                        if($('#colorbox').width() < 300) {
515                            $('#colorbox').filter('.theme_1').find('#cboxSlideshow').css('bottom', '30px');
516                        }
517					});
518				}
519			}
520
521            this.initColorbox = true;
522            var colorBoxConfig = {
523				fadeOut: this.$container.data('popup-fadeOut'),
524				fixed:  true,
525				maxHeight: getImageDimension().height,
526				maxWidth: getImageDimension().width,
527				scalePhotos: true,
528				scrolling: false,
529				returnFocus: false,
530				slideshow: slidePlay && this.$container.data('popup-slideshow-speed'),
531				slideshowAuto: slidePlayAuto,
532				slideshowSpeed: slideshowSpeed,
533				rel: this.$container.attr('id'),
534				slideshowStart: self.popupTranslates.start_slideshow,
535				slideshowStop: self.popupTranslates.stop_slideshow,
536				current: self.popupTranslates.image + " {current} " + self.popupTranslates.of + " {total}",
537				previous: self.popupTranslates.previous,
538				next: self.popupTranslates.next,
539				close: self.popupTranslates.close,
540                'isDisableRightClick': this.$container.attr('data-disable-right-click') == 'true',
541				title: function() {
542					return self.getPopupTitle($(this));
543				},
544				speed: 350,
545				transition: 'elastic',
546				onComplete: function(e) {
547					self.changePopUpHash($(e.el).attr('id') || $(e.el).attr('data-id'));
548					self.addSocialShareToPopUp($(e.el), $('#cboxContent'), 'popup');
549					self.$container.find('.grid-gallery-photos > .gg-colorbox, .hi-icon.gg-colorbox')
550						.colorbox.resize();
551					$("#cboxLoadedContent").append("<div id='cboxRight'></div><div id='cboxLeft'></div>");
552				},
553				onLoad: function(e){
554					if(self.popup_opened_image == e.el) return;
555					self.popup_opened_image = e.el;
556                    var dimensions = getColorboxImageDimension();
557                    $(self.popup_opened_image).data('colorbox').maxWidth = dimensions.width;
558                    $(self.popup_opened_image).data('colorbox').maxHeight = dimensions.height;
559				},
560				onOpen: function(e) {
561					//Enable/Disable stop slideshow on mouse hover
562					if(popupHoverStop){
563						var timeoutId = 0;
564						$('#cboxContent').hover(function(){
565							clearTimeout(timeoutId);
566							$('.cboxSlideshow_on #cboxSlideshow').click();
567						},function(){
568							if(slidePlayAuto) {
569								clearTimeout(timeoutId);
570								timeoutId = setTimeout(function(){
571									$('.cboxSlideshow_off #cboxSlideshow').click();
572								},slideshowSpeed);
573							}
574						})
575					}
576				},
577				onClosed: function(){
578					self.popup_opened_image = false;
579					self.clearPopUpHash();
580				}
581			};
582
583			if(popupPlacementType == 1 || popupPlacementType == 2) {
584				colorBoxConfig['maxWidth'] = '100%';
585				colorBoxConfig['imgPlaceType'] = popupPlacementType;
586			}
587            this.$container.find(colorBoxItemSelector).off('click').colorbox(colorBoxConfig);
588
589
590
591            $(window).resize(function(){
592                self.resizeColorbox();
593            });
594
595            $('#cboxOverlay').removeClass().addClass($this.data('popup-theme')+'-overlay');
596            $('#colorbox').removeClass().addClass($this.data('popup-theme'));
597
598
599            generateOverlayColor('#cboxOverlay', popupBackground, popupOverlayTransper, true);
600        }
601
602        if(popupType == 'pretty-photo') {
603			// simple selector
604			var prettyPhotoItemSelector = '.grid-gallery-photos > a[data-rel^="prettyPhoto"]:visible,'
605				+ ' .grid-gallery-photos .gg-mosaic-wrapper a[data-rel^="prettyPhoto"],'	// mosaic selector
606				+ ' .grid-gallery-photos .hi-icon-wrap > a[data-rel^="prettyPhoto"]:visible';		// icon selector
607			// for popup "Display only first image"
608			if(this.$container.hasClass('one-photo') || this.$container.hasClass('hidden-item')) {
609				prettyPhotoItemSelector = '.grid-gallery-photos > a[data-rel^="prettyPhoto"],'
610					+ ' .grid-gallery-photos .gg-mosaic-wrapper a[data-rel^="prettyPhoto"],'	// mosaic selector
611					+ ' .grid-gallery-photos .hi-icon-wrap > a[data-rel^="prettyPhoto"]';		// icon selector
612			}
613
614            if(!this.$prettyPhoto) {
615				if(hideLongTooltipTitles == 0) {
616					var $prettyPhotoTooltip = $('<div id="sggPrettyPhototooltip">');
617					$(document).on({
618						mouseenter: function () {
619							$prettyPhotoTooltip.addClass('active');
620						},
621						mouseleave: function () {
622							setTimeout(function () {
623								$prettyPhotoTooltip.removeClass('active');
624							}, 400);
625						}
626					}, '.pp_content_container .pp_description');
627				}
628
629                if(this.$container.attr('data-show-buttonlink-in-popup') == 1 && window.prettyPhotoDetailLink) {
630                   this.loadButtonsFontFamily(this.$container.attr('data-buttonlink-font'), null);
631                }
632
633				this.$prettyPhoto = this.$container
634					.find(prettyPhotoItemSelector)
635                    .off('click')
636                    .ggPrettyPhoto({
637                        hook: 'data-rel',
638                        theme: 'light_square',
639                        allow_resize: true,
640                        allow_expand: true,
641                        deeplinking: false,
642                        slideshow:  slidePlay && this.$container.data('popup-slideshow-speed'),
643                        autoplay_slideshow: slidePlayAuto,
644                        social_tools: '',
645                        default_width: popupMaxWidth,
646                        default_height: popupMaxHeight,
647                        getImageDimensions : getImageDimension,
648						'is_lazy_load': isLazyLoad,
649						'ppTranslates': self.popupTranslates,
650                        'isDisableRightClick': this.$container.attr('data-disable-right-click') == 'true',
651						'isShowRotateBtn': this.$container.attr('data-show-rotate-btn-in-popup') == 1,
652                        'isShowAttributes': this.$container.attr('data-show-attributes-in-popup') == 1,
653                        'attributesPosition': this.$container.attr('data-attributes-position'),
654                        'attributesWidth': this.$container.attr('data-attributes-width'),
655                        'isShowButtonLink': this.$container.attr('data-show-buttonlink-in-popup') == 1,
656                        'buttonLinkStyle': this.$container.attr('data-buttonlink-style'),
657						'isShowLinkBtn': this.$container.attr('data-show-link-btn-in-popup') == 1,
658						'isShowHovThumbnail': this.$container.attr('data-show-thumb-hov-in-popup') == 1,
659						'galleryId': this.$container.attr('data-gg-id'),
660						'getTitle': function() {},
661						'setImageTitleForPrepare': function($element) {
662							var imgTile = self.getPopupTitle($element);
663							return imgTile;
664						},
665						'popup_border_type': this.$container.attr('data-popup-border-type'),
666						'popup_border_color': this.$container.attr('data-popup-border-color'),
667						'popup_border_width': this.$container.attr('data-popup-border-width'),
668						'popup_border_enable': this.$container.attr('data-popup-border-enable') == 'on',
669                        changepicturecallback: function(element){
670                            self.changePopUpHash(element.attr('id') || element.attr('data-id'));
671                            self.popup_opened_image = element;
672                            $('.pp_description').html(self.getPopupTitle(element)).show();
673                            //add social share buttons if enabled
674                            self.addSocialShareToPopUp(element,$('.pp_hoverContainer'),'popup');
675                            if(!slidePlay){
676                                $('.pp_play').hide();
677                            }
678							// change detail link url
679							if(self.$container.attr('data-show-link-btn-in-popup') == 1 && window.prettyPhotoDetailLink) {
680								window.prettyPhotoDetailLink(element);
681							}
682                            if(self.$container.attr('data-show-attributes-in-popup') == 1 && window.prettyPhotoAttributes)
683                            {
684                                window.prettyPhotoAttributes(element, self.$container);
685                            }
686
687                            //Enable/Disable stop slideshow on mouse hover
688                            if(popupHoverStop){
689                                $('.pp_hoverContainer').hover(function(){
690                                    $('.pp_nav .pp_pause').click();
691                                },function(){
692                                    if(slidePlayAuto) {
693                                    	$('.pp_nav .pp_play').click();
694                                    }
695                                })
696                            }
697                            var $_desc = $('.pp_description'),
698                                desc_height = parseInt($_desc.height()),
699                                desc_line_height = parseInt($_desc.css('font-size'));
700                            if(desc_line_height < desc_height){
701                                $('.pp_content').height($('.pp_fade').outerHeight(true) + $('.pp_details').outerHeight(true));
702                            }
703
704							if(hideLongTooltipTitles == 0) {
705								if (!$('#sggPrettyPhototooltip').length) {
706									$(".pp_content_container .pp_content").append($prettyPhotoTooltip);
707								}
708								$prettyPhotoTooltip.html($(".pp_content_container .pp_description").html());
709							}
710                        },
711                        callback: function(){
712                            self.popup_opened_image = false;
713                            self.clearPopUpHash();
714                        }
715                    });
716                $(window).resize(function(){
717					if(!self.popup_opened_image || !self.$prettyPhoto) return;
718                    //if(self.$prettyPhoto[0].closest('div') != self.popup_opened_image[0].closest('div')) return;
719					self.$prettyPhoto.open(self.popup_opened_image);
720                });
721            } else {
722				this.$prettyPhoto.refresh(this.$container.find(prettyPhotoItemSelector));
723            }
724
725            generateOverlayColor('.pp_overlay', popupBackground, popupOverlayTransper, true);
726        }
727
728        if(popupType == 'photobox') {
729			var photoBoxItemSelector = 'a.pbox:visible'
730			,	photoBoxConfig = null;
731            // for popup "Display only first image"
732            if(this.$container.hasClass('one-photo') || this.$container.hasClass('hidden-item') || this.$container.data('gridType') == '4') {
733                photoBoxItemSelector = 'a.pbox';
734            }
735
736            if (this.initPhotobox) {
737                this.$container.find('.grid-gallery-photos').photobox('destroy');
738            }
739            this.initPhotobox = true;
740			photoBoxConfig = {
741				autoplay: slidePlayAuto,
742                'isDisableRightClick': this.$container.attr('data-disable-right-click') == 'true',
743				thumb: function(link) {
744					if(self.$container.data('caption-buider') == '1' && self.$container.data('caption-builder-icons') == 1) {
745						return link.closest('.grid-gallery-caption').find('img')[0];
746					} else if(self.$container.data('icons')) {
747						return link.closest('.grid-gallery-caption').find('img')[0];
748					}
749					return null;
750				},
751				getTitle: function(el){
752					var nameTitle = self.getPopupTitle($(el));
753					return nameTitle;
754				},
755				beforeShow: function(element){
756					self.changePopUpHash($(element).attr('id') || $(element).attr('data-id'));
757					self.addSocialShareToPopUp($(element),$('#pbCaption'),'photobox',true);
758				},
759				afterClose: function(){
760					self.clearPopUpHash();
761				}
762			};
763			if(isLazyLoad) {
764				photoBoxConfig['thumbAttr'] = 'data-gg-real-image-href';
765			}
766
767			this.$container.find('.grid-gallery-photos').off('click').photobox(photoBoxItemSelector, photoBoxConfig);
768
769            //Hide autoplay button when slideshow = false
770            if(!this.$container.data('popup-slideshow')){
771                $("#pbAutoplayBtn").hide();
772            }
773
774            //Enable/Disable stop slideshow on mouse hover
775            if(popupHoverStop){
776                $('.pbWrapper img').hover(function(){
777                    $('#pbOverlay .playing').click();
778                },function(){
779                	if(slidePlayAuto) {
780                    	$('#pbOverlay .play').click();
781                    }
782                })
783            }
784
785            generateOverlayColor('#pbOverlay', popupBackground, popupOverlayTransper);
786        }
787        //===========|Popup gallery scripts|===========//
788    });
789
790    Gallery.prototype.preventImages = (function() {
791        var popupType = this.$container.data('popup-type');
792
793        if (popupType == 'disable') {
794            this.$container.find('a.gg-link').off('click');
795            this.$container.find('a.gg-link:not([data-type=link])').addClass('disabled');
796            this.$container.on('click', 'a.gg-link', function(event) {
797                if ($(this).data('type') !== 'link') {
798                    event.preventDefault();
799                    event.stopPropagation();
800                }
801            });
802        }
803    });
804
805    Gallery.prototype.getResponsiveColumnsNumber = function() {
806        var columnsData = this.$container.data('responsive-colums'),
807            settings = [],
808            columnsNumber = parseInt(this.$container.data('columns-number'));
809
810        for (var key in columnsData) {
811            settings.push(columnsData[key]);
812        }
813
814        settings.sort(function(a, b) {
815            a.width = Number(a.width);
816            b.width = Number(b.width);
817            if (a.width > b.width) {
818                return 1;
819            } else if (a.width < b.width) {
820                return -1;
821            } else {
822                return 0;
823            }
824        });
825
826        for (var i = 0,
827                 len = settings.length,
828                 windowWidth = $(window).width(),
829                 minBreakpoint = 0; i < len; i++) {
830            if (windowWidth > minBreakpoint && windowWidth <= settings[i].width) {
831                columnsNumber = Number(settings[i].columns);
832                break;
833            }
834            minBreakpoint = settings[i].width;
835        };
836
837        return columnsNumber;
838    };
839
840    Gallery.prototype.initRowsMode = function() {
841        var columnsNumber = parseInt(this.$container.data('columns-number'));
842
843        if (this.$container.data('horizontal-scroll')) {
844            return;
845        }
846
847        if (typeof this.$container.data('responsive-colums') == 'object') {
848            columnsNumber = this.getResponsiveColumnsNumber();
849        }
850
851        if (columnsNumber) {
852            var containerWidth = parseInt(this.$container.width()),
853                spacing = parseInt(this.$container.data('offset')),
854                scaleHeight = parseInt(this.$container.data('width')) / parseInt(this.$container.data('height')),
855                elementWidth = null,
856                elementHeight = null;
857
858            elementWidth = Math.floor((this.$container.width() - (columnsNumber - 1) * spacing) / columnsNumber);
859            elementHeight = Math.floor(elementWidth / scaleHeight);
860
861            this.$elements.each(function() {
862                var $this = $(this);
863                if (!$this.find('.post-feed-crop').length) {
864                        $this.css('width', elementWidth);
865                    if (!isNaN(elementHeight)) {
866                        $this.css('height', elementHeight);
867                    } else {
868                        $this.css('height', 'auto');
869                    }
870                } else {
871                    $this.find('figcaption').css('width', elementWidth);
872                }
873            });
874
875            this.$elements.find('.crop').css({
876                width: 'auto',
877                height: 'auto'
878            });
879        }
880    };
881
882    Gallery.prototype.setImagesHeight = (function () {
883        var $images = this.$container.find('img');
884
885        if ($images != undefined && $images.length > 0) {
886            $images.each(function () {
887                var $image = $(this),
888                    $wrapper = $image.parent();
889
890                if ($image.height() < $wrapper.height()) {
891                    $wrapper.css('height', $image.height());
892                }
893            });
894        }
895    });
896
897    Gallery.prototype.setOverlayTransparency = (function () {
898        this.$elements.find('figcaption, [class*="caption-with-icons"]').each(function () {
899            var $caption = $(this),
900                alpha    = (10 - parseInt($caption.data('alpha'), 10)) / 10,
901                rgb      = $caption.css('background-color'),
902                rgba     = rgb.replace(')', ', ' + alpha + ')').replace('rgb', 'rgba');
903
904
905            $caption.css('background', rgba);
906        });
907    });
908
909    Gallery.prototype.setIconsPosition = (function () {
910		var self = this;
911        this.$elements.each(function () {
912            var $element = $(this),
913				isCaptionBuilderUsed = self.$container.data('caption-buider'),
914                $wrapper = $element.find('div.hi-icon-wrap'),
915                $icons   = $element.find('a.hi-icon');
916
917            $icons.each(function () {
918                var $icon   = $(this),
919                    marginData = {},
920                    marginY = ($element.height() / 2) - ($icon.height() / 2) - 10,
921                    marginX = $wrapper.data('margin');
922
923                if(marginX && !isCaptionBuilderUsed) {
924                    marginData['margin-left'] = marginX;
925                    marginData['margin-right'] = marginX;
926                }
927                if(marginY && !isCaptionBuilderUsed) {
928                    marginData['margin-top'] = Math.abs(marginY);
929                }
930                $icon.css(marginData);
931            });
932        });
933    });
934
935    Gallery.prototype.initCategories = (function () {
936        var $defaultElement = this.$navigation.find('a[data-tag="__all__"]'),
937            $elements = this.$navigation.find('a'),
938            $defaultBackground = $elements.first().css('background-color');
939
940        function shadeColor(color, percent) {
941            var f=parseInt(color.slice(1),16),t=percent<0?0:255,p=percent<0?percent*-1:percent,R=f>>16,G=f>>8&0x00FF,B=f&0x0000FF;
942            return "#" + (0x1000000+(Math.round((t-R)*p)+R)*0x10000+(Math.round((t-G)*p)+G)*0x100+(Math.round((t-B)*p)+B)).toString(16).slice(1);
943        }
944
945        bg = shadeColor('#' + this.rgb2hex($elements.first().css('borderTopColor')), 0.3);
946
947        this.$navigation.find('a').on('click', $.proxy(function (event) {
948            event.preventDefault();
949
950            var $category   = $(event.currentTarget),
951                requested   = String($category.data('tag')),
952                _defaultTag = '__all__',
953                currentGallery = this.$navigation.parent().attr('id');
954
955            $elements.css('background-color', $defaultBackground);
956            $category.css('background-color', bg);
957
958            if (requested == _defaultTag) {
959
960                this.$elements.each(function () {
961                    if ($(this).parent().attr('rel')) {
962                        $(this).parent().attr('rel', 'prettyPhoto['+currentGallery+']');
963                    }
964                }).fadeIn();
965
966                this.correctMargin();
967                this.initWookmark();
968
969                if (!this.isFluidHeight() && this.$qsEnable) {
970                    this.callQuicksand(this.$qsHolder, this.$qsData, this.$qsDuration);
971                }
972                return false;
973            }
974
975            if (!this.isFluidHeight() && this.$qsEnable) {
976                var $filteredData = this.$qsData.filter(function () {
977                    var tags = $(this).children().data('tags');
978                    if (typeof tags !== 'undefined') {
979                        tags = tags.split('|');
980                    }
981                    return ($.inArray(requested, tags) > -1);
982                });
983                this.callQuicksand(this.$qsHolder, $filteredData, this.$qsDuration);
984            } else {
985                $hidden = $();
986                $visible = $();
987                this.$elements.each(function () {
988                    var $element = $(this),
989                        tags     = $element.data('tags');
990
991                    if (typeof tags != 'string') {
992                        tags = String(tags);
993                    }
994
995                    if (tags != undefined) {
996                        tags = tags.split('|');
997                    }
998                    if ($.inArray(requested, tags) > -1) {
999                        if ($element.parent().attr('rel')) {
1000                            $element.parent().attr('rel', 'prettyPhoto['+currentGallery+'-'+requested+']');
1001                        }
1002                        $visible.push(this);
1003                    } else {
1004                        $hidden.push(this);
1005                    }
1006                });
1007
1008                $.when($hidden.fadeOut()).done($.proxy(function(){
1009                    $visible.fadeIn().css({'height':''});
1010                    this.correctMargin();
1011                    this.initWookmark();
1012                }, this));
1013            }
1014
1015        }, this));
1016
1017        var firstTag = $elements.first().data('tag');
1018        this.$container.find('a[data-tag="'+ firstTag+ '"]').trigger('click');
1019    });
1020
1021    Gallery.prototype.callQuicksand = function($holder, $filteredData, duration) {
1022        self = this;
1023
1024        $filteredData.find('figure.grid-gallery-caption').css('margin', this.initialMargin).parent().css('clear', 'none');
1025
1026        $holder.quicksand($filteredData, {
1027                duration: Number(duration),
1028                easing: 'swing',
1029                attribute: 'href',
1030            }, function() {
1031                $holder.css({
1032                    width: 'auto',
1033                    height: 'auto'
1034                }).append('<div class="grid-gallery-clearfix"></div>');
1035                self.initPopup();
1036                self.correctMargin();
1037				if(self.$container.data('lazyload-enable') == '1') {
1038					// images area removed and filled new images
1039					self.initLazyLoad();
1040				}
1041            }
1042        );
1043    };
1044
1045    Gallery.prototype.hidePopupCaptions = function() {
1046        //never show alternative text for popup theme 6 on top of popup
1047        $('<style type="text/css">.ppt{ display:none!important; }</style>').appendTo("head");
1048        if (this.$container.data('popup-captions') == 'hide') {
1049            $('<style type="text/css">#cboxTitle, #cboxCurrent, .pbCaptionText, .ppt, .pp_description { display:none!important; }</style>').appendTo("head");
1050        }
1051    };
1052
1053    Gallery.prototype.hidePaginationControls = (function () {
1054        return false;
1055    });
1056
1057    Gallery.prototype.setImageOverlay = (function() {
1058        if(this.isImageOverlay()) {
1059            this.$container.find('.grid-gallery-caption').each(function () {
1060                var image = $(this).find('img');
1061                var crop = $(this).find('.image-overlay');
1062                image.css('opacity', '0.2');
1063                crop.css('background-color', '#424242');
1064                $(this).on('mouseenter', function () {
1065                        image.css('opacity', '1.0');
1066                        crop.css('background-color', 'inherit');
1067                    }
1068                );
1069                $(this).on('mouseleave', function () {
1070                    image.css('opacity', '0.2');
1071                    crop.css('background-color', '#424242');
1072                });
1073            });
1074        }
1075    });
1076
1077    Gallery.prototype.setMouseShadow = (function() {
1078        var shadow = null,
1079            $selector = null,
1080            $captions = this.$container.find('.grid-gallery-caption'),
1081            self = this,
1082            showOver = function(event) {
1083                if (event.type === 'mouseenter') {
1084                    $(this).css('box-shadow', self.mouseOverBoxShadow);
1085                } else {
1086                    $(this).css('box-shadow', 'none');
1087                }
1088            },
1089            hideOver = function(event) {
1090                if (event.type === 'mouseenter') {
1091                    $(this).css('box-shadow', 'none');
1092                } else {
1093                    $(this).css('box-shadow', self.mouseOverBoxShadow);
1094                }
1095            };
1096        // only first Init elem has correct value
1097        if(!self.mouseOverBoxShadow) {
1098			self.mouseOverBoxShadow = $captions.filter(':first').css('box-shadow');
1099        }
1100
1101        if ($captions.is('.shadow-show')) {
1102            $captions.css('box-shadow', 'none');
1103            $captions.off('hover').on('hover', showOver);
1104        } else if ($captions.is('.shadow-hide')) {
1105            $captions.off('hover').on('hover', hideOver);
1106        }
1107    });
1108
1109    Gallery.prototype.initPagination = (function () {
1110        var perPage = parseInt(this.$container.find('.grid-gallery-photos').data('per-page'), 10),
1111            buffer  = [],
1112            page    = 1,
1113            offset  = 0
1114        self    = this;
1115
1116        if (isNaN(perPage)) {
1117            this.$elements.fadeIn();
1118            return false;
1119        }
1120
1121        if(this.$container.data('gridType') == 4 && this.$container.data('show-mosaic-all-img') != 1) {
1122            this.$elements.fadeIn();
1123            this.pagination.wrapper.hide();
1124            return false;
1125        }
1126
1127        var showCurrentPage = (function (gallery) {
1128            gallery.$elements.removeClass('current-page').hide(350);
1129
1130            $.each(buffer[gallery.pagination.currentPage], function () {
1131                $(this).addClass('current-page').css({height:gallery.$container.data('height'),width:gallery.$container.data('width')}).show(function () {
1132                    gallery.setIconsPosition();
1133                    self.correctMargin();
1134                });
1135            });
1136            /*
1137             if (!gallery.isFluidHeight()) {
1138             $('.current-page .crop').css('height', function () {
1139             var height = null;
1140             $('.crop img').each(function () {
1141             if($(this).height() && !height) {
1142             height = $(this).height();
1143             }
1144             });
1145             return height;
1146             });
1147             }
1148             */
1149        });
1150
1151        this.pagination.limit = perPage;
1152
1153        this.$elements.each($.proxy(function (index, el) {
1154            var currentIndex = index + 1;
1155
1156            if ((currentIndex - offset) <= this.pagination.limit) {
1157                if (!$.isArray(buffer[page])) {
1158                    buffer[page] = [];
1159                }
1160
1161                buffer[page].push(el);
1162            } else {
1163                offset += this.pagination.limit;
1164                page   += 1;
1165
1166                buffer[page] = [el];
1167            }
1168        }, this)).hide();
1169
1170        this.pagination.pages = Math.ceil(this.pagination.total / this.pagination.limit);
1171
1172        var element=this.pagination.$wrapper.find('a.grid-gallery-page[data-page="1"]');
1173        element.css('font-size','19pt');
1174
1175        this.pagination.$wrapper.find('a.grid-gallery-page').on('click', $.proxy(function (e) {
1176            e.preventDefault();
1177
1178            var element = $(e.currentTarget);
1179            var galery = Gallery.prototype;
1180            this.pagination.$wrapper.find('a.grid-gallery-page').each(function() {
1181                $(this).css('font-size','inherit');
1182            });
1183            galery.selectedCategory = element.data('page');
1184            element.css('font-size','19pt');
1185
1186            var $anchor       = $(e.currentTarget),
1187                requestedPage = $anchor.data('page');
1188
1189            this.pagination.currentPage = requestedPage;
1190
1191            showCurrentPage(this);
1192
1193            return false;
1194        }, this));
1195
1196        showCurrentPage(this);
1197    });
1198
1199    Gallery.prototype.hex=function(x) {
1200        return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
1201    };
1202
1203    Gallery.prototype.rgb2hex = function(rgb) {
1204        if(rgb) {
1205            rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(0\.\d+))?\)$/);
1206            function hex(x) {
1207                return ("0" + parseInt(x).toString(16)).slice(-2);
1208            }
1209            return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
1210        }
1211    };
1212
1213    Gallery.prototype.hex2rgb = function(hex) {
1214
1215        var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
1216        hex = hex.replace(shorthandRegex, function(m, r, g, b) {
1217            return r + r + g + g + b + b;
1218        });
1219
1220        var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
1221        return result ? {
1222            r: parseInt(result[1], 16),
1223            g: parseInt(result[2], 16),
1224            b: parseInt(result[3], 16)
1225        } : null;
1226    };
1227
1228    Gallery.prototype.importFontFamily = (function(familyName) {
1229        var styleId = 'sggFontFamilyStyle',
1230            $style = $('#' + styleId);
1231        if (!$style.length) {
1232            $style = $('<style/>', { id: styleId });
1233            $('head').append($style);
1234        }
1235        familyName = familyName.replace(/\s+/g, '+').replace(/"/g, '');
1236
1237        var obj = document.getElementById(styleId),
1238            sheet = obj.sheet || obj.styleSheet;
1239        if(this.loadedFonts.indexOf(familyName) === -1) {
1240            if(sheet.insertRule) {
1241                sheet.insertRule('@import url("//fonts.googleapis.com/css?family=' + familyName + '"); ', 0);
1242            } else if(sheet.addImport) {
1243                sheet.addImport('//fonts.googleapis.com/css?family=' + familyName);
1244            }
1245            this.loadedFonts.push(familyName);
1246        }
1247    });
1248
1249
1250    Gallery.prototype.loadFontFamily = (function () {
1251        font = this.$container.data('caption-font-family');
1252        if(window && window.sggStandartFontsList && $.inArray(font.replace(/\"/g, ''), window.sggStandartFontsList) != -1) {
1253            return false;
1254        }
1255        if (font && font !== 'Default') {
1256            this.importFontFamily(font);
1257        }
1258    });
1259
1260    Gallery.prototype.initCaptionCalculations = (function () {
1261        var self = this;
1262
1263        this.$container.find('.grid-gallery-caption').each(function () {
1264            wrap = $(this).find('div.grid-gallery-figcaption-wrap');
1265            figcaption = $(this).find('figcaption');
1266
1267            wrap.css({
1268                'display': 'table-cell',
1269                'text-align': figcaption.css('text-align')
1270            });
1271
1272            wrap.wrap($('<div>', {
1273                css: {
1274                    display:'table',
1275                    height:'100%',
1276                    width:'100%'
1277                }
1278            }));
1279        });
1280    });
1281
1282    Gallery.prototype.checkDirection = function($element, e) {
1283        var w = $element.width(),
1284            h = $element.height(),
1285            x = ( e.pageX - $element.offset().left - ( w / 2 )) * ( w > h ? ( h / w ) : 1 ),
1286            y = ( e.pageY - $element.offset().top - ( h / 2 )) * ( h > w ? ( w / h ) : 1 );
1287
1288        return Math.round(( ( ( Math.atan2(y, x) * (180 / Math.PI) ) + 180 ) / 90 ) + 3) % 4;
1289    };
1290
1291    Gallery.prototype.generateOverlayCaptionColor = (function (overlayColor, alpha) {
1292        if(typeof(overlayColor) == 'string'){
1293            overlayColor = overlayColor.split(')');
1294
1295            if(overlayColor.length > 0) {
1296                overlayColor = overlayColor[0].split('(');
1297
1298                if(overlayColor.length > 1) {
1299                    var chanels = overlayColor[1].split(',');
1300
1301                    if(chanels.length == 4) {   // it is already rgba (fix for IE)
1302                        overlayColor[0] = overlayColor[0].replace('a', '');
1303                        chanels.splice(-1,1);
1304                        overlayColor[1] = chanels.join(',');
1305                    }
1306                    return overlayColor[0] + 'a(' + overlayColor[1] + ', ' + (1 - alpha
1306/10) + ')';
1307                }
1308            }
1309        }
1310        return overlayColor;
1311    });
1312
1313    Gallery.prototype.initCaptionEffects = (function () {
1314        var self = this,
1315            allwaysShowCaptionOnMobile = this.$container.data('caption-mobile'),
1316            disableCaptionOnMobile = this.$container.data('caption-disabled-on-mobile'),
1317            isMobile = !!parseInt(this.$container.data('is-mobile'));
1318
1319        if(isMobile && navigator && navigator.userAgent && navigator.userAgent.indexOf("Safari") > -1) {
1320            var $3dCubeCaptions = this.$container.find('.grid-gallery-caption[data-grid-gallery-type="3d-cube"]');
1321            $3dCubeCaptions.attr('data-grid-gallery-type', 'revolving-door-bottom');
1322            $3dCubeCaptions.data('grid-gallery-type', 'revolving-door-bottom');
1323        }
1324
1325        $.each(this.$elements, function(index, el) {
1326            var $el = $(el),
1327                overlayColor = $el.find('figcaption').css('backgroundColor'),
1328                alpha = parseInt($el.find('figcaption').data('alpha'));
1329
1330            if (isMobile && allwaysShowCaptionOnMobile){
1331                $el.attr('data-grid-gallery-type', 'none');
1332            }
1333
1334            if ($el.data('grid-gallery-type') == 'cube') {
1335                $el.on('mouseenter mouseleave', function(e) {
1336                    var $figcaption = $(this).find('figcaption'),
1337                        direction = self.checkDirection($(this), e),
1338                        classHelper = null;
1339
1340                    switch (direction) {
1341                        case 0:
1342                            classHelper = 'cube-' + (e.type == 'mouseenter' ? 'in' : 'out') + '-top';
1343                            break;
1344                        case 1:
1345                            classHelper = 'cube-' + (e.type == 'mouseenter' ? 'in' : 'out') + '-right';
1346                            break;
1347                        case 2:
1348                            classHelper = 'cube-' + (e.type == 'mouseenter' ? 'in' : 'out') + '-bottom';
1349                            break;
1350                        case 3:
1351                            classHelper = 'cube-' + (e.type == 'mouseenter' ? 'in' : 'out') + '-left';
1352                            break;
1353                    }
1354
1355                    $figcaption.removeClass().addClass(classHelper);
1356                });
1357            }
1358
1359            if ($el.data('grid-gallery-type') == 'direction-aware') {
1360                var color = $el.find('figcaption').css('color'),
1361                    isCaptionBuilderUsed = self.$container.data('caption-buider'),
1362					classStr = '',
1363					addAttr = '',
1364                    align = $el.find('figcaption').css('text-align');
1365
1366				if(isCaptionBuilderUsed == 1) {
1367                    $el.attr('data-caption', '<div style="padding:0px; height: ' + $el.height() + 'px; font-family:' +
1368                        self.$container.data('caption-font-family') + '; font-size:' + self.$container.data('caption-text-size') +'">' +
1369                        ($el.find('figcaption').html() || '') + '</div>');
1370				} else {
1371					var $ggImgCaption = $el.find('.gg-image-caption');
1372					if($ggImgCaption.hasClass('ggRtlClass')) {
1373						classStr = 'ggRtlClass';
1374						addAttr = 'dir="rtl"';
1375					}
1376					$el.attr('data-caption', '<div class="' + classStr + '" ' + addAttr + ' style="padding:20px;font-family:' +
1377						self.$container.data('caption-font-family') + '; font-size:' + self.$container.data('caption-text-size') +';">' +
1378						($ggImgCaption.html() || '') + '</div>');
1379                }
1380
1381                $el.sliphover({
1382                    target: $el,
1383                    backgroundColor: self.generateOverlayCaptionColor(overlayColor, alpha),
1384                    fontColor: color,
1385                    textAlign: align,
1386                    caption: 'data-caption'
1387                });
1388
1389            }
1390
1391            if ($el.data('grid-gallery-type') == '3d-cube'){
1392				if(!$el.find('.box-3d-cube-scene').length){
1393					var cubeWidth = $el.width(),
1394						cubeHeight = $el.height();
1395					// $el.addClass('box-3d-cube-scene');
1396					$el.children('div').addClass('front').addClass('face');
1397					$el.children('figcaption').addClass('back').addClass('face');
1398					$el.html('<div class="box-3d-cube-scene"><div class="box-3d-cube">' + $el.html() + '</div></div>');
1399					// $el.html("<div class='box-3d-cube-scene'><div class='box-3d-cube'><div class='front face'><img src='http://placehold.it/"+cubeWidth+"x"+cubeHeight+"/' alt=''></div><div class='back face'><div>This is back</div></div></div></div>");
1400					self.changeImageHeightFor3dCubeEffect($el, cubeWidth, cubeHeight);
1401				}
1402            }
1403
1404            if ($el.data('grid-gallery-type') == 'polaroid') {
1405                self.polaroidCaptionCalculate($el);
1406            } else {
1407                var topRow = $el.find('.gg-caption-row.top'),
1408                   centerRow = $el.find('.gg-caption-row.center');
1409                if(centerRow.length == 1 && topRow.length == 1) {
1410                    centerRow.css({'top': topRow.height(), 'transform': 'initial'});
1411                }
1412            }
1413        });
1414
1415        $(document).on('click', '.sliphover-container', function(event) {
1416            event.preventDefault();
1417            $(this).data('relatedElement').get(0).click();
1418        });
1419
1420
1421        if(isMobile && !disableCaptionOnMobile) {
1422            this.$container.find('.grid-gallery-caption').each(function() {
1423                var caption = this,
1424                    $caption = $(caption),
1425                    hammer = new Hammer_gg(this),
1426					captionIsMobile = self.$container.attr('data-caption-mobile'),
1427					preventClick = false;
1428
1429				$caption.on('click', function(event) {
1430					if (preventClick) {
1431						event.preventDefault();
1432						event.stopPropagation();
1433					}
1434				});
1435
1436                hammer.on("tap panstart", function(event) {
1437
1438                    if (event.type === 'panstart') {
1439                        self.$container.find('.grid-gallery-caption').removeClass('hovered');
1440                    }
1441
1442                    if (event.type === 'tap') {
1443						preventClick = false;
1444                        if (!$caption.hasClass('hovered')) {
1445                            self.$container.find('.grid-gallery-caption').not(caption).removeClass('hovered');
1446							$(caption).addClass('hovered');
1447							if(captionIsMobile == 'false') {
1448								preventClick = true;
1449							}
1450						}
1451
1452                    }
1453                });
1454            });
1455        }
1456
1457        if (isMobile && disableCaptionOnMobile) {
1458			this.$container.find('.grid-gallery-caption figcaption').hide();
1459		}
1460
1461    });
1462
1463    Gallery.prototype.polaroidCaptionCalculate = (function ($el) {
1464        if ($el.data('grid-gallery-type') != 'polaroid' || $(this).find('.post-feed-crop').length || $el.hasClass('initialized')) return;
1465        var $img = $el.find('img');
1466
1467        if($img.hasClass('ggLazyImg') || $img.hasClass('ggNotInitImg')) return;
1468        if($el.closest('.gg-mw-row').hasClass('sggDisplNone')) return;
1469
1470        $el.addClass('initialized');
1471        $img.finish();
1472        var width = $el.width(),
1473            gridType = this.$container.data('gridType'),
1474            frameWidth = parseInt(this.$container.data('polaroid-frame-width'), 10) || 20,
1475            captionHeight = this.$container.data('polaroid-caption-height'),
1476            clearHeight = captionHeight ? parseInt(captionHeight.toString().match(/\d.?\d*.?\d*/)[0]) : 0,
1477            overlayColor = $el.find('figcaption').css('backgroundColor'),
1478            alpha = parseInt($el.find('figcaption').data('alpha')),
1479            $figcaption = $el.find('figcaption'),
1480            scaleRatio = $img.width() / $img.height();
1481        if(gridType == 2) {
1482            var imageHeight = $img.height() - frameWidth * 2,
1483                imageWidth = imageHeight * scaleRatio;
1484        } else {
1485            var imageWidth = $img.width() - frameWidth * 2,
1486                imageHeight = imageWidth / scaleRatio;
1487        }
1488        var figcaptionHeight = !isNaN(clearHeight) && clearHeight != 0 ? (captionHeight.toString().indexOf('%') > 0 ? (imageHeight * clearHeight / 100) : clearHeight) : 0,
1489            figureFullHeight = imageHeight + frameWidth * 2 + figcaptionHeight;
1490
1491        $img.css({
1492            'width': imageWidth + 'px',
1493            'height': imageHeight + 'px',
1494            'margin': frameWidth + 'px auto 0',
1495        });
1496        $el.find('.gg-caption-table').css('height', '1px');
1497
1498        $el.find('.crop').css({
1499            'height': imageHeight + frameWidth + 'px'
1500        });
1501        if(gridType == 0) {
1502            $el.find('.crop').css('overflow', 'visible');
1503        } else if(gridType == 2) {
1504            $el.css({
1505                'height': figureFullHeight + 'px',
1506                'width': imageWidth + frameWidth * 2 + 'px',
1507            });
1508        } else if(gridType == 3) {
1509            $el.css({
1510                'height': figureFullHeight + 'px',
1511            });
1512        }
1513
1514        $el.css({
1515            'background': overlayColor
1516        });
1517        $el.css({
1518            'width': $el.width(),
1519            'background': this.generateOverlayCaptionColor(overlayColor, alpha)
1520        });
1521
1522        $figcaption.css({
1523            'background': 'none',
1524            'transition': 'none',
1525        });
1526        if(figcaptionHeight) {
1527            figcaptionHeight += 'px';
1528            $figcaption.css('height', figcaptionHeight);
1529            $el.find('.gg-caption-row').css({'max-height': figcaptionHeight ? figcaptionHeight : '100%', 'height': 'auto'});
1530            $el.find('.gg-caption-cell').css('height', '100%');
1531            if(gridType == 3) {
1532                $figcaption.css('margin-top', frameWidth + 'px');
1533            }
1534        } else {
1535            $figcaption.css('padding', frameWidth + 'px');
1536        }
1537
1538        if ($figcaption.find('.grid-gallery-figcaption-wrap').text().length === 0) {
1539            $figcaption
1540               .find('.grid-gallery-figcaption-wrap')
1541               .append('<span></span>');
1542        }
1543
1544        if (this.$container.data('polaroid-animation')) {
1545            $el.addClass('polaroid-animation');
1546        }
1547
1548        if (this.$container.data('polaroid-scattering')) {
1549            $el.css({
1550                'transform': 'rotate(' + (-3 + Math.random() * (10 - 3)) + 'deg)'
1551            });
1552            $el.addClass('polaroid-scattering');
1553        }
1554        var slimScroll = $el.closest('div.slimScrollDiv');
1555        if(slimScroll.length) {
1556            var scrollHeight = figureFullHeight + 20 + 'px';
1557            slimScroll.css('height', scrollHeight);
1558            slimScroll.find('.grid-gallery-photos').css('height', scrollHeight);
1559        }
1560    });
1561
1562	Gallery.prototype.changeImageHeightFor3dCubeEffect = (function($figure, cubeWidth, cubeHeight) {
1563		// check params
1564		if(!$figure) {
1565			return;
1566		}
1567		// call this function from PRO script
1568		if(!$figure.length) {
1569			if('figure' in $figure && 'width' in $figure && 'height' in $figure) {
1570				cubeWidth = $figure.width;
1571				cubeHeight = $figure.height;
1572				$figure = $figure.figure;
1573			} else {
1574				return;
1575			}
1576		}
1577
1578		if(!cubeWidth) {
1579			cubeWidth = $figure.width();
1580		}
1581		if(!cubeHeight) {
1582			cubeHeight = $figure.height();
1583		}
1584
1585		var perspective = Math.max(cubeHeight,cubeWidth) * 2 + 'px'
1586		,	transformOrigin = '50% 50% -' + Math.round(cubeHeight/2) + 'px';
1587
1588		$figure.find('.box-3d-cube-scene').css({
1589			'perspective': perspective,
1590			'-webkit-perspective': perspective
1591		});
1592		$figure.find('.box-3d-cube').css({
1593			'transform-origin': transformOrigin,
1594			'-ms-transform-origin': transformOrigin,
1595			'-webkit-transform-origin': transformOrigin,
1596		});
1597		$figure.find('.box-3d-cube, .box-3d-cube .face').css({
1598			width: cubeWidth + 'px',
1599			height: cubeHeight + 'px',
1600		});
1601	});
1602
1603    Gallery.prototype.correctMargin = (function () {
1604		if(this.$container.data('area-position') == 'right') {
1605			return;
1606		}
1607		if(this.$container.data('gridType') == 4) {
1608			return;
1609		}
1610		// if responsive mode = 'one by one' and mobile -> run this method
1611		var horizontalScroll = this.$container.data('horizontal-scroll')
1612		,	isMobile = parseInt($anyGallery.attr('data-is-mobile'))
1613		if(horizontalScroll && horizontalScroll.responsiveMode == 1 && isMobile) {} else {
1614			return;
1615		}
1616		if(!this.isFluidHeight()) {
1617
1618            if (this.$qsEnable) {
1619                this.$elements = this.$container.find('figure.grid-gallery-caption');
1620            };
1621
1622            var prevElement = null
1623                ,	totalElements = this.$elements.filter(':visible').length
1624                ,   rowWidth = 0
1625                ,   maxRowWidth = this.$container.width()
1626                ,   initialMargin = this.initialMargin;
1627
1628            this.$elements.css('margin', this.initialMargin);
1629            this.$elements.parent().css('clear', 'none');
1630
1631            this.$elements.filter(':visible').each(function(index){
1632
1633                if (rowWidth + $(this).outerWidth() > maxRowWidth) {
1634                    $(prevElement).css('margin-right', 0);
1635                    $(this).css('margin-right', this.initialMargin);
1636                    $(this).parent().css('clear', 'left');
1637                    rowWidth = $(this).outerWidth() + parseInt(initialMargin);
1638                } else if (rowWidth + $(this).outerWidth() == maxRowWidth) {
1639                    $(this).css('margin-right', 0);
1640                    rowWidth = 0;
1641                } else {
1642                    rowWidth += $(this).outerWidth() + parseInt(initialMargin);
1643                }
1644
1645                if(index == totalElements - 1) {
1646                    $(this).css('margin-right', 0);
1647                }
1648
1649                prevElement = this;
1650
1651            });
1652        }
1653    });
1654
1655    Gallery.prototype.hideTitleTooltip = (function () {
1656        if(this.$container.data('hide-tooltip') == true) {
1657            title = '';
1658            this.$container.find('a, img, div:not(.grid-gallery-photos)').on('mouseenter', function() {
1659                title = $(this).attr('title');
1660                $(this).attr({'title':' '});
1661            }).mouseout(function() {
1662                $(this).attr({'title':title});
1663            });
1664        };
1665    });
1666
1667    Gallery.prototype.correctFullscreen = (function () {
1668        var windowWidth = $(window).width();
1669        this.$elements.each(function() {
1670            var coef = parseInt(windowWidth / $(this).width())
1671                , resultWidth = Math.round(windowWidth / coef);
1672            $(this).width(resultWidth);
1673        });
1674    });
1675
1676    Gallery.prototype.correctFullScreenWidthGallery = (function(){
1677        var windowWidth = $(window).width(),
1678            $parentContainer = this.$container.parent(),
1679            containerOffset = $parentContainer.offset(),
1680            containerOffsetLeft = containerOffset.left + parseFloat($parentContainer.css('padding-left'));
1681
1682        this.$container.find('.grid-gallery-photos').css({
1683            width: windowWidth
1684        });
1685
1686        var cssDirection = this.$container.css('direction');
1687
1688        if ('ltr' == cssDirection) {
1689            this.$container.css({
1690                width: windowWidth,
1691                left: '-' + containerOffsetLeft + 'px',
1692				//'max-width': '100%'
1693            });
1694            this.$container.find('.grid-gallery-nav').css('width', windowWidth + 'px');
1695        } else {
1696            this.$container.css({
1697                width: windowWidth //, 'max-width': '100%'
1698            }).offset(function(i, coords) {
1699                return {'top' : coords.top, 'left' : 0};
1700            });
1701        }
1702    });
1703
1704    Gallery.prototype.getOriginalImageSizes = function (img) {
1705
1706        var tempImage = new Image(),
1707            width,
1708            height;
1709
1710        if ('naturalWidth' in tempImage && 'naturalHeight' in tempImage) {
1711            width = img.naturalWidth;
1712            height = img.naturalHeight;
1713        } else {
1714            tempImage.src = img.src;
1715            width = tempImage.width;
1716            height = tempImage.height;
1717        }
1718
1719        return {
1720            width: width,
1721            height: height,
1722        };
1723    };
1724
1725    Gallery.prototype.initHorizontalMode = (function () {
1726
1727		var horizontalScroll = this.$container.data('horizontal-scroll')
1728		,	height = this.$container.data('height')
1729		,	width = this.$container.data('width')
1730		,	offset = this.$container.data('offset')
1731		,	isMobile = parseInt($anyGallery.attr('data-is-mobile'))
1732		,	mouseWheelStep = 100
1733		,	touchStep = 100
1734		,	responsiveMode = 0
1735		,	tmpValue = 0
1736		,	self = this;
1737
1738		if(this.$container.data('gridType') == 4) {
1739			return;
1740		}
1741        if (!horizontalScroll) {
1742            return;
1743        }
1744		if(horizontalScroll) {
1745			// if responsive mode = 'one by one' and mobile -> need to disable "responsive mode"
1746			if(horizontalScroll.responsiveMode == 1 && isMobile) {
1747				return;
1748			}
1749			if(horizontalScroll.mouseWheelStep) {
1750				tmpValue = parseInt(horizontalScroll.mouseWheelStep);
1751				if(!isNaN(tmpValue)) {
1752					mouseWheelStep = tmpValue;
1753				}
1754			}
1755			if(horizontalScroll.touchStep) {
1756				tmpValue = parseInt(horizontalScroll.touchStep);
1757				if(!isNaN(tmpValue)) {
1758					touchStep = tmpValue;
1759				}
1760			}
1761		}
1762
1763        //Calculate max-height and margin
1764        if (!height) {
1765            var elementsHeight = this.$container.find('.grid-gallery-caption>a').map(function() {
1766                    return $(this).height();
1767                }).get(),
1768                height = Math.max.apply(null, elementsHeight);
1769        } else {
1770            if(offset && offset > 0){
1771                height = height + offset*2;
1772            }
1773        }
1774
1775        if (width === 'auto') {
1776            this.$elements.each(function(index, el) {
1777                var $figure = $(el),
1778                    $image = $figure.find('img');
1779                    sizes = self.getOriginalImageSizes($image.get(0));
1780                    $image.css('max-width', 'none');
1781                if(!$image.hasClass('ggLazyImg'))
1782                    $figure.width(Math.floor((height / sizes.height) * sizes.width));
1783            });
1784        }
1785
1786        //Fixed IE9 scroll bug
1787        var isIE9OrBelow = function() {
1788            return /MSIE\s/.test(navigator.userAgent) && parseFloat(navigator.appVersion.split("MSIE")[1]) < 10;
1789        }
1790
1791        if(isIE9OrBelow()){
1792            this.$container.find('.grid-gallery-photos > *').css('display','table-cell');
1793        } else {
1794            this.$container.find('.grid-gallery-photos > *').css('display','inline-block');
1795        }
1796
1797        this.$container.find('.grid-gallery-photos > *').css({
1798            margin:0,
1799            padding:0,
1800            float: 'none',
1801            animate: true,
1802            'vertical-align': 'middle',
1803            clear: 'right',
1804            //'margin-right': '-5px',
1805            'border': 'none',
1806            'max-width': 'none',
1807        });
1808
1809        this.$container.find('.grid-gallery-photos').css({
1810            'font-size': 0,
1811        });
1812
1813        this.$container.find('.grid-gallery-photos .grid-gallery-caption').css({
1814            float: 'none',
1815            'margin-left': 0,
1816        });
1817
1818        // https://github.com/lanre-ade/jQuery-slimScroll
1819        height = height + 7; //This is scrollbar height;
1820        var slimScroll = this.$container.find('.grid-gallery-photos').slimScroll({
1821            height: height,
1822            width: 'auto',
1823            railVisible: true,
1824            alwaysVisible: true,
1825            allowPageScroll: true,
1826            axis: 'x',
1827            animate: true,
1828            color: horizontalScroll.color || '#000',
1829            opacity:(100 - horizontalScroll.transparency) * 0.01,
1830			'wheelStep': mouseWheelStep,
1831			'touchScrollStep': touchStep,
1832			'isMobile': isMobile,
1833			'ggSlimscrollHandler': function() {
1834				self.lazyLoadTriggerHandler();
1835			},
1836        });
1837
1838        // Load more height fix
1839        if (slimScroll.height() < height) {
1840            slimScroll.height(height);
1841            slimScroll.parent().height(height);
1842        }
1843
1844    });
1845
1846    Gallery.prototype.initHorizontalGalleryType = (function () {
1847        if (this.$container.data('height') && String(this.$container.data('height')).indexOf('%') > -1) {
1848            var height = this.$elements.first().height();
1849            this.$elements.find('img').css({
1850                'max-height': height,
1851                'min-height': height,
1852            });
1853        }
1854        var self = this;
1855        setTimeout(function() {
1856            self.resizeHorizontalElements();
1857        }, 50);
1858    });
1859
1860    Gallery.prototype.hidePreloader = function() {
1861        var preloadEnab = this.$container.attr('data-preloader'),
1862            preloader = this.$container.find('.gallery-loading'),
1863            galleryPhotos = this.$container.find('.grid-gallery-photos');
1864
1865        preloader.hide();
1866        if(preloadEnab !== '' && preloadEnab === 'true') {
1867			setTimeout(function() {
1868				galleryPhotos.show().fadeTo("slow", 1, function() {
1869					galleryPhotos.css('opacity', '1');
1870				});
1871			}, 0);
1872        } else {
1873            galleryPhotos.show().fadeTo('fast', 1, function() {
1874                galleryPhotos.css('opacity','1');
1875            });
1876        }
1877    };
1878
1879    Gallery.prototype.showGalleryParts = function(){
1880        this.$container.children('.hidden-item').removeClass('hidden-item');
1881    };
1882
1883    Gallery.prototype.$getImagesFigureContainer = function(){
1884        return this.$container.find('figure.grid-gallery-caption');
1885    };
1886
1887    Gallery.prototype.initSocialSharing = function(){
1888        if(!this.socialSharing || !this.socialSharing.enabled){
1889            return;
1890        }
1891        this.initGallerySocialSharing();
1892        this.initImageSocialSharing();
1893    };
1894
1895    Gallery.prototype.initEvent = function($elements){
1896        $elements.find('.supsystic-social-sharing a.social-sharing-button').on('click',function (e) {
1897	        if( !e ) e = window.event;
1898        	e.preventDefault();
1899            e.stopPropagation();
1900            e.stopImmediatePropagation();
1901            $(document).trigger('ssSocialClick', this);
1902            if (e.currentTarget.href.slice(-1) !== '#') {
1903                window.open(e.currentTarget.href, 'mw' + e.timeStamp, 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
1904            }
1905
1906	        var button = $(this)
1907	        ,   figureWrapper = button.closest('.grid-gallery')
1908	        ,   socialHtmlWrapper = figureWrapper.find('#social-share-html')
1909	        // ,   socialHtmlWrapper = figureWrapper.find('.supsystic-social-sharing')
1910	        ,   popupWrapper = socialHtmlWrapper.find('.supsystic-social-sharing-popup');
1911
1912            if(button.hasClass('trigger-popup')){
1913            	if(socialHtmlWrapper.css('display') === 'none'){
1914		            socialHtmlWrapper.find('a').css('display', 'none');
1915		            socialHtmlWrapper.css('display','block');
1916		            popupWrapper.css('display','block');
1917	            }else{
1918		            socialHtmlWrapper.css('display','none');
1919		            popupWrapper.css('display','none');
1920	            }
1921            }
1922            if(button.closest('#pp_full_res').length){
1923	            var buttonOverlayWrapper = button.closest('#pp_full_res')
1924	            ,   buttonPopupWrapper = buttonOverlayWrapper.find('.supsystic-social-sharing-popup');
1925	            if(buttonPopupWrapper.css('display') === 'none'){
1926		            buttonPopupWrapper.css('display','block');
1927	            }else{
1928		            buttonPopupWrapper.css('display','none');
1929	            }
1930            }
1931	        $(document).on('click', function (e) {
1932		        if( !e ) e = window.event;
1933		        if (!$(e.target).is(".supsystic-social-sharing-popup")) {
1934			        socialHtmlWrapper.css('display','none');
1935			        popupWrapper.css('display','none');
1936			        socialHtmlWrapper.find('a').css('display', 'block');
1937		        }
1938	        });
1939        });
1940    };
1941
1942    Gallery.prototype.getSocialButtons = function(wrapper_class, url, img_id, img_src, title, noCounter) {
1943        title = title || '';
1944
1945		var html = this.$container.find('#social-share-html').html();
1946
1947        if (html !== undefined && html.length){
1948            html = html.replace(/{url}/g, url).replace(/{title}/g, title);
1949            if(noCounter) {
1950                // cut counter div
1951                html = html.replace(/<div class="counter-wrap.*?>.*?<\/div>/g, '');
1952            }
1953        }
1954
1955        return $('<div>', {
1956            class: wrapper_class,
1957            'data-img-thumbnail': img_src,
1958            'data-img-id': img_id,
1959            'data-img-title': title,
1960        }).html(html);
1961    };
1962
1963    Gallery.prototype.getSocialButtonsByImage = function(wrapper_class, $element, popup) {
1964
1965        var $img = $element.find('img'),
1966            imgSrc = $element.attr('href'),
1967            title = $element.attr('title'),
1968            $captionContainer = $element.find('.gg-image-caption'),
1969            url = location.href,
1970			imageId = null;
1971
1972		if($element.attr('data-type') == 'link' || $element.attr('data-video-source') == 'youtube') {
1973			if($img.length) {
1974				if($img.attr('data-gg-real-image-href')) {
1975					imgSrc = $img.attr('data-gg-real-image-href');
1976				} else {
1977					imgSrc = $img.attr('src');
1978				}
1979			}
1980		}
1981
1982		if($element && $element.attr('id') && $element.attr('id').split('-').pop()) {
1983			imageId = $element.attr('id').split('-').pop();
1984		}
1985
1986        if ($captionContainer.length) {
1987            var caption = $.trim(
1988                $captionContainer.clone().html($captionContainer.html()
1989                    .replace(/<br\s*[\/]?>/gi, ' '))
1990                    .text()
1991                    .replace(/\s+/, ' ')
1992            );
1993
1994            if (caption.length) {
1995                title = caption;
1996            }
1997        }
1998
1999        if (imgSrc && imgSrc.indexOf('http') !== 0) {
2000            imgSrc = 'http:' + imgSrc;
2001        }
2002
2003        function updateQueryStringParameter(uri, key, value) {
2004            var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
2005            var separator = uri.indexOf('?') !== -1 ? "&" : "?";
2006            if (uri.match(re)) {
2007                return uri.replace(re, '$1' + key + "=" + value + '$2');
2008            } else {
2009                return uri + separator + key + "=" + value;
2010            }
2011        }
2012
2013        if (popup) {
2014            url = url.replace('#!', '?');
2015        }
2016		if(imageId) {
2017			url = updateQueryStringParameter(url, '_gallery', $element.attr('id'));
2018			url = encodeURIComponent(updateQueryStringParameter(url, 'shared-image', imageId));
2019		}
2020
2021        return this.getSocialButtons(wrapper_class, url, $element.attr('id'), imgSrc, title, true);
2022    };
2023
2024    Gallery.prototype.initGallerySocialSharing = function() {
2025
2026        var gallerySharing = this.socialSharing.gallerySharing;
2027
2028        if (!parseInt(gallerySharing.enabled)) {
2029            return;
2030        }
2031
2032        var $socialButtons = this.getSocialButtons(
2033                '',
2034                this.socialButtonsUrl,
2035                '',
2036                '',
2037                this.$container.data('title')
2038            );
2039
2040
2041        if (gallerySharing.position == 'top' || gallerySharing.position == 'all') {
2042			var buttons = this.$container.find('.gallery-sharing-top')
2043                .html($socialButtons.html())
2044                .find('.supsystic-social-sharing');
2045            window.initSupsysticSocialSharing(buttons);
2046        }
2047
2048        if (gallerySharing.position == 'bottom' || gallerySharing.position == 'all'){
2049			var buttons = this.$container.find('.gallery-sharing-bottom')
2050                .html($socialButtons.html())
2051                .find('.supsystic-social-sharing');
2052            window.initSupsysticSocialSharing(buttons);
2053        }
2054
2055		this.initEvent(this.$container.find('.gallery-sharing-top,.gallery-sharing-bottom'));
2056    };
2057
2058    //init social share for all images in gallery
2059    Gallery.prototype.initImageSocialSharing = function(){
2060
2061        var imageSharing = this.socialSharing.imageSharing;
2062
2063        if(!parseInt(imageSharing.enabled)){
2064            return;
2065        }
2066
2067        var $images = this.$getImagesFigureContainer(),
2068            socialButtonsClass = 'supsystic-grid-gallery-image-sharing ' + imageSharing.wrapperClass,
2069            self = this,
2070            iconsEnabled = this.$container.data('icons');
2071
2072
2073        $images.each(function() {
2074            var $this = $(this),
2075                $el;
2076
2077            if (!iconsEnabled) {
2078                $el = $this.parent();
2079            } else {
2080                $el = $this.find('a.hi-icon');
2081            }
2082
2083            $this.append(
2084                self.getSocialButtonsByImage(socialButtonsClass, $el)
2085            );
2086        });
2087
2088        this.correctImageSocialButtons($images.children("." + this.socialSharingWrapperClass));
2089        this.initEvent($images.children("." + this.socialSharingWrapperClass));
2090    };
2091
2092    Gallery.prototype.correctImageSocialButtons = function($imageSharing){
2093
2094        if(!$imageSharing.size()){
2095            return;
2096        }
2097        var $example = $imageSharing.eq(0),
2098            correctCss = {};
2099
2100        if($example.hasClass('vertical')){
2101            var buttonWidth = $example.find('.social-sharing-button').eq(0).outerWidth();
2102            correctCss.width = buttonWidth;
2103            $example.width(buttonWidth);
2104        }
2105
2106        var width = $example.width();
2107        var height = $example.height();
2108
2109        if($example.hasClass('center')){
2110            $.extend(correctCss,{'margin-left': '-' + (width/2) + 'px'})
2111        }
2112        if($example.hasClass('middle')){
2113            $.extend(correctCss,{'margin-top': '-' + (height/2) + 'px'})
2114        }
2115
2116        $imageSharing.find('.social-sharing-button.print').on('click',function(){
2117            var image_url = $(this).closest('.supsystic-grid-gallery-image-sharing').data('img-url');
2118            window.open(image_url).print();
2119        });
2120
2121        $imageSharing.find('.social-sharing-button.mail').on('click',function(){
2122            var $infoElement = $(this).closest('.supsystic-grid-gallery-image-sharing'),
2123                image_id = $infoElement.data('img-id'),
2124                image_title = $infoElement.data('img-title');
2125            var url = window.location.href.replace(window.location.hash,'') + '#' + image_id + '/';
2126
2127            var src = 'mailto:[email protected]?subject=' + encodeURIComponent(document.title) + ',' + image_title + '&body=' + url;
2128            var iframe = $('<iframe id="mailtoFrame" src="' + src + '" width="1" height="1" border="0" frameborder="0"></iframe>');
2129
2130            $('body').append(iframe);
2131            window.setTimeout(function(){
2132                iframe.remove();
2133            }, 500);
2134        });
2135
2136        var self = this;
2137        $imageSharing.each(function(){
2138
2139            $(this).css(correctCss);
2140
2141            var thumbnail = $(this).data('img-thumbnail');
2142
2143            if (thumbnail) {
2144
2145                for(var sharingClass in self.socialSharingImageOperators){
2146                    var $button = $(this).find('.social-sharing-button.'+sharingClass);
2147                    if($button.size()){
2148                        var img_url = $(this).data('img-url'),
2149                            img_id = $(this).data('img-id'),
2150							shareUrlObj = self.urlToObject($button.attr('href')),
2151							newHref = '';
2152
2153						// set gallery image for share link
2154						shareUrlObj.params[self.socialSharingImageOperators[sharingClass]] = thumbnail;
2155						newHref = self.objectToUrl(shareUrlObj);
2156
2157						if(img_url) {
2158							newHref = newHref.replace(
2159								img_url,
2160								self.addPopUpHashToUrl(self.socialButtonsUrl, img_id)
2161							);
2162						}
2163
2164						$button.attr('href', newHref);
2165                    }
2166                }
2167            }
2168        });
2169
2170    };
2171
2172	Gallery.prototype.urlToObject = (function(strUrl) {
2173		if(!strUrl) {
2174			return null;
2175		}
2176		var posQ = strUrl.indexOf('?');
2177		if(posQ == -1) {
2178			return null;
2179		}
2180		var strQueryParams = strUrl.substr(posQ + 1)
2181		,	result = {
2182			'url': strUrl.substr(0, posQ),
2183			'params': {},
2184		}
2185		;
2186		strQueryParams.split("&").forEach(function(part) {
2187			var item = part.split("=");
2188			if(item.length >=2) {
2189				result.params[item[0]] = decodeURIComponent(item[1]);
2190			}
2191		});
2192		return result;
2193	});
2194
2195	Gallery.prototype.objectToUrl = (function(specObj) {
2196		if(!specObj) {
2197			return null;
2198		}
2199
2200		var resUrl = '';
2201		if(specObj.url) {
2202			resUrl = specObj.url;
2203		}
2204		if(specObj.params) {
2205
2206			var paramParts = []
2207			,	paramKeys = Object.keys(specObj.params)
2208			,	indX = 0
2209			;
2210			for(indX = 0; indX < paramKeys.length; indX++) {
2211				paramParts.push(encodeURIComponent(paramKeys[indX]) + '=' + encodeURIComponent(specObj.params[paramKeys[indX]]));
2212			}
2213			resUrl = resUrl + '?' + paramParts.join('&');
2214		}
2215		return resUrl;
2216	});
2217
2218    Gallery.prototype.addSocialShareToPopUp = function($element, $wrapper, addClass, fixed) {
2219
2220        if(!this.socialSharing.enabled || !parseInt(this.socialSharing.popupSharing.enabled)){
2221            return;
2222        }
2223
2224        var buttonsClass = 'supsystic-grid-gallery-image-sharing ' + addClass;
2225
2226        if (!fixed) {
2227            buttonsClass +=' ' + this.socialSharing.popupSharing.wrapperClass;
2228        }
2229
2230        var attachId = $element.attr('data-attachment-id');
2231        var attachObject = jQuery('body').find('.gg-link[data-attachment-id="'+attachId+'"]');
2232        var attachHtml = attachObject.find('.supsystic-social-sharing').html();
2233        $wrapper.find('.supsystic-grid-gallery-image-sharing').remove();
2234        $wrapper.prepend(this.getSocialButtonsByImage(buttonsClass, $element, true));
2235        $wrapper.find('.supsystic-social-sharing').html(attachHtml);
2236
2237		// remove "Show all networks" button
2238		$wrapper.find('.supsystic-social-sharing .trigger-popup').remove();
2239
2240        this.correctImageSocialButtons($wrapper.find('.supsystic-grid-gallery-image-sharing'));
2241
2242        this.initEvent($wrapper.children("." + this.socialSharingWrapperClass));
2243    };
2244
2245    Gallery.prototype.removePopUpHashFromUrl = function(url){
2246        var match = url.match(/gg-\d+-\d+/);
2247        return url.replace(url[url.indexOf(match)-1] + match,"");
2248    };
2249
2250    Gallery.prototype.addPopUpHashToUrl = function(url, hash){
2251		if(!hash || !hash.length) {
2252            return url;
2253        }
2254        var prefix = '?';
2255        if(url.indexOf(prefix) != -1) prefix = '&';
2256        return url + prefix + hash;
2257    };
2258
2259    Gallery.prototype.openHashPopUp = function(){
2260        var getElementId = function() {
2261
2262            var search = window.location.search;
2263            if (search.match(/gg-\d+-\d+/)) {
2264                return search.match(/gg-\d+-\d+/);
2265            }
2266
2267            var hash = window.location.hash;
2268            if (hash.match(/gg-\d+-\d+/)) {
2269                return hash.match(/gg-\d+-\d+/);
2270            }
2271        };
2272
2273        var elementId = getElementId(),
2274			$element = this.$container.find('#' + elementId + ', [data-id="' + elementId + '"]').first();
2275
2276        if($element.length){
2277			$element.click();
2278			var $figure;
2279
2280			if ($element.hasClass('hi-icon')) {
2281				$figure = $element.closest('figure.grid-gallery-caption');
2282			} else {
2283				$figure = $element.children('figure');
2284			}
2285
2286			if($figure.length) {
2287				$('html, body').animate({
2288					scrollTop: $figure.offset().top
2289				}, 100);
2290			}
2291        }
2292    };
2293
2294	Gallery.prototype.updateQueryParams = function (url, params) {
2295		for (var param in params) {
2296
2297			var re = new RegExp("[\\?&]" + param + "=([^&#]*)"),
2298				match = re.exec(url),
2299				delimiter,
2300				value = params[param];
2301
2302
2303			if (match === null) {
2304
2305				var hasQuestionMark = /\?/.test(url);
2306				delimiter = hasQuestionMark ? "&" : "?";
2307
2308				if (value) {
2309					url = url + delimiter + param + "=" + value;
2310				}
2311
2312			} else {
2313				delimiter = match[0].charAt(0);
2314
2315				if (value) {
2316					url = url.replace(re, delimiter + param + "=" + value);
2317				} else {
2318					url = url.replace(re, '');
2319					if (delimiter === '?' && url.length) {
2320						url = '?' + url.substr(1);
2321					}
2322				}
2323			}
2324		}
2325
2326		return url;
2327	};
2328
2329    Gallery.prototype.changePopUpHash = function(hash){
2330
2331        var galleryId = this.$container.attr('data-gg-id')
2332        ,   galleryOpenPopupHashRegex = new RegExp('gg-' + galleryId + '(?:-(\\d+))*')
2333        ,   regexFoundGalleryImageId = galleryOpenPopupHashRegex.exec(hash)
2334		,   changedUrlDisabled = this.$container.attr('data-popup-disable-changed-url');
2335
2336		if(changedUrlDisabled !== 'true') {
2337			// if image id not exits
2338			if (!regexFoundGalleryImageId || regexFoundGalleryImageId.length < 2 || !regexFoundGalleryImageId[1]) {
2339				return;
2340			}
2341			this.popupIsOpened = true;
2342
2343			if (this.ignoreStateChange) {
2344				this.ignoreStateChange = false;
2345				return;
2346			}
2347			var queryParams = this.updateQueryParams(window.location.search, {'_gallery': hash}),
2348				stateUrl = window.location.pathname + queryParams;
2349
2350			this.historyStateChange = true;
2351
2352			if (!this.popupIsInit) {
2353
2354				if (queryParams === document.location.search) {
2355
2356					History.replaceState({
2357						type: 'sc-gallery',
2358						hash: hash,
2359						state: 'close'
2360					}, document.title, window.location.pathname + this.updateQueryParams(window.location.search, {'_gallery': null}));
2361
2362					History.pushState({
2363						type: 'sc-gallery',
2364						hash: hash,
2365						state: 'init'
2366					}, document.title, stateUrl);
2367
2368				} else {
2369
2370					History.replaceState({
2371						type: 'sc-gallery',
2372						hash: hash,
2373						state: 'init'
2374					}, document.title, stateUrl);
2375				}
2376
2377				this.popupIsInit = true;
2378
2379			} else {
2380
2381				if (this.disablePopupHistory) {
2382					History.replaceState({
2383						type: 'sc-gallery',
2384						hash: hash,
2385						state: 'change'
2386					}, document.title, stateUrl);
2387				} else {
2388					History.pushState({
2389						type: 'sc-gallery',
2390						hash: hash,
2391						state: 'change'
2392					}, document.title, stateUrl);
2393				}
2394			}
2395
2396			this.historyStateChange = false;
2397		}
2398	};
2399
2400    Gallery.prototype.clearPopUpHash = function() {
2401		this.historyStateChange = true;
2402
2403		if (this.disablePopupHistory) {
2404			History.replaceState({
2405				type: 'sc-gallery',
2406				hash: '',
2407				state: 'close'
2408			}, document.title, window.location.pathname + this.updateQueryParams(window.location.search, {'_gallery': null}));
2409		} else {
2410			History.pushState({
2411				type: 'sc-gallery',
2412				hash: '',
2413				state: 'close'
2414			}, document.title, window.location.pathname + this.updateQueryParams(window.location.search, {'_gallery': null}));
2415		}
2416
2417		this.historyStateChange = false;
2418		this.popupIsOpened = false;
2419	};
2420
2421	Gallery.prototype.getRealImgSizeInBrowser = (function(arguments) {
2422		if(!arguments && !arguments.length) {
2423			return null;
2424		}
2425		if(arguments.length > 1) {
2426			returnType = arguments[1];
2427		}
2428		if(arguments.length) {
2429			$image = arguments[0];
2430		}
2431
2432		var returnData = null
2433		,	boundRect = null;
2434		if($image && $image.length && $image[0].getBoundingClientRect) {
2435			boundRect = $image[0].getBoundingClientRect();
2436		}
2437
2438		if(returnType == 'h') {
2439			if(boundRect && boundRect.height) {
2440				returnData = boundRect.height;
2441			} else {
2442				returnData = parseFloat($image.css('height'));
2443			}
2444		} else if(returnType == 'w') {
2445			if(boundRect && boundRect.width) {
2446				returnData = boundRect.width;
2447			} else {
2448				returnData = parseFloat($image.css('width'));
2449			}
2450		}
2451
2452		return returnData;
2453	});
2454
2455	Gallery.prototype.lazyLoadTriggerHandler = (function() {
2456		$(document).trigger('scroll');
2457	});
2458	Gallery.prototype.lazyLoadDistanceRefresh = (function(waitTime) {
2459		var self = this,
2460            galleryType = this.$container.data('gridType');
2461
2462        if(typeof(waitTime) == 'undefined') {
2463            waitTime = 400;
2464        }
2465
2466		// need run function once at every load
2467		if(self.ggLazyTimeOut) {
2468			clearTimeout(self.ggLazyTimeOut);
2469		}
2470		self.ggLazyTimeOut = setTimeout(function() {
2471            setTimeout(function() {
2472                $.each(self.$elements, function(index, el) {
2473                    var $el = $(el);
2474                    if ($el.data('grid-gallery-type') == 'polaroid'){
2475                        self.polaroidCaptionCalculate($el);
2476                    }
2477                });
2478            }, waitTime + 50);
2479
2480			switch(galleryType) {
2481				case 4:
2482					$(document).trigger('ggMosaicResizedEvent');
2483					break;
2484				case 0:
2485                    if(typeof(self.setCaptionOnHoverImage) == 'function') {
2486                        self.setCaptionOnHoverImage();
2487                    }
2488					// if hidden images  not showing
2489					setTimeout(function() {
2490						self.lazyLoadTriggerHandler();
2491                        setTimeout(function() {
2492                            if(self.wookmark) {
2493                                self.wookmark.trigger('refreshWookmark');
2494                            }
2495                        }, 50);
2496					}, waitTime + 60);//450); // animation transition time
2497					break;
2498				case 1:
2499                    if(typeof(self.setCaptionOnHoverImage) == 'function') {
2500                        self.setCaptionOnHoverImage();
2501                    }
2502                    $.each(self.$elements, function(index, el) {
2503                        var $el = $(el);
2504                        if ($el.data('grid-gallery-type') == '3d-cube'){
2505                            self.changeImageHeightFor3dCubeEffect($el, $el.width(), ($el.find('img').length ? $el.find('img').height() : $el.height()));
2506                        }
2507                    });
2508				case 2:
2509				case 3:
2510				default:
2511					//self.initWookmark();
2512					// if hidden images  not showing
2513					setTimeout(function() {
2514						self.lazyLoadTriggerHandler();
2515						self.initWookmark();
2516					}, waitTime + 50);//450); // animation transition time
2517					break;
2518			}
2519		}, 100);
2520	});
2521
2522	Gallery.prototype.initLazyLoad = (function() {
2523		var self = this
2524		,	hoverImgSrc = this.$container.data('image-on-hover');
2525		/*if(hoverImgSrc && hoverImgSrc.length) {
2526			// lazy load not work for image on hover
2527			return;
2528		}*/
2529        var showMoreCategory = this.$container.find('.showMoreCategory'),
2530            effect = this.$container.data('lazyload-effect'),
2531            duration = this.$container.data('lazyload-effect-duration');
2532
2533        if(typeof(effect) == 'undefined') {
2534            effect = 'show';
2535            duration = 400;
2536        }
2537        var waitTime = effect == 'fadeIn' ? 200 : duration;
2538
2539		self.ggLazyTimeOut = null;
2540		this.$container.find('.ggLazyImg').ggLazyLoad({
2541			'data_attribute': 'gg-real-image-href',
2542			'threshold': 50,
2543            'effect': effect,
2544            'effectspeed': duration,
2545            'skip_invisible': (showMoreCategory.length > 0),
2546			'load': function(event) {
2547				var image = $(this);
2548				self.lazyLoadDistanceRefresh(waitTime);
2549				if(self.$container.data('gridType') != 0) {
2550                    image.closest('div .crop').css('height', '');
2551                }
2552				image.closest('figure').css('height', 'auto');
2553				if(self.$container.data('gridType') == 2 && self.$elements) {
2554					setTimeout(function() {
2555						self.resizeElementHeight(image, image.closest('figure'));
2556					}, waitTime + 20);//460); // animation transition time + 20ms
2557				}
2558			},
2559		});
2560	});
2561
2562    Gallery.prototype.init = (function () {
2563
2564        this.$container.imagesLoaded($.proxy(function () {
2565
2566            var self = this;
2567            // this.setImagesHeight();
2568            $(document).trigger("GalleryBeforeInit", this);
2569
2570            this.hidePreloader();
2571            this.showCaption();
2572            this.initRowsMode();
2573            this.initHorizontalGalleryType();
2574            this.initQuicksand();
2575
2576            if(this.$container.attr('data-fullscreen') == 'true') {
2577                this.correctFullScreenWidthGallery();
2578                $(window).resize(function() {
2579                    self.correctFullScreenWidthGallery();
2580                });
2581            }
2582
2583            this.initHorizontalMode();
2584            this.setOverlayTransparency();
2585            this.initCaptionCalculations();
2586            this.initCaptionEffects();
2587            this.hideTitleTooltip();
2588            this.initPagination();
2589
2590            this.initPopup();
2591
2592            this.setMouseShadow();
2593            this.setImageOverlay();
2594
2595            this.loadFontFamily();
2596            this.hidePopupCaptions();
2597            this.preventImages();
2598            this.initWookmark();
2599            this.initCategories();
2600            this.setIconsPosition();
2601
2602            this.correctMargin();
2603            this.initControll();
2604            this.showGalleryParts();
2605			this.initLazyLoad();
2606
2607            this.initSocialSharing();
2608
2609
2610            // iOS Safari fix
2611            setTimeout(function() {
2612                if (self.wookmark) {
2613                    self.wookmark.trigger('refreshWookmark');
2614                }
2615            }, 500);
2616
2617            $(document).trigger("GalleryAfterInit", this);
2618
2619            setTimeout(function(){
2620                self.openHashPopUp();
2621            },500);
2622
2623            // this.openHashPopUp();
2624
2625            var galleryId = this.$container.attr('data-gg-id'),
2626				openByLinkRegexp = new RegExp('#gg-open-' + galleryId + '(\\-([\\d]+))*$');
2627
2628			History.Adapter.bind(window, 'statechange', function(event) {
2629				var state = History.getState();
2630
2631				// self.historyStateChange if true means manual update state and we need skip this event
2632				if (!self.historyStateChange) {
2633
2634					if ((state.data.type !== 'sc-gallery' && self.popupIsOpened) ||
2635						(state.data.type === 'sc-gallery' && (state.data.state === 'close' || state.data.state ===  'hashchange') && self.popupIsOpened)
2636					) {
2637
2638						if (self.popupType == 'pretty-photo') {
2639							this.$prettyPhoto && this.$prettyPhoto.close();
2640						}
2641
2642						if (self.popupType == 'colorbox') {
2643							$.colorbox && $.colorbox.close();
2644						}
2645
2646						if (self.popupType == 'photobox') {
2647							window._photobox && window._photobox.close();
2648						}
2649
2650					}
2651
2652					// On history open image
2653					if (state.data.type === 'sc-gallery' && state.data.hash && state.data.state !== 'close') {
2654
2655						self.ignoreStateChange = true;
2656
2657						var $el = self.$container.find('#' + state.data.hash + ', [data-id="' + state.data.hash + '"]').first();
2658
2659						if (self.popupIsOpened) {
2660
2661							if (self.popupType == 'pretty-photo' && this.$prettyPhoto) {
2662								var href = $el.attr('href'),
2663									index = this.$prettyPhoto.getImagesList().indexOf(href);
2664								this.$prettyPhoto.changePage(index);
2665							}
2666
2667							if (self.popupType == 'colorbox') {
2668								$.colorbox.resizeResponsive($el);
2669							}
2670
2671							if (self.popupType == 'photobox') {
2672								var images = window._photobox.getImages(),
2673									href = $el.attr('href');
2674
2675								for (var i = 0; i < images.length; i++) {
2676									if (images[i][0] == href || images[i][0] == 'http:' + href || images[i][0] == 'https:' + href) {
2677										window._photobox.changeImage(i);
2678									}
2679								}
2680							}
2681
2682						} else {
2683							$el.trigger('click');
2684						}
2685
2686					}
2687
2688				}
2689
2690			});
2691
2692			//check url and show popups
2693			//options "Open by link in popup"
2694			function checkUrl(){
2695				var hash = window.location.hash,
2696					matches = openByLinkRegexp.exec(hash);
2697
2698				if (matches) {
2699					History.replaceState({
2700						type: 'sc-gallery',
2701						hash: '',
2702						state: 'hashchange'
2703					}, document.title, window.location.pathname);
2704
2705					var position = matches[2] ? 'eq(' + (matches[2] - 1) + ')' : 'first';
2706					self.$container.find('.gg-link:' + position + ', .hi-icon:' + position).trigger('click');
2707				}
2708			}
2709
2710            $(window).on('hashchange', function(event) {
2711				checkUrl();
2712            });
2713
2714			$(document).ready(function () {
2715				checkUrl();
2716			});
2717
2718
2719
2720        }, this));
2721
2722        $(window).on('resize', $.proxy(function () {
2723            this.correctMargin();
2724            this.resizeHorizontalElements();
2725            this.initHorizontalMode();
2726        }, this));
2727    });
2728
2729	Gallery.prototype.resizeHorizontalElements = (function () {
2730		var self = this;
2731		if(this.$container.data('gridType') == 2 && this.$elements) {
2732			this.$elements.each(function(){
2733				var element = $(this),
2734					image = element.find('img');
2735				if(image) {
2736					self.resizeElementHeight(image, element);
2737				}
2738			});
2739		}
2740	});
2741
2742	Gallery.prototype.resizeElementHeight = (function (image, element) {
2743		var imageHeight = parseInt(image.css('height'));
2744		if(!isNaN(imageHeight) && !element.hasClass('initialized')) {
2745			element.css('height', Math.floor(imageHeight - 1) + 'px');
2746		}
2747        if(!image.hasClass('ggLazyImg')) {
2748            image.removeClass('ggNotInitImg');
2749            this.polaroidCaptionCalculate(element);
2750        }
2751	});
2752
2753    window.initGridGallery = (function (el, autoInit) {
2754        var makeSelector = (function (el) {
2755            return '#' + el.id;
2756        });
2757        return new Gallery(makeSelector(el), autoInit);
2758    });
2759
2760    window.contentLoaded = (function() {
2761
2762
2763        var $galleries = $(".grid-gallery:not('.initialized')"),
2764            $promise = new $.Deferred().resolve();
2765
2766        if ($galleries.length > 0) {
2767
2768            $.each($galleries, (function(i, el) {
2769                $promise = $promise.then(function() {
2770                    return new Gallery(el, true);
2771                });
2772            }));
2773        }
2774
2775        $('.crop').css('display', 'block');
2776
2777    });
2778
2779    if (!init) {
2780		var hammer = new Hammer_gg(document)
2781		,	$anyGallery = $(".grid-gallery:first")
2782		,	isMobile = parseInt($anyGallery.attr('data-is-mobile'))
2783		;
2784		// only if mobile, because "mouse dragg" include for this event
2785		if(!isNaN(isMobile) && isMobile) {
2786			// On swipe click next prev button in active popup
2787			hammer.on('swipeleft swiperight', function(event) {
2788				if (event.type == 'swipeleft') {
2789					$("#colorbox:visible #cboxNext, .pp_pic_holder a.pp_arrow_next, #cboxOverlay:visible #pbNextBtn").click();
2790				} else {
2791					$("#colorbox:visible #cboxPrevious, .pp_pic_holder a.pp_arrow_previous, #cboxOverlay:visible #pbPrevBtn").click();
2792				}
2793			});
2794		}
2795		init = true;
2796	}
2797
2798    $(document).ready(function () {
2799        contentLoaded();
2800    }).ajaxComplete(function() {
2801        contentLoaded();
2802    });
2803
2804    if ( jQuery('body').hasClass('oceanwp-theme') ) {
2805		function oceanwpFixedFooter () {
2806			$("#main").css("min-height", "0px");
2807		};
2808		jQuery(window).resize(function() {
2809			oceanwpFixedFooter();
2810		});
2811		jQuery(document).ready(function () {
2812			setTimeout(function(){
2813				oceanwpFixedFooter();
2814			},3000);
2815		});
2816	}
2817
2818	// added Gallery initialization by trigger
2819	$(document).on('ggFirInitialize', function() {
2820		contentLoaded();
2821	});
2822
2823    //if a customer enter an e-mail for image link in gallery he'll get a mailto: link
2824    $('a.gg-link').each(function(){
2825        var gLink =  $(this).attr('href');
2826        var reg= /[0-9a-z_]+@[0-9a-z_]+\.[a-z]{2,5}/i;
2827		if(gLink) {
2828			var isEmail = gLink.match(reg);
2829			if(isEmail) {
2830				$(this).attr('href','mailto:' + isEmail[0]);
2831			}
2832		}
2833    });
2834
2835    jQuery(document).ready(function(){
2836       setTimeout(function(){
2837          jQuery('body').find('.supsystic-social-sharing').each(function( key, value ){
2838                var summary = 0;
2839                jQuery(this).find('.social-sharing-button').each(function( key2, value2 ){
2840                   if (jQuery(this).parent().hasClass('supsystic-social-sharing-popup')) return;
2841                   var networks = jQuery(this).attr('data-networks');
2842                   networks = jQuery.parseJSON(networks);
2843                   var attachId = jQuery('.supsystic-social-sharing').eq(key).closest('[data-attachment-id]').attr('data-attachment-id');
2844                   if (typeof attachId != 'undefined') {
2845                      var nid = jQuery(this).attr('data-nid');
2846                      var counter = networks[attachId][nid];
2847                      if (parseInt(counter) && !isNaN(counter)) {
2848                        summary = summary + parseInt(counter);
2849                      }
2850                      var counterWrapper = '';
2851                      if (jQuery(this).hasClass('counter-standard')) {
2852                        jQuery(this).find('.counter-wrap.standard').remove('');
2853                        counterWrapper = '<div class="counter-wrap standard"><span class="counter">
2853'+counter+'</span></div>';
2854                      }
2855                     if (jQuery(this).hasClass('counter-arrowed')) {
2856                        jQuery(this).find('.counter-wrap.arrowed').remove('');
2857                        counterWrapper = '<div class="counter-wrap arrowed"><span class="counter">'+counter+'</span></div>';
2858                      }
2859                      if (jQuery(this).hasClass('counter-white-arrowed')) {
2860                        jQuery(this).find('.counter-wrap.white-arrowed').remove('');
2861                        counterWrapper = '<div class="counter-wrap white-arrowed"><span class="counter">'+counter+'</span></div>';
2862                      }
2863                      var attachId = jQuery(this).append(counterWrapper);
2864                   }
2865                });
2866                summary = '<span>Shares</span> <span>'+summary+'</span>';
2867                jQuery(this).closest('a').find('.supsystic-social-sharing-total-counter.counter-wrap').html(summary);
2868          });
2869       }, 1000);
2870    });
2871}(jQuery));

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