PageSourceSearch

https://bookshop.codesria.org/wp-content/themes/imarket/assets/js/functions.js?ver=1.4.6

js codesria.org collected 2026-09-24 09:30:03 UTC 140,409 bytes, 4,245 lines download raw bytes

1/*
2 * Theme js functions file.
3 */
4 
5var $ 					= jQuery.noConflict(),
6	imarketOwlArg 	= imarketOwlArg || {},
7	imarket_options 	= imarket_options || {},
8	imarket 			= imarket || {};
9(function($) { 
10	
11    "use strict";
12	
13	imarket.init = function() {
14		imarket.$doc          	= $(document);
15		imarket.$html    			= $('html');
16		imarket.$body 			= $(document.body);
17		imarket.$window 			= $(window);
18		imarket.$windowWidth 		= $(window).width();
19		imarket.$windowHeight 	= $(window).height();
20		imarket.ajaxXHR 			= null;
21		imarket.isPostLoading 	= false;
22		imarket.$tooltip 			= $('.product-buttons a,.whishlist-button a');
23		imarket.$swatches 		= imarket.$doc.find( 'div.imarket-swatches-wrap' );
24		imarket.$swatchForm 		= imarket.$doc.find( 'form.imarket-swatches-wrap.variations_form' );
25		
26		this.isCheckRTL();
27		this.mobileDevice();
28		this.BrowserDetection();
29		this.backToTop();
30		this.imagelazyload();
31		this.reinitLazyload();
32		this.initNanoScroller();
33		this.initMagnaficPopup();
34		this.newsLetterPopup();	
35		this.imarketMegamenu();
36		this.mobileMenu();
37		this.promoBar();
38		this.stickyHeader();
39		this.StickyHeaderScrollUP();
40		this.stickySidebar();
41		this.canvasSidebar();
42		this.openMiniSearch();
43		this.widgetMenuToggle();
44		this.widgetToggle();
45		this.footerWidgetCollapse();
46		this.widgetMaxLimitItem();
47		this.imarketOwlCarousel();
48		this.MasonryGrid();
49		this.postGalleryCarousel();
50		this.loadmorePosts();
51		this.socialShare();
52		this.portfolioFilters();
53		this.portfolioLoadMore();
54		
55		/* Woocommerce */
56		this.productLiveSearch();
57		this.swapLoginSignupFrom();
58		this.userLoginSignupPopup();
59		this.miniCartWidget();		
60		this.addToWishlist();
61		this.wishlistCount();
62		this.addToCompare();
63		this.compareCount();		
64		this.removeToCompare();
65		this.ProductLoopQuantityField();
66		this.addToCart();
67		this.addToCartAjax();	
68		this.stickyAddToCart();
69		this.productQuickView();
70		this.productShowFilter();
71		this.productShowHideFilters();
72		this.productFilterAjax();
73		this.productSwatch();
74		this.initAjaxLoad();
75		this.loadmoreProducts();
76		this.tooltip();
77		this.productGallerySummarySticky();
78		this.productGallerySlider();
79		this.productImageZoom();
80		this.productPhotoSwipe();		
81		this.productSaleCountdown();
82		this.productReviewLink();
83		this.getProductSizeChart();
84		this.getAjaxBlock();
85		this.productQuantityPlusMinus();
86		this.productQuickShop();
87		this.productBoughtTogetherInit();
88		this.wooProductTabsAccordian();
89		this.wooProductTabsToggle();
90		this.wcfm_vendor();
91		this.MiniCartUpdateQuantity();
92		this.autoCartUpdate();
93		this.checkoutUpdateQuantity();
94		this.getVisitorCount();
95		this.askQuestionsForm();
96		
97		/* Elements */
98		this.imarketEqualTabsHeight();
99		this.imarketAjaxtab();
100		this.imarketResponsiveTab();
101		this.imarketProgressbar();
102		this.imarketCounterUp();
103		this.imageGaleryMasonry();
104		this.imarketElementorOwlCarousel();
105		this.BackgroundParallax();
106	}
107	
108	imarket.isCheckRTL = function(){
109		/*
110		* If check is site RTL
111		*/		
112		$('html[dir="rtl"] body').addClass('rtl');
113		var imarket_rtl = false;
114		if($('body,html').hasClass('rtl')){ 
115			imarket_rtl =  true;
116		}	
117		
118		return imarket_rtl;
119	};
120	
121	imarket.mobileDevice = function() {
122		var window_size = jQuery('body').innerWidth();
123		if(window_size < 991){
124			jQuery('body').addClass('imarket-mobile-device');
125		}else{
126			jQuery('body').removeClass('imarket-mobile-device');
127		}
128		 imarket.$window.on('resize', function () {
129			var window_size = jQuery('body').innerWidth();
130			if(window_size < 991){
131				jQuery('body').addClass('imarket-mobile-device');
132			}else{
133				jQuery('body').removeClass('imarket-mobile-device');
134			}
135		}); 
136	};
137	
138	imarket.BrowserDetection = function () {
139		/* Check if browser is IE */
140		if (navigator.userAgent.search("MSIE") >= 0) {
141			jQuery('body').addClass('browser-msie');
142		}
143		/* Check if browser is Chrome */
144		else if (navigator.userAgent.search("Chrome") >= 0) {
145			jQuery('body').addClass('browser-chrome');
146		}
147		/* Check if browser is Firefox  */
148		else if (navigator.userAgent.search("Firefox") >= 0) {
149			jQuery('body').addClass('browser-firefox');
150		}
151		/* Check if browser is Safari */
152		else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) {
153			jQuery('body').addClass('browser-safari');
154		}
155		/* Check if browser is Opera */
156		else if (navigator.userAgent.search("Opera") >= 0) {
157			jQuery('body').addClass('browser-opera');
158		}
159	};
160	
161	imarket.backToTop = function(){
162		//*******************************************************************
163		//* Back to top button 
164		//********************************************************************/
165		var el = $('.imarket-back-to-top');
166		imarket.$window.on('scroll',function(){				
167			if(el.length > 0){
168				if( imarket.$window.scrollTop() > 150 ){
169					el.fadeIn(400);	
170				}else{
171					el.fadeOut(400);	
172				}	
173			}	
174		});
175		
176		el.on('click', function (e) {
177				$('html,body').animate({scrollTop:0}, 600);	
178				return false;
179		});				
180	};
181	
182	imarket.imagelazyload = function(){
183		if ( imarket.$body.find('.lazy').length > 0 && imarket_options.lazy_load ) {
184			var lazy_args = [];
185			lazy_args.afterLoad      = function (element) {
186				element.removeClass('lazy');
187				element.removeClass('loading');
188				element.addClass('lazy-loaded');
189			};
190			lazy_args.effect         = "fadeIn";
191			lazy_args.enableThrottle = true;
192			lazy_args.throttle       = 250;
193			lazy_args.effectTime     = 1000;
194			lazy_args.threshold      = 0;
195			imarket.$body.find('.lazy').lazy(lazy_args);			
196		}
197	};
198	
199	imarket.reinitLazyload = function(){
200		if ( !imarket_options.lazy_load )  return;
201		$(document).on('shown.bs.tab', 'a[data-toggle="tab"]', function (e) {
202			imarket.imagelazyload();			
203		});
204		$(document).on('removed_from_cart', function (e) {
205			imarket.imagelazyload();			
206		});
207		$(window).bind('mousewheel DOMMouseScroll', function(event){
208			if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0) {
209				
210			}
211			else {
212				imarket.imagelazyload();		
213			}
214		});
215	}
216	
217	imarket.initNanoScroller = function() {
218		/*
219		* Nano Scroller
220		*/		
221		if( $(window).width() < 1024 ) return;
222		$(".imarket-scroll").nanoScroller({
223			paneClass: 'imarket-scroll-pane',
224			sliderClass: 'imarket-scroll-slider',
225			contentClass: 'imarket-scroll-content',
226			preventPageScrolling: false
227		});
228
229		$( 'body' ).on( 'wc_fragments_refreshed wc_fragments_loaded added_to_cart', function() {
230			$(".widget_shopping_cart .imarket-scroll").nanoScroller({
231				paneClass: 'imarket-scroll-pane',
232				sliderClass: 'imarket-scroll-slider',
233				contentClass: 'imarket-scroll-content',
234				preventPageScrolling: false
235			});
236		} );
237	}
238	
239	imarket.initMagnaficPopup = function (){		
240		
241		var wordpress_galery = $(document).find('.gallery');
242		wordpress_galery.each(function(index){
243			var current_gallery = $(this);
244			$( current_gallery ).magnificPopup({
245				delegate: 'img',
246				type: 'image',
247				removalDelay: 500,
248				callbacks: {
249					beforeOpen: function() {
250						this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
251						this.st.mainClass = 'mfp-with-zoom mfp-img-mobile';
252					},
253					elementParse: function(item) {  item.src = item.el.attr('src'); }
254				},
255				image: {
256					verticalFit: true
257				},
258				gallery: {
259					enabled: true,
260					navigateByImgClick: true
261				},
262			});
263			
264		});
265		
266		$( '.product-360-degree-btn a' ).magnificPopup({
267		  type: 'inline',
268		  midClick: true,
269		  mainClass: 'mfp-fade'
270		});
271		
272		init_magnificpopup('.imarket-gallery-carousel','.owl-item:not(.cloned) a');
273		init_magnificpopup('.imarket-image-gallery.image-gallery-normal-grid','a');
274		init_magnificpopup('.imarket-image-gallery.image-gallery-masonry-grid','a');
275		init_magnificpopup('.imarket-image-gallery.image-gallery-carousel','.owl-item:not(.cloned) a');
276		init_magnificpopup('.portfolios-list','a.project-zoom');
277		init_magnificpopup('.imarket-portfolio-image:not(.imarket-gallery-carousel)','.imarket-post-gallery__image a');
278		init_magnificpopup('.related.portfolios .imarket-carousel','.owl-item:not(.cloned) a.project-zoom');
279		init_magnificpopup('.imarket-portfolios-carousel','.owl-item:not(.cloned) a.project-zoom');
280		init_magnificpopup('.product-sizechart','a.zoom-gallery');
281		
282		
283		function init_magnificpopup(container,delegate){
284			
285			var container_wrap = $(document).find(container);
286			
287			if( typeof('container_wrap') !== 'undefined' && container_wrap != '' ) {
288				container_wrap.each(function(index){
289					var portfolio_item = $(this);
290					$(portfolio_item).magnificPopup({
291						delegate    : delegate,
292						type: 'image',
293						removalDelay: 500,
294						callbacks: {
295							beforeOpen: function() {
296								this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
297								this.st.mainClass = 'mfp-with-zoom mfp-img-mobile';
298							}
299						},
300						image: {
301							verticalFit: true
302						},
303						gallery: {
304							enabled: true,
305							navigateByImgClick: false
306						},
307					});
308					
309				});
310			}
311		}
312		
313		$('.link-popup').magnificPopup({
314			type: 'image',
315			removalDelay: 500,
316			callbacks: {
317				beforeOpen: function() {
318					this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
319					this.st.mainClass = 'mfp-with-zoom mfp-img-mobile';
320				}
321			},
322			image: {
323				verticalFit: true
324			},
325		});
326		
327		var $ombed_vids = $(".imarket-video-popup");
328		if( $ombed_vids.length > 0 ) {
329			$ombed_vids.each(function () {
330				var $mfp_popup_link_non_html5 = $(this);
331
332				$($mfp_popup_link_non_html5).magnificPopup({
333					disableOn: 320,
334					type: 'iframe',
335					mainClass: 'mfp-fade product-video-popup',
336					removalDelay: 160,
337					preloader: false,
338					fixedContentPos: false,
339					iframe: {
340						patterns: {
341							youtube: {
342								index: 'youtube.com/',
343								id: function(url) {
344									var m = url.match(/[\\?\\&]v=([^\\?\\&]+)/);
345									if ( !m || !m[1] ) return null;
346									return m[1];
347								},
348								src: '//www.youtube.com/embed/%id%?autoplay=1&rel=0'
349							},
350							youtu: {
351								index: 'youtu.be',
352								id: '/',
353								src: '//www.youtube.com/embed/%id%?autoplay=1&rel=0'
354							},
355							vimeo: {
356								index: 'vimeo.com/',
357								id: function(url) {
358									var m = url.match(/(https?:\/\/)?(www.)?(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/);
359									if ( !m || !m[5] ) return null;
360									return m[5];
361								},
362								src: '//player.vimeo.com/video/%id%?autoplay=1'
363							},
364						}
365					}
366				});
367			});
368		}		
369    };
370	
371	imarket.newsLetterPopup = function(){		
372		
373		if( !imarket_options.newsletter_args.newsletter_popup ){
374			return;
375		}
376		
377		var newsletter_popup 	= imarket_options.newsletter_args.newsletter_popup,
378			popup_display_on 	= imarket_options.newsletter_args.popup_display_on,
379			popup_delay 		= imarket_options.newsletter_args.popup_delay,
380			x_scroll 			= imarket_options.newsletter_args.popup_x_scroll,
381			show_for_mobile 	= parseInt(imarket_options.newsletter_args.show_for_mobile),
382			popup_exit 			= false,
383			startinterval 		= false,
384			newsletter_key 		= 'imarket_newsletter_closed_' + imarket_options.newsletter_args.version,
385			popup_closed 		= Cookies.get( newsletter_key ),
386			$news_letter_wrap 	= $(".imarket-newsletter-popup"),
387			from_button         = false;
388		if( !$news_letter_wrap.length) {
389			return false;
390		}
391		/* yith-woocompare */
392		if(jQuery(document).find('#yith-woocompare').length > 0){
393			return false;
394		}
395		
396		if( ! newsletter_popup || imarket_options.maintenance_mode || ( ! show_for_mobile && $(window).width() < 768 ) ){
397			return false; 
398		}
399		
400		/* newsletter popup opened from button on click by user
401		it must be enabled even if with 'do-not-show' cookie saved */
402		var newsletter_btn = $('.header-newsletter');
403		newsletter_btn.on('click',function(){
404			from_button = true;
405			show_popup();
406		});
407		
408		
409		if( popup_closed == 'do-not-show' ) {
410			return false; 
411		}
412		
413		if( popup_display_on == 'exit' ){
414			jQuery(document).on('mouseleave', function (e) {
415				show_popup();
416			});
417		}else if(popup_display_on == 'scroll'){
418
419            jQuery(window).scroll(function () {
420                var h = jQuery(document).height() - jQuery(window).height();
421                var sp = jQuery(window).scrollTop();
422                var p = parseInt(sp / h * 100);
423
424                if (p >= x_scroll) {
425                   show_popup();                
426                }
427            });
428        }else{
429			if( popup_delay ){
430				setTimeout(function(){show_popup(); }, popup_delay * 1000);	
431			}else{
432				show_popup();
433			}			         
434        }
435		
436		$news_letter_wrap.find('.mc4wp-form').submit(function () {
437            Cookies.set( newsletter_key , 'do-not-show', { expires: parseInt(imarket_options.newsletter_args.show_in_next_days), path: '/' });
438        });
439		
440		function show_popup() {
441			/* popup must open everytime if the user clicked to open it */
442			if(popup_exit && !from_button){
443				return;
444			}
445			
446			popup_exit = true;
447			$.magnificPopup.open({
448				type: 'inline',
449				removalDelay: 500,
450				items: {
451					src: '.imarket-newsletter-popup' ,					
452				},
453				callbacks: {
454					open: function () {
455						var popupWrap = $( '.imarket-newsletter-popup' );
456						popupWrap.addClass('animated slideInDown');
457						
458						/* donotshow div element must be hidden if the user clicked to open popup */
459						if (from_button){
460							$('#newsletter-donotshow').parent('div').hide();
461						}
462						
463					},							
464					beforeClose: function() {
465						var popupWrap = $( '.imarket-newsletter-popup' );
466						popupWrap.removeClass('slideInDown').addClass('slideOutUp');
467					}, 
468					close: function() {
469						this.content.removeClass('animated slideOutUp'); 
470						/* check box click */
471						if($('#newsletter-donotshow:checked') && $('#newsletter-donotshow:checked').val() == 'do-not-show'){
472							Cookies.set( newsletter_key , 'do-not-show', { expires: parseInt(imarket_options.newsletter_args.show_in_next_days), path: '/' });
473						}
474						
475						/* we restore the default visibility of donotshow div element if the user clicked to open popup */
476						if (from_button) {
477							$('#newsletter-donotshow').parent('div').show();
478							from_button = false;
479						}
480					}
481				},				
482			});
483		}
484	};
485	
486	imarket.imarketMegamenu = function(){
487		
488		var main_menu_wrap 				= $('.main-navigation').find('ul.menu');
489		
490		main_menu_wrap.on('mouseover', ' > li.imarket-megamenu-dropdown', function(e) {
491			setOffset( $(this) );
492		});
493		jQuery(window).resize(function() {
494			main_menu_wrap.on('mouseover', ' > li.imarket-megamenu-dropdown', function(e) {
495				setOffset( $(this) );
496			});
497		});
498
499		var setOffset = function( li ) {
500
501			var megaMenuWrapper 		= li.find(' > .imarket-megamenu-wrapper'),
502				megaMenuHolder 			= li.find(' .imarket-megamenu-holder');
503			
504			megaMenuWrapper.attr('style', '');
505
506			var container	 			= $('.site-header .container'),
507				containerWidth 			= container.outerWidth(),
508				containerOffsetLeft 	= container.offset().left + 15,
509				containerPaddingLeft 	= parseInt(container.css('padding-left')),
510				containerPaddingRight 	= parseInt(container.css('padding-right')),
511				viewportWidth 		  	= containerWidth - containerPaddingLeft - containerPaddingRight;
512				
513			if( li.hasClass( 'imarket-megamenu-item-full-width' ) ) { 
514				megaMenuHolder.css({
515					width: viewportWidth
516				});
517			}
518			
519			var	megaMenuWrapperWidth	= megaMenuWrapper.outerWidth(),
520				megaMenuWrapperOffset	= megaMenuWrapper.offset();		
521				
522			if( ! megaMenuWrapperWidth || ! megaMenuWrapperOffset ) return;
523			
524			var mega_menu_wrapOffsetRight = viewportWidth - megaMenuWrapperOffset.left - megaMenuWrapperWidth;
525			
526			if( $('body').hasClass('rtl') && mega_menu_wrapOffsetRight + megaMenuWrapperWidth + containerOffsetLeft >= viewportWidth && ( li.hasClass( 'imarket-megamenu-dropdown' ) ) ) {
527				
528				var toLeft = mega_menu_wrapOffsetRight + megaMenuWrapperWidth - viewportWidth + containerOffsetLeft;
529				megaMenuWrapper.css({
530					right: - toLeft
531				}); 
532
533			}else if( megaMenuWrapperOffset.left + megaMenuWrapperWidth - containerOffsetLeft >= viewportWidth && ( li.hasClass( 'imarket-megamenu-dropdown' ) ) ) {
534				
535				var toRight = megaMenuWrapperOffset.left + megaMenuWrapperWidth - viewportWidth - containerOffsetLeft;
536				megaMenuWrapper.css({
537					left: - toRight
538				}); 
539			}				
540		};	
541	}
542	
543	imarket.mobileMenu = function(){
544		/*
545		* Mobile menu
546		*/
547		
548		/* Menu wrapper */
549		$(document).on('click', '.mobile-nav-tabs li', function(e) {
550			if(!$(this).hasClass("active")){
551				var cn=$(this).data("menu");
552				$(this).parent().find(".active").removeClass("active");
553				$(this).addClass("active");
554				$(".mobile-nav-content").removeClass("active").fadeOut(300);
555				$(".mobile-"+cn+"-menu").addClass("active").fadeIn(300);
556			}
557		});
558		
559		/* Menu */
560		var $mobileMenu 	= $('.imarket-mobile-menu'),
561			$closeSidebar 	= $('.imarket-mask-overaly');
562		$( '.mobile-navbar .navbar-toggle' ).on( 'click', function ( e ) {
563			e.preventDefault();			
564			if ( ! $mobileMenu.hasClass('opened') ) {
565				$mobileMenu.addClass('opened');
566				$closeSidebar.addClass('opened');
567			}
568		});
569
570		$( '.mobile-main-menu li.menu-item-has-children' ).append( '<span class="menu-toggle"></span>' );
571		
572		$mobileMenu.on('click', '.menu-item-has-children > .menu-toggle', function (e) {
573			e.preventDefault();
574
575			$(this).closest('li').siblings().find('ul').slideUp();
576			$(this).closest('li').siblings().removeClass('active');
577			$(this).closest('li').siblings().find('li').removeClass('active');
578
579			$(this).closest('li').children('ul').slideToggle();
580			$(this).closest('li').toggleClass('active');
581
582		});
583		
584		imarket.$body.on('click', '.imarket-mask-overaly, .imarket-mobile-menu .close-sidebar', function (e) {
585			if ( $mobileMenu.hasClass( 'opened' ) ) {
586				$mobileMenu.removeClass('opened');
587				$closeSidebar.removeClass('opened');
588			}
589		});
590		
591		imarket.$window.on('resize', function () {
592			if ( imarket.$window.width() > 991 ) {
593				if ( $mobileMenu.hasClass( 'opened' ) ) {
594					$mobileMenu.removeClass('opened');
595					$closeSidebar.removeClass('opened');
596				}
597			}
598		});
599	};
600	
601	imarket.promoBar = function(){
602		/*
603		 * Promo Bar
604		 */
605		var $promo_bar 			= $( '.imarket-promo-bar' ),
606			$siteWrapper 		= $( '.site-wrapper' ),
607			$siteHeader 		= $( '.site-header' ),
608			$stickyElements 	= $( '.header-sticky' ),
609			position_type 		= $promo_bar.attr('data-position_type'),
610			position 			= $promo_bar.attr('data-position'),
611			promo_barHeight 	= $promo_bar.outerHeight(),
612			adminBarHeight 		= $('#wpadminbar').outerHeight();
613			
614		if( position == 'top' && position_type == 'fixed'){
615			$siteWrapper.css({'margin-top' : promo_barHeight + 'px'});
616		}
617		/* Set a cookie and hide Promo bar when the dismiss button is clicked */
618		var promo_bar_key = 'imarket_promo_bar_close';
619		$( '.promo-bar-close' ).on( 'click', function( event ) {
620			event.preventDefault();
621			if( $(this).hasClass('promo-bar-dismiss') ) {
622				Cookies.set( promo_bar_key, true, { path: '/',expires: parseInt(imarket_options.show_promobar_in_next_days) } );
623			}
624			if( position == 'top' && position_type == 'fixed'){
625				$siteWrapper.css({'margin-top' : '0px'});
626			}
627			if( position == 'top' && position_type == 'fixed'){
628				if(adminBarHeight){
629					if( $siteHeader.hasClass('header-sticked')){
630					$stickyElements.css({
631					'top': adminBarHeight+'px'
632				});
633				}
634				}else{
635					if( $siteHeader.hasClass('header-sticked')){
636							$stickyElements.css({
637							'top': '0px'
638						});
639						}
640				}
641			}
642			$promo_bar.slideUp('slow',function(){ $(this).remove();});
643			
644		});
645	};
646	
647	imarket.stickyHeader = function(){
648		/*
649		 *  Sticky Header.
650		 */
651		if( ! imarket_options.sticky_header ){
652			return;
653		}
654		var $header 			= $('.site-header'),
655			$headerStickyClass 	= $('.header-' + imarket_options.sticky_header_class),
656			$window 			= imarket.$window,
657			origPosition 		= $(window).scrollTop(),
658			isSticked 			= false;
659			
660		if ( ! $headerStickyClass.length > 0 ) {
661			$headerStickyClass = $('.header-main');
662		}
663		
664		$window.on('scroll', function () {
665			var windowWidth 	= $(window).width(),
666				headerHeight 	= $header.outerHeight(),
667				stickyOffset 	= headerHeight + 450;
668			imarket.promoBar();
669			
670			/* Disable sticky in desktop & tablet & mobile */
671			if( ( !imarket_options.sticky_header && windowWidth > 992 ) ||
672				( !imarket_options.sticky_header_tablet && ( windowWidth <= 992 && windowWidth > 576 ) ) ||
673				( !imarket_options.sticky_header_mobile && windowWidth <= 575 ) ) {
674				return false; 
675			}
676			
677			if( ( imarket_options.sticky_header_mobile && windowWidth < 575 ) ||  ( imarket_options.sticky_header_tablet && ( windowWidth <= 992 && windowWidth > 576 ) ) ){
678				$headerStickyClass 	= $('.header-main');
679			}else{
680				$headerStickyClass 	= $('.header-' + imarket_options.sticky_header_class)
681			}
682			
683			var currentScroll 	= $(this).scrollTop();
684			if ( currentScroll > stickyOffset ) {
685				stickHeader();
686			} else {
687				unstickHeader();
688			}
689		});
690		
691		function stickHeader() {
692			if ( isSticked ) { 
693				return; 
694			}
695			isSticked = true;
696			
697			var adminBarHeight = 0, promo_top = 0, offset_top = 0;
698			
699			if( $('#wpadminbar').length > 0 ){
700				adminBarHeight 	= $('#wpadminbar').outerHeight();
701			}
702			
703			if( $('.position-top.position-type-fixed').length > 0 ){
704				promo_top 	= $('.position-top.position-type-fixed').outerHeight();
705			}
706			
707			offset_top = adminBarHeight + promo_top; 
708			
709			$header.addClass('fixed');
710			$headerStickyClass.addClass('header-sticked');
711			$('.open-categories-menu .categories-menu-wrapper').removeClass('opened-categories');
712			$headerStickyClass.css({
713				'top': offset_top+'px'
714			});
715		}
716
717		function unstickHeader() {
718			if ( !isSticked ) { 
719				return;
720			}
721			isSticked = false;
722			$header.removeClass('fixed');
723			$headerStickyClass.removeClass('header-sticked');
724			$('.open-categories-menu .categories-menu-wrapper').addClass('opened-categories');
725			$headerStickyClass.css({
726				'top': 0
727			});
728		}
729	}
730	
731	imarket.StickyHeaderScrollUP = function(){
732		/*
733		 * Sticky header on ScrollUp
734		 */		
735		if ( ! imarket_options.sticky_header ||  ! imarket_options.sticky_header_scroll_up) { return; }
736				
737		var origPosition 		= $(window).scrollTop(),			
738			$headerStickyClass 	= $('.header-' + imarket_options.sticky_header_class);
739		
740		if ( ! $headerStickyClass.length > 0 ) {
741			$headerStickyClass = $('.header-main');
742		}
743		if(  imarket.$windowWidth  < 1023 ){			
744			$headerStickyClass = $('.themejr-header-main');
745		}
746		$(window).scroll(function(e) {
747			var currentScroll = $(window).scrollTop();
748			if( currentScroll > origPosition ) {
749				$headerStickyClass.removeClass( 'scroll-up' ).addClass( 'scroll-down' );
750			} else {
751				$headerStickyClass.removeClass( 'scroll-down' ).addClass( 'scroll-up' );
752			}
753			origPosition = currentScroll;
754		});
755	};
756	
757	imarket.stickySidebar = function(){
758		/*
759		 *  Sticky Sidebar.
760		 */
761		if ( ! imarket_options.sticky_sidebar ) { return; }
762		
763		if ( typeof ( $.fn.stick_in_parent ) != 'undefined' ) {
764			$(document).ready(function(){
765				if( $( window ).width() <= 768  ) { return; }
766				
767				var sticky_sidebar = $( '#secondary .sidebar-inner' );	
768				var offset = 15;
769				
770				if ( $( '#header .header-sticked' )[0] ) {
771					offset = $( '#header .header-sticked' ).height() + 30;
772				}
773				
774				sticky_sidebar.stick_in_parent({ offset_top: offset });
775				
776				$( window ).resize(function() {
777					if ( $( window ).width() <= 768 ) {
778						sticky_sidebar.trigger( 'sticky_kit:detach' );					
779					}else{
780						sticky_sidebar.stick_in_parent({
781							offset_top: offset
782						});
783					}
784				});
785			});
786		}
787	};
788	
789	imarket.canvasSidebar = function(){
790		/*
791		 *  Canvas Sidebar.
792		 */
793		
794		var sidebar_canvas 		= $('.imarket-canvas-sidebar .canvas-sidebar-icon, .imarket-product-off-canvas-btn, .imarket-mobile-navbar .canvas-sidebar-icon');
795		var secondary 			= $('#secondary');
796        var closeSidebar 		= $('.imarket-mask-overaly');
797		
798		sidebar_canvas.on('click', function(e) {
799			e.preventDefault();	
800			
801			if ( ! secondary.hasClass('opened') ) {
802				secondary.addClass('opened');
803				setTimeout(function() {imarket.imagelazyload();}, 1000);
804				closeSidebar.addClass('opened');
805			}					
806		});
807		
808		imarket.$body.on('click', '.imarket-mask-overaly, .close-sidebar', function (e) {
809			e.preventDefault();
810			secondary.removeClass('opened');
811			closeSidebar.removeClass('opened');
812		});	
813		
814		imarket.$window.on('resize', function () {
815			if ( imarket.$window.width() > 767 ) {
816				if ( secondary.hasClass( 'opened' ) ) {
817					secondary.removeClass('opened');
818					closeSidebar.removeClass('opened');
819				}
820			}
821		});
822		
823	};
824	
825	imarket.openMiniSearch = function(){
826		//*******************************************************************
827		//* openMiniSearch
828		//*******************************************************************/
829		
830		var sidebar_canvas 	= $('a.search-icon-text');
831		var search_popup 	= $('.imarket-search-popup');
832		var closeSidebar 	= $('.imarket-search-popup .close-sidebar');
833		
834		sidebar_canvas.on('click', function(e) {
835			e.preventDefault();
836			
837			if ( ! search_popup.hasClass('opened') ) {
838				search_popup.addClass('opened');
839			}					
840		});
841		
842		closeSidebar.on('click', function(e) {
843			e.preventDefault();
844			
845			if ( search_popup.hasClass('opened') ) {
846				search_popup.removeClass('opened');
847			}					
848		});		
849	};
850	
851	imarket.widgetMenuToggle = function(){
852		//*******************************************************************
853		//* Widget Menu Toggle
854		//*******************************************************************/
855		
856		if( imarket_options.widget_menu_toggle) {
857			/* Wordpress Menu widget */ 
858			$('#secondary .widget .menu-item > a').each(function(){ 
859				if( $(this).siblings('ul.sub-menu').length > 0 ) {
860					var $childIndicator = $('<span class="child-indicator"></span>');
861
862					$(this).siblings('.sub-menu').hide();
863					$('.current-menu-item > .sub-menu').show();
864					$('.current-menu-parent > .sub-menu').show();
865					if($(this).siblings('.sub-menu').is(':visible')){
866						$childIndicator.addClass( 'open-item' );
867					}
868
869					$childIndicator.on( 'click', function(){
870						$(this).parent().siblings('.sub-menu').toggle( 'fast', function(){
871							if($(this).is(':visible')){
872								$childIndicator.addClass( 'open-item' );
873							}else{
874								$childIndicator.removeClass( 'open-item' );
875							}
876						});
877						return false;
878					});
879					$(this).append($childIndicator);
880				}
881			});
882			
883			/* Product/Category widget */
884			$('#secondary .widget .cat-item > a').each(function(){
885				if( $(this).siblings('ul.children').length > 0 ) {
886					var $childIndicator = $('<span class="child-indicator"></span>');
887
888					$(this).siblings('.children').hide();
889					$('.current-cat > .children').show();
890					$('.current-cat-parent > .children').show();
891					if($(this).siblings('.children').is(':visible')){
892						$childIndicator.addClass( 'open-item' );
893					}
894
895					$childIndicator.on( 'click', function(){
896						$(this).parent().siblings('.children').toggle( 'fast', function(){
897							if($(this).is(':visible')){
898								$childIndicator.addClass( 'open-item' );
899							}else{
900								$childIndicator.removeClass( 'open-item' );
901							}
902						});
903						return false;
904					});
905					
906					if( ! $(this).find('.child-indicator').length > 0 ){
907						$(this).append($childIndicator);
908					}
909				}
910			});
911		}		
912	};
913	
914	imarket.widgetToggle = function(){
915		//*******************************************************************
916		//* Widget Menu Toggle
917		//*******************************************************************/		
918		if( imarket_options.widget_toggle) {
919			$( document ).find('.widget-area .widget').addClass('widget-toggle').removeClass('closed');
920			$( document ).on( 'click', '.widget-area .widget .widget-title, .dokan-widget-area .widget .widget-title', function(e) {
921				e.stopImmediatePropagation();
922				if ($(this).next().is(':visible')){
923                    $(this).parent().addClass('closed');
924                } else {
925                    $(this).parent().removeClass('closed');
926                }
927                $(this).next().stop().slideToggle(200);
928			});			
929		}
930	};
931	
932	imarket.footerWidgetCollapse = function(){
933		//*******************************************************************
934		//* Footer Widget Collapse
935		//*******************************************************************/	
936		if ($(window).width() > 576) {
937			return;
938		}
939		$( document ).on( 'click', '.imarket-mobile-device .footer-widget-collapse .widget .widget-title', function(e) {
940			var $title 		= $(this);
941			var $widget 	= $title.parent();
942			var $content 	= $widget.find('> *:not(.widget-title)');
943
944			if ($widget.hasClass('footer-widget-opened')) {
945				$widget.removeClass('footer-widget-opened');
946				$content.stop().slideUp(200);
947			} else {
948				$widget.addClass('footer-widget-opened');
949				$content.stop().slideDown(200);
950			}
951					
952		});
953				
954	};
955	
956	imarket.widgetMaxLimitItem = function(){
957		//*******************************************************************
958		//* Widget Hide Max Limit Item
959		//*******************************************************************/
960		if( imarket_options.widget_hide_max_limit_item) {
961			var js_translate_text = imarket_options.js_translate_text;
962			$('#secondary .widget .widget-title + ul,#footer .widget .widget-title + ul').hideMaxListItems({
963				'max': imarket_options.number_of_show_widget_items,
964				'speed': 500,
965				'moreText': js_translate_text.show_more,
966				'lessText': js_translate_text.show_less
967			});
968		}
969	};
970	
971	imarket.imarketOwlCarousel = function() { 
972		/*
973		 * Owl carousel slider
974		 */
975
976		if ( imarketOwlArg.length === 0 || typeof imarketOwlArg.owlCarouselArg === 'undefined' ) {
977			return; 
978		}
979		
980		function add_owl_overlayclass(){
981			$('.owl-stage-outer .product-wrapper').mouseenter(function(){
982				var slider_elemnt = $(this).closest('.products.imarket-carousel');
983				slider_elemnt.find('.owl-stage-outer').addClass('overlay');
984			}).mouseleave(function(){
985				var slider_elemnt = $(this).closest('.products.imarket-carousel');
986				slider_elemnt.find('.owl-stage-outer').removeClass('overlay');
987			});
988		}
989		setTimeout(function() {add_owl_overlayclass()}, 1000)
990		$.each( imarketOwlArg.owlCarouselArg, function ( id, owlCarouselArg ) {
991			
992			var loop 				= ( owlCarouselArg.slider_loop ) ? true : false,
993				autoplay 			= ( owlCarouselArg.slider_autoplay ) ? true : false,							
994				autoplayHoverPause 	= ( autoplay && owlCarouselArg.slider_autoplayHoverPause ) ? true : false,
995				autoplaytimeout 	= owlCarouselArg.slider_autoplaytimeout,
996				smartspeed 			= parseInt(owlCarouselArg.slider_smartspeed),
997				
998				rewind 				= ( owlCarouselArg.slider_rewind ) ? true : false,
999				nav 				= ( owlCarouselArg.slider_nav ) ? true : false,				
1000				nav_mobile			= ( owlCarouselArg.slider_nav_mobile ) ? true : false,				
1001				center 				= ( owlCarouselArg.slider_center ) ? true : false,				
1002				dots 				= ( owlCarouselArg.slider_dots ) ? true : false,
1003				autoHeight 			= ( owlCarouselArg.slider_autoHeight ) ? true : false,
1004				touchDrag			= ( owlCarouselArg.slider_touchDrag ) ? true : false,
1005				touchDrag_mobile	= ( owlCarouselArg.slider_touchDrag_mobile ) ? true : false,
1006				animateIn 			= owlCarouselArg.slider_animatein,
1007				animateOut 			= owlCarouselArg.slider_animateout,
1008				margin 				= owlCarouselArg.slider_margin,
1009				rs_extra_large 		= ( owlCarouselArg.rs_extra_large > 0 ) ? owlCarouselArg.rs_extra_large : 4,
1010				rs_large 			= ( owlCarouselArg.rs_large > 0 ) ? owlCarouselArg.rs_large : 4,
1011				rs_medium 			= ( owlCarouselArg.rs_medium > 0 ) ? owlCarouselArg.rs_medium : 3,
1012				rs_small 			= ( owlCarouselArg.rs_small > 0 ) ? owlCarouselArg.rs_small : 2,
1013				rs_extra_small 		= ( owlCarouselArg.rs_extra_small > 0 ) ? owlCarouselArg.rs_extra_small : 2,
1014				numItems 			= null,
1015				slider_element 		= null;
1016				
1017			if($('#'+id).hasClass('imarket-carousel')){
1018				numItems 			= $( '#'+id ).children().length;
1019				slider_element 		= $( '#'+id );
1020			}else{
1021				numItems 			= $( '#'+id).find( '.imarket-carousel').children().length;
1022				slider_element 		= $( '#'+id ).find( '.imarket-carousel');
1023			}
1024				
1025			slider_element.owlCarousel({				
1026				autoplay			: autoplay,
1027				autoplayHoverPause	: autoplayHoverPause,
1028				autoplayTimeout		: autoplaytimeout,
1029				smartSpeed 			: smartspeed,
1030				rewind				: rewind,				
1031				nav					: nav,
1032				center				: center,
1033				navText				: ['',''],
1034				dots				: dots,
1035				autoHeight			: autoHeight,
1036				touchDrag			: touchDrag,				
1037				animateIn			: animateIn,
1038				animateOut			: animateOut,
1039				margin				: margin,
1040				rtl 				: ( imarket.isCheckRTL() ) ? true : false,
1041				responsive			: {
1042					0:{
1043						items	: rs_extra_small,
1044						loop	: ( numItems >= rs_extra_small && loop) ? true : false,
1045						nav		: nav_mobile,
1046						mouseDrag: false,
1047						touchDrag: touchDrag_mobile						
1048					},
1049					576:{
1050						items	: rs_small,
1051						loop	: ( numItems >= rs_small && loop) ? true : false,
1052						nav		: nav_mobile,
1053						mouseDrag: false,
1054						touchDrag: touchDrag_mobile	
1055					},
1056					768:{
1057						items	: rs_medium,
1058						loop	: ( numItems >= rs_medium && loop) ? true : false,
1059						nav		: nav_mobile,
1060					},
1061					1025:{
1062						items	: rs_large,
1063						loop	: ( numItems >= rs_large && loop) ? true : false,
1064					},					
1065					1200:{
1066						items 	: rs_extra_large,
1067						loop	: ( numItems >= rs_extra_large && loop) ? true : false,
1068					}
1069				},
1070				onInitialized: function(){
1071					slider_element.addClass('owl-theme');
1072				}
1073			}).on('changed.owl.carousel', function(event) {
1074				imarket.imagelazyload();
1075			}).on('translated.owl.carousel', function(event) {
1076				imarket.imagelazyload();
1077			});		
1078
1079		} );	
1080	};
1081	
1082	imarket.MasonryGrid = function (){
1083		
1084		/*
1085		* Init Masonry grid
1086		*/
1087		if($( '.articles-list.masonry-grid' ).length){
1088			 imarket.$body.imagesLoaded(function () {
1089				imarket.$body.find('.articles-list.masonry-grid').isotope({
1090					itemSelector: '.type-post',
1091					layoutMode: 'masonry'
1092				});
1093			});			
1094		}
1095	};
1096	
1097	imarket.postGalleryCarousel = function (){
1098		/*
1099		*  Post Gallery Carousel
1100		*/
1101		$('.imarket-gallery-carousel').owlCarousel({
1102			loop			: true,
1103			autoplay 		: false,
1104			autoplayTimeout : 3000,
1105			rtl 			: ( imarket.isCheckRTL() ) ? true : false,
1106			/* rewind		: true, */
1107			smartSpeed		: 750,
1108			nav 			: true,
1109			navText			: ['',''],
1110			dots			: true,		
1111			items			: 1
1112		});
1113		$( '.imarket-gallery-carousel').addClass('owl-theme owl-center');
1114	};
1115	
1116	imarket.loadmorePosts = function(){
1117		
1118		$('.imarket-blog-load-more .imarket-load-more').on('click',function(){
1119			
1120			var load_more_btn = $(this);
1121			var page = parseInt(load_more_btn.parent().attr('data-page'));
1122			var data_attr = load_more_btn.parent().data();
1123			var	atts = data_attr.attribute;
1124			var post_wrap = load_more_btn.closest('.imarket-element').find('.articles-list');
1125            var wrap_id = load_more_btn.closest('.imarket-element').attr('id');
1126			var data = {
1127				action: 'imarket_loadmore_posts',
1128				nonce: imarket_options.nonce,
1129				attr: atts,
1130				page: page,
1131			};
1132			if(load_more_btn.hasClass('process')){ return false;}
1133			imarket.loadAjaxPost(load_more_btn,data,post_wrap,wrap_id);
1134		});
1135		var animationFrame = function () {
1136			$('.imarket-blog-load-more a.infinity-scroll').each(function (i, val) {
1137				var load_more_btn = $(this);
1138				var page = parseInt(load_more_btn.parent().attr('data-page'));
1139				var post_wrap = load_more_btn.closest('.imarket-element').find('.articles-list');
1140				var wrap_id = load_more_btn.closest('.imarket-element').attr('id');
1141				var bottomOffset = post_wrap.offset().top + post_wrap.height() - $(window).scrollTop();
1142				if (bottomOffset < window.innerHeight && bottomOffset > 0) {
1143					if(load_more_btn.hasClass('process')){ 
1144						imarket.isPostLoading = true;
1145					}else{
1146						imarket.isPostLoading = false;
1147					}
1148					var page = parseInt(load_more_btn.parent().attr('data-page'));
1149					if(!load_more_btn.hasClass('imarket-loadmore-disabled')){ 
1150						load_more_btn.trigger('click');
1151					}
1152				}
1153			});
1154		}
1155		
1156		var scrollHandler = function () {
1157			requestAnimationFrame(animationFrame);
1158		};                    
1159		$(window).scroll(scrollHandler);
1160	}
1161	
1162	imarket.socialShare = function (){
1163		/*
1164		* Social Share
1165		*/
1166		imarket.$doc.on('click', '.social-print', function(){
1167			window.print();
1168			return false;
1169		});
1170
1171		/*
1172		 * Open Share buttons in a popup
1173		 */
1174		imarket.$doc.on('click', '.social-share a', function(){
1175			var link = jQuery(this).attr('href');
1176			if( link != '#' ){
1177				window.open( link, 'TIEshare', 'height=450,width=760,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0' );
1178				return false;
1179			}
1180		});
1181	};
1182	
1183	imarket.portfolioFilters = function (){		
1184		/*
1185		* Portfolio Filters
1186		*/
1187		
1188		if ( ! $('.portfolios-list').length > 0 ) return;
1189		var $layoutMode='masonry';
1190		
1191		if($( '.portfolios-list' ).length){
1192			$( '.portfolios-list' ).each(function(){
1193				if($( this ).hasClass('simple-grid') ){
1194					$layoutMode='fitRows';
1195				}
1196				var portfolio_container = $( this );
1197				/* initialize Masonry after all images have loaded */
1198                portfolio_container.imagesLoaded(function() {
1199					portfolio_container.isotope({
1200						itemSelector: '.portfolio-post-loop',
1201						isOriginLeft: ! $('body').hasClass('rtl'),
1202						layoutMode: $layoutMode
1203					});
1204				 });
1205			});			
1206		}
1207		
1208		$('.filter-categories').on('click', 'a', function(e) {
1209			e.preventDefault();
1210			
1211			var $portfolio_container = $(this).closest('.portfolio-filter').next('.portfolios-list');
1212			if($portfolio_container.hasClass('simple-grid') ){
1213				$layoutMode='fitRows';
1214			}	
1215			$(this).closest('.portfolio-filter').find('.active').removeClass('active');
1216			$(this).addClass('active');
1217			var filterValue = $(this).attr('data-filter');
1218			$portfolio_container.isotope({
1219				filter		: filterValue,
1220				layoutMode	: $layoutMode,
1221			});
1222		});
1223		
1224	};
1225	
1226	imarket.portfolioLoadMore = function () {
1227		
1228		$('.imarket-portfolio-load-more .imarket-load-more').on('click',function(){
1229						
1230			var $this = $(this),
1231				portfolio_wrap = $this.parent().parent().parent().find('.portfolios-list'),
1232				data_attr = $this.parent().data(),
1233				atts = data_attr.attribute,
1234				page = parseInt($this.parent().attr('data-page')),
1235				load_more_label = data_attr.load_more_label,
1236				loading_finished_msg = data_attr.loading_finished_msg;
1237				$this.addClass('request-running');
1238			if($this.hasClass('imarket-loadmore-disabled')){
1239				return;
1240			}
1241			$this.html('<span class="loading"> '+imarket_options.js_translate_text.loading_txt+'</span>');
1242			var data = {
1243					attr: atts,
1244					page: page,
1245					nonce: imarket_options.nonce,
1246					action: 'imarket_loadmore_portfolios',
1247				};
1248		
1249			$.ajax({
1250				url: imarket_options.ajax_url,
1251				data: data,
1252				dataType: 'json',
1253				method: 'POST',
1254				success: function (response) {
1255
1256					var portfolio_items = $(response.html);
1257					if (portfolio_items) {
1258						if (portfolio_wrap.hasClass('masonry-grid')) {
1259							/* initialize Masonry after all images have loaded */
1260							portfolio_wrap.append(portfolio_items).isotope('appended', portfolio_items);
1261							portfolio_wrap.imagesLoaded().progress(function () {
1262								portfolio_wrap.isotope('layout');								
1263							});
1264						} else {
1265							portfolio_wrap.append(portfolio_items).isotope('appended', portfolio_items);
1266							portfolio_wrap.imagesLoaded().progress(function () {
1267								portfolio_wrap.isotope('layout');								
1268							});
1269						}						
1270					}
1271					if ($.trim(response.show_bt) == '0') {
1272						$this.addClass('disabled imarket-loadmore-disabled').html(loading_finished_msg);
1273					} else {
1274						$this.parent().attr('data-page', page + 1);					
1275						$this.html(load_more_label);
1276					}
1277
1278				},
1279				error: function (response) {
1280					console.log('ajax error');
1281				},
1282				complete: function () {
1283					imarket.isPostLoading = false;
1284					imarket.initMagnaficPopup();			
1285					$this.removeClass('request-running');	
1286				},
1287			});
1288					
1289		});
1290		
1291		
1292		var animationFrame = function () {
1293			$('.imarket-portfolio-load-more a.infinity-scroll').each(function (i, val) {
1294				var $this = $(this),
1295				portfolio_wrap = $this.parent().parent().parent().find('.portfolios-list');
1296				var bottomOffset = portfolio_wrap.offset().top + portfolio_wrap.height() - $(window).scrollTop();
1297				if (bottomOffset < window.innerHeight && bottomOffset > 0) {
1298					if($this.hasClass('request-running')){ 
1299						imarket.isPostLoading = true;
1300					}else{
1301						imarket.isPostLoading = false;
1302					}
1303					
1304					if(!$this.hasClass('imarket-loadmore-disabled')){ 
1305						if(!imarket.isPostLoading){
1306							imarket.isPostLoading = true;
1307							$this.trigger('click');
1308						}
1309					}
1310				}
1311			});
1312		}
1313		
1314		var scrollHandler = function () {
1315			requestAnimationFrame(animationFrame);
1316		};                    
1317		$(window).scroll(scrollHandler);
1318		
1319	};
1320	
1321	/* Imarket product live search */
1322	imarket.productLiveSearch = function () {
1323		
1324		if ( ! imarket_options.product_ajax_search ) { return false; }
1325		
1326		$('.trending-search-wrap').hide();
1327		 var serviceUrl = imarket_options.ajax_url + '?action=imarket_ajax_search';
1328		$('.imarket-ajax-search').each(function(){
1329			
1330			var append 				= $(this).find('.search-results-wrapper'),
1331				container 			= $(this),
1332				search_categories 	= $(this).find('.categories-filter'),
1333				product_cat 		= '';
1334			
1335			if (search_categories.length && search_categories.val() !== '') {
1336				product_cat = search_categories.val();
1337			}
1338			$(this).find('.search-field').keyup(function(){
1339				 var search_text = $(this).val();
1340				 if(search_text.length < 3){
1341					$('.trending-search-wrap').show();
1342				 }else{
1343					 $('.trending-search-wrap').hide();
1344				 }
1345			});
1346			 $(this).find('.search-field').focus(function() {
1347				 var search_text = $(this).val();
1348				 if(search_text.length < 3){
1349					$('.trending-search-wrap').show();
1350				 }else{
1351					 $('.trending-search-wrap').hide();
1352				 }
1353			});
1354			$(this).find('.search-field').focusout(function() {
1355			});
1356			$(this).find('.search-field').devbridgeAutocomplete({
1357				minChars        : 3,
1358				appendTo        : append,
1359				triggerSelectOnValidInput: false,
1360				serviceUrl      : serviceUrl,
1361				type            : 'POST',
1362				params : { 'product_cat' : product_cat,nonce: imarket_options.nonce },
1363				onSearchStart   : function () { 
1364					container.find('.search-submit').removeClass('imarket-spinner');
1365					container.find('.search-submit').addClass('imarket-spinner');
1366					$('.trending-search-wrap').hide();
1367				},
1368				onSearchComplete: function () { 
1369					container.find('.search-submit').removeClass('imarket-spinner');
1370				},
1371				beforeRender: function (container) {					
1372					$(container).removeAttr('style');
1373				},
1374				formatResult: function (suggestion, currentValue) {
1375					
1376						var pattern = '(' + $.Autocomplete.utils.escapeRegExChars(currentValue) + ')';
1377						var html = '';
1378						if (suggestion.id != -1) {
1379							html += '<a href="'+suggestion.url+'" title="'+ suggestion.value +'">';
1380						} 
1381						if(suggestion.img) html += '<img class="search-image" src="'+suggestion.img+'">';
1382						html += '<div class="search-name">'+suggestion.value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')+'</div>';
1383						if(suggestion.price || suggestion.rating ) {
1384							html += '<div class="serch-price-rating">';
1385							if(suggestion.price) html += '<span class="search-price">'+suggestion.price+'</span>';
1386							if(suggestion.rating) html += '<span class="search-rating">'+suggestion.rating+'</span>';
1387							html += '</div>';
1388						}
1389						if (suggestion.id != -1) {
1390							html += '</a>';
1391						} 
1392						return html;
1393					}
1394			});
1395
1396			if( search_categories.length ){
1397				var searchForm = $(this).find('.search-field').devbridgeAutocomplete();
1398
1399				search_categories.on( 'change', function( e ){
1400
1401					if( search_categories.val() != '' ) {
1402						product_cat = search_categories.val();
1403						searchForm.setOptions({
1404							params : { 'product_cat' : product_cat, nonce: imarket_options.nonce }
1405							
1406						});
1407					} else{
1408						searchForm.setOptions({
1409							params : { 'product_cat' : '', nonce: imarket_options.nonce }
1410						});
1411					}
1412					// update suggestions
1413					searchForm.hide();
1414					searchForm.onValueChange();
1415				});
1416			}
1417		});
1418		 
1419		/* Hide .trending-search-wrap */
1420		$(document).mouseup(function (e){
1421			var container = $(".imarket-ajax-search");			
1422			if (!container.is(e.target) && container.has(e.target).length === 0){				
1423				$(".trending-search-wrap").hide();				
1424			}
1425		}); 
1426	};
1427	
1428	imarket.swapLoginSignupFrom = function () {
1429		/*
1430		* Swap Login Signup Form
1431		*/
1432		var userSignup 	= $('.new-signup');
1433		var userSignin	= $('.user-signin');
1434		
1435		userSignup.on('click', function(e) {
1436			e.preventDefault();	
1437			$('.customer-login').removeClass('active')
1438			$('.customer-signup').addClass('active');
1439			
1440		});
1441		userSignin.on('click', function(e) {
1442			e.preventDefault();
1443			$('.customer-signup').removeClass('active');
1444			$('.customer-login').addClass('active');
1445			
1446		});
1447	}
1448	
1449	imarket.userLoginSignupPopup = function () {
1450		/*
1451		* User Login Signup Popup
1452		*/
1453
1454		if( !imarket_options.login_register_popup || $('body').hasClass('woocommerce-account') )  return false;
1455		
1456		$('.customer-signinup').magnificPopup({
1457			type: 'inline',
1458			preloader: false,			
1459			removalDelay: 500,
1460			items: {
1461				src: '#imarket-signin-up-popup' ,					
1462			},
1463			/* mainClass: 'animated bounceIn', */
1464			callbacks: {
1465				open: function() {
1466					var closeSidebar 	= $('.imarket-mask-overaly');
1467					var mobileSidebar = $('.imarket-mobile-menu');
1468					closeSidebar.removeClass('opened');
1469					mobileSidebar.removeClass('opened');
1470					$('.imarket-signin-up-popup').addClass('animated slideInDown');
1471				},
1472				beforeClose: function() {
1473						var popupWrap = $( '.imarket-signin-up-popup' );
1474						popupWrap.removeClass('slideInDown').addClass('slideOutUp');
1475					}, 
1476				close: function() {
1477					$('.imarket-signin-up-popup').removeClass('animated slideOutUp');
1478					$('.imarket-signin-up-popup').find('.signin-up-error-message').remove();
1479				}
1480			} 
1481		});				
1482	};
1483	
1484	imarket.miniCartWidget = function () {
1485		/*
1486		 * Mini Cart Widget Sidebar
1487		 */
1488		 
1489		if ( 'slider' != imarket_options.header_minicart_popup ) { return false; }
1490
1491		var headerCart 		= $('.header-cart');
1492		var miniCartSidebar = $('.imarket-minicart-slide');
1493        var closeSidebar 	= $('.imarket-mask-overaly');
1494		var mobileSidebar = $('.imarket-mobile-menu');
1495		
1496		
1497		headerCart.on('click', function(e) {
1498			
1499			if( $('body').hasClass('woocommerce-cart') || $('body').hasClass('woocommerce-checkout') ) { return; };
1500			
1501			e.preventDefault();
1502			imarket.imagelazyload();
1503			if ( ! miniCartSidebar.hasClass('opened') ) {
1504				miniCartSidebar.addClass('opened');
1505				closeSidebar.addClass('opened');				
1506			}
1507			setTimeout(function(){
1508			 imarket.imagelazyload();
1509			}, 200);
1510
1511			
1512		});
1513		
1514		imarket.$body.on('click', '.imarket-mask-overaly, .close-sidebar', function (e) {
1515			e.preventDefault();
1516			miniCartSidebar.removeClass('opened');
1517			closeSidebar.removeClass('opened');
1518			mobileSidebar.removeClass('opened');
1519		});	
1520		 
1521		imarket.$doc.keyup( function( e ) {
1522            if ( e.keyCode === 27 ) {
1523				miniCartSidebar.removeClass('opened');
1524				closeSidebar.removeClass('opened');
1525			}
1526        });
1527	};
1528	
1529	imarket.addToWishlist = function(){
1530		/*
1531		* Add wishlist loader
1532		*/
1533       imarket.$body.on("click", ".add_to_wishlist", function() {
1534		  /*  Bootstrap tooltips hide */
1535			var tooltip_hide = ('.yith-wcwl-add-to-wishlist a');			
1536			$(tooltip_hide).tooltip('hide');
1537			
1538            $(this).addClass("loading");
1539        });
1540	}
1541	
1542	imarket.wishlistCount = function(){
1543		/*
1544		* Ajax Count Wishlist Product
1545		*/
1546		
1547		var imarket_ajax_wishlist_count = function() {
1548			$.ajax({
1549				type: 'POST',
1550				url: yith_wcwl_l10n.ajax_url,
1551				data      : {
1552					action	: 'imarket_ajax_wishlist_count',
1553					nonce   : imarket_options.nonce,
1554				},
1555				beforeSend: function () {
1556				},
1557				complete  : function () {
1558				},			
1559				success   : function (data) {
1560					$('span.header-wishlist-count').html(data);
1561					imarket.tooltip();
1562				}
1563			});
1564		};
1565		$('body').on( 'added_to_wishlist removed_from_wishlist', imarket_ajax_wishlist_count );
1566	};
1567	
1568	
1569	imarket.compareCount = function(){
1570		//*******************************************************************
1571		//* Ajax Count Compare Product
1572		//*******************************************************************/
1573		
1574		$('body').on( 'yith_woocompare_open_popup woocompare_open_popup_mod', function () {				
1575			$.ajax({
1576				type: 'post',
1577				url: imarket_options.ajax_url,
1578				data      : {
1579					action: 'imarket_ajax_compare_count',
1580					nonce	: imarket_options.nonce,
1581				},
1582				beforeSend: function () { 
1583				},
1584				complete  : function () { 
1585				},	
1586				success: function (response) { 
1587					$('span.header-compare-count').html(response);				
1588				},
1589				error: function(errorThrown){
1590					/* alert(errorThrown); */
1591			   } 
1592			});
1593		});
1594
1595		$(window).on('yith_woocompare_product_removed', function () {
1596			$('body').trigger('woocompare_open_popup_mod');
1597		});
1598		
1599		/* Remove product in compare product widget */
1600		$('.yith-woocompare-widget').on('click', 'li a.remove, a.clear-all', function (e) {
1601
1602			e.preventDefault();
1603			var product_id = $(this).data('product_id');
1604			
1605			$.ajax({
1606				type: 'post',
1607				url: imarket_options.ajax_url,
1608				data      : {
1609					action	: 'imarket_ajax_compare_count',
1610					nonce	: imarket_options.nonce,
1611					id		: product_id
1612				},
1613				beforeSend: function () { 
1614				},
1615				complete  : function () { 
1616				},	
1617				success: function (response) { 
1618					$('label.compare-count').html(response);				
1619				},
1620				error: function(errorThrown){
1621					/* alert(errorThrown); */
1622			   } 
1623			});
1624
1625		});
1626	};
1627	imarket.addToCompare = function () {
1628		
1629		/*
1630		* Add to compare list
1631		*/
1632		var button = $("a.compare");
1633
1634        imarket.$body.on("click", "a.compare", function() {
1635            $(this).addClass("loading");
1636        });
1637
1638        imarket.$body.on("yith_woocompare_open_popup", function() {
1639			
1640           imarket.$body.find('.compare').removeClass('loading');
1641           imarket.$body.addClass("compare-opened");
1642        });
1643
1644        imarket.$body.on('click', '#cboxClose, #cboxOverlay', function() {
1645            imarket.$body.removeClass("compare-opened");
1646        });
1647	}
1648	
1649	imarket.removeToCompare = function () {
1650		/*
1651		* Remove to compare list
1652		*/
1653		
1654		$(document).find('.compare-list').on('click', '.remove a', function (e) {
1655            e.preventDefault();
1656			$(this).addClass('loading');
1657            var compare_counter = $('.header-compare-count', window.parent.document).html();
1658            compare_counter = parseInt(compare_counter, 10) - 1;
1659            if (compare_counter < 0) {
1660                compare_counter = 0;
1661            }
1662
1663            $('.header-compare-count', window.parent.document).html(compare_counter);
1664        });
1665		
1666		imarket.$body.on("click", ".yith-woocompare-widget li a.remove", function(e) {
1667            e.preventDefault();
1668            var compare_counter = $(document).find('.header-compare-count').html();
1669            compare_counter = parseInt(compare_counter, 10) - 1;
1670            if (compare_counter < 0) {
1671                compare_counter = 0;
1672            }
1673
1674            setTimeout(function () {
1675                $(document).find('.header-compare-count').html(compare_counter);
1676            }, 2000);
1677
1678        });
1679
1680        imarket.$body.on("click", ".yith-woocompare-widget a.clear-all", function(e) {
1681            e.preventDefault();
1682            setTimeout(function () {
1683                $(document).find('.header-compare-count').html('0');
1684            }, 2000);
1685        });
1686		
1687		
1688	}
1689	
1690	imarket.ProductLoopQuantityField = function () {
1691		/*
1692		* Product Quantity Field
1693		*/		
1694		
1695		$(".woocommerce .product-buttons").on("change input", ".quantity .qty", function () {
1696		  var add_to_cart_button = $(this).parents(".product").find(".add_to_cart_button");
1697		  add_to_cart_button.attr("data-quantity", $(this).val());
1698		});
1699		$(".woocommerce .product-buttons").on("keypress", ".quantity .qty", function (e) {
1700		  if ((e.which || e.keyCode) === 13) {
1701			$(this).parents(".product").find(".add_to_cart_button").trigger("click");
1702		  }
1703		});
1704	}
1705	
1706	imarket.addToCart = function () {
1707		/*
1708		 *  Adding to cart
1709		 */
1710		 $('body').on('added_to_cart', function(event, fragments, cart_hash) {
1711			$.magnificPopup.close();
1712			if( $('.header-cart').length > 0 ) {
1713				if ( imarket_options.mini_cart_popup == '1' ) {
1714					$('.header-cart').trigger('click');
1715				}
1716			}
1717		 });
1718	};
1719	
1720	imarket.addToCartAjax = function () {
1721		/*
1722		 *  Adding to cart Ajax
1723		 */
1724		if ( ! imarket_options.enable_add_to_cart_ajax ) { return; }
1725		
1726		$('.single_add_to_cart_button').addClass('single_add_to_cart_ajax_button');
1727		imarket.$body.find('form.cart').on('click', '.single_add_to_cart_button', function (e) {
1728			 
1729			var $productWrapper = $(this).parents('.single-product-page');
1730            if ($productWrapper.hasClass('product-type-external')) return;          
1731
1732            var $form = $(this).closest('form.cart'),
1733                $singleBtn =  $(this),
1734				product_id = $form.find('input[name=add-to-cart]').val() || $singleBtn.val();
1735			if ($singleBtn.hasClass('disabled')) {
1736				return;
1737			}
1738			if ($singleBtn.hasClass('quick-buy-proceed')) {
1739				return;
1740			}
1741			if ($form.length > 0) {
1742                e.preventDefault();
1743            } else {
1744                return;
1745            }
1746			var data = {
1747				action			: 'imarket_ajax_add_to_cart',
1748				'add-to-cart'	: product_id,
1749				nonce   		: imarket_options.nonce,
1750			};
1751
1752			$form.serializeArray().forEach(function (element) {
1753				data[element.name] = element.value;
1754			});
1755			if ($singleBtn.hasClass('loading')) {
1756				return;
1757			}
1758			$singleBtn.addClass('loading');
1759			
1760			$(document.body).trigger('adding_to_cart', [$singleBtn, data]);
1761			$.ajax({
1762				type: 'post',
1763				url: imarket_options.ajax_url,
1764				data: data,
1765				beforeSend: function (response) {
1766					$singleBtn.removeClass('added').removeClass('not-added');
1767				},
1768				success: function (response) {
1769					if (response.error & response.product_url) {
1770					  window.location = response.product_url;
1771					  return;
1772					} else {
1773						if (typeof wc_add_to_cart_params !== 'undefined') {
1774							if (wc_add_to_cart_params.cart_redirect_after_add === 'yes') {
1775								window.location = wc_add_to_cart_params.cart_url;
1776								return;
1777							}
1778						}					
1779						
1780						/* Show notices */
1781                        if( response.notices.indexOf( 'error' ) > 0 ) {
1782                            $('.woocommerce-notices-wrapper').empty().append(response.notices);
1783							$singleBtn.addClass('not-added').removeClass('loading');
1784                        } else {
1785                            if ( imarket_options.product_open_cart_mini == '1' ) {
1786								$('.header-cart').trigger('click');
1787							}
1788							$singleBtn.addClass('added').removeClass('loading');
1789                            $(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $singleBtn]);
1790                        }
1791						
1792					}
1793				},
1794			});
1795			
1796		});
1797	};
1798	
1799	imarket.stickyAddToCart = function(){
1800		/*
1801		* Sticky Add To Cart Bottom Button
1802		*/	
1803		
1804		if ( ! $('body').hasClass( 'single-product' ) || $('.imarket-sticky-add-to-cart').length == 0 || $(window).width() < 992 || $('.entry-summary form .single_add_to_cart_button').length == 0 ) {
1805			return;
1806		}
1807		
1808		$('body').on( 'click', '.imarket-sticky-add-to-cart .button', function (event) {
1809			event.preventDefault();			
1810			if( $(this).hasClass('variable') || $(this).hasClass('grouped') ){				
1811				$('html, body').animate({
1812					scrollTop: $(".variations").offset().top - 70
1813				}, 1000);
1814			}else{
1815				$(this).addClass('loading');
1816				$( '.entry-summary .single_add_to_cart_button' ).click();
1817				event.stopPropagation();				
1818			}
1819		});
1820		
1821		$(document.body).on( 'added_to_cart', function () {			
1822			$('.imarket-sticky-add-to-cart .button').removeClass('loading');
1823		});
1824		
1825		var cartButtonOffset = $('.entry-summary form .single_add_to_cart_button').offset().top;
1826		
1827		$(window).scroll(function(e) {			
1828			var documentHeight = $(document).height();
1829			var windowHeight = $(this).height();
1830			var scrollTop = $(this).scrollTop();
1831			var bottomscroll = parseInt( windowHeight + scrollTop ) + 100;
1832			
1833			if ( scrollTop > cartButtonOffset ) {
1834				$('.imarket-sticky-add-to-cart').slideDown();
1835				$('.imarket-back-to-top').addClass('sticky-add-cart');
1836			} else if ( scrollTop < cartButtonOffset) {
1837				$('.imarket-sticky-add-to-cart').slideUp(); /* Hide on bottom */
1838				$('.imarket-back-to-top').removeClass('sticky-add-cart');
1839			}
1840		});		
1841	};
1842	
1843	imarket.productQuickView = function () {
1844		/*
1845		* Product Quickview
1846		*/		
1847		imarket.$doc.on("click", ".quickview-btn", function(e) {
1848            e.preventDefault();
1849			var $btn = $(this),pid;
1850			if($btn.hasClass('loading')) return;
1851			$btn.addClass('loading');
1852			var pid           = $btn.attr( 'data-id' );
1853			$.ajax( {
1854				url    : imarket_options.ajax_url,
1855				data   : {
1856					action	: 'imarket_product_quick_view',
1857					pid   	: pid,
1858					nonce   : imarket_options.nonce,
1859				},
1860				timeout: 10000,
1861				success: function( response ) {
1862					$.magnificPopup.open({
1863						alignTop: true,
1864						removalDelay: 500,
1865						overflowY: 'scroll',
1866						items: {
1867						  src: '<div class="animated slideInDown imarket-quick-view woocommerce">' + response + '</div>', 
1868						  type: 'inline'
1869						},
1870						callbacks: {
1871							open: function () {
1872														
1873							},
1874							close: function () {
1875								imarket.singlePageSwatch();						
1876							},
1877							beforeClose: function() {
1878								var quickViewWrap = $( '.imarket-quick-view' );
1879								quickViewWrap.addClass('slideOutUp');
1880							},
1881						},
1882					});
1883					
1884					if( $('.woocommerce-product-gallery').find( '.single-product-gallery' ).length > 0 ) {
1885						$( '.single-product-gallery' ).not( '.slick-initialized' ).slick({
1886							slidesToShow	: 1,
1887							slidesToScroll	: 1,
1888							rtl				: ( imarket.isCheckRTL() ) ? true : false,
1889						});
1890					}
1891					$('.product-quick-view .woocommerce-product-gallery__image a').on('click', function(e){
1892						e.stopPropagation();
1893						e.preventDefault();
1894					});
1895					setTimeout(function() {
1896						var form_variation = $( '.product-quick-view' ).find( '.variations_form' );
1897						if ( form_variation.length > 0 ) {
1898							form_variation.trigger( 'check_variations' );
1899							form_variation.trigger( 'reset_image' );						
1900							form_variation.wc_variation_form();
1901							form_variation.find( 'select' ).change();
1902							imarket.singlePageSwatch();
1903							
1904						}
1905					}, 1000);
1906					
1907					
1908					$btn.removeClass( 'loading' );
1909					
1910					imarket.productSaleCountdown();
1911					imarket.addToCartAjax();
1912					imarket.productQuickShop();
1913					imarket.tooltip();
1914					imarket.imagelazyload();
1915					
1916				},
1917				error  : function( error ) {
1918					console.log( error );
1919					$btn.removeClass( 'loading' );
1920				},
1921
1922			} );
1923        });
1924	}
1925	imarket.productShowFilter = function () {
1926		$('.product-show .show-number').on('change', function () {
1927			 if ( !imarket.$body.hasClass('imarket-catalog-ajax-filter') ) {
1928				$( this ).closest( 'form' ).submit();
1929			}
1930      });
1931	}
1932	
1933	/* Get price js slider */
1934	imarket.priceSlider = function () {
1935		/* woocommerce_price_slider_params is required to continue, ensure the object exists */
1936		if (typeof woocommerce_price_slider_params === 'undefined') {
1937			return false;
1938		}
1939		
1940		if (!$('#main-content').find('.widget_price_filter').length) {
1941			return false;
1942		}
1943		
1944		/* Get markup ready for slider */
1945		$('input#min_price, input#max_price').hide();
1946		$('.price_slider, .price_label').show();
1947
1948		/* Price slider uses jquery ui */
1949		var min_price = $('.price_slider_amount #min_price').data('min'),
1950			max_price = $('.price_slider_amount #max_price').data('max'),
1951			current_min_price = parseInt(min_price, 10),
1952			current_max_price = parseInt(max_price, 10);
1953
1954		if ($('.price_slider_amount #min_price').val() != '') {
1955			current_min_price = parseInt($('.price_slider_amount #min_price').val(), 10);
1956		}
1957		if ($('.price_slider_amount #max_price').val() != '') {
1958			current_max_price = parseInt($('.price_slider_amount #max_price').val(), 10);
1959		}
1960
1961		$(document.body).on('price_slider_create price_slider_slide', function (event, min, max) {
1962			if (woocommerce_price_slider_params.currency_pos === 'left') {
1963
1964				$('.price_slider_amount span.from').html(woocommerce_price_slider_params.currency_symbol + min);
1965				$('.price_slider_amount span.to').html(woocommerce_price_slider_params.currency_symbol + max);
1966
1967			} else if (woocommerce_price_slider_params.currency_pos === 'left_space') {
1968
1969				$('.price_slider_amount span.from').html(woocommerce_price_slider_params.currency_symbol + ' ' + min);
1970				$('.price_slider_amount span.to').html(woocommerce_price_slider_params.currency_symbol + ' ' + max);
1971
1972			} else if (woocommerce_price_slider_params.currency_pos === 'right') {
1973
1974				$('.price_slider_amount span.from').html(min + woocommerce_price_slider_params.currency_symbol);
1975				$('.price_slider_amount span.to').html(max + woocommerce_price_slider_params.currency_symbol);
1976
1977			} else if (woocommerce_price_slider_params.currency_pos === 'right_space') {
1978
1979				$('.price_slider_amount span.from').html(min + ' ' + woocommerce_price_slider_params.currency_symbol);
1980				$('.price_slider_amount span.to').html(max + ' ' + woocommerce_price_slider_params.currency_symbol);
1981
1982			}
1983
1984			$(document.body).trigger('price_slider_updated', [min, max]);
1985		});
1986		if (typeof $.fn.slider !== 'undefined') {
1987			$('.price_slider').slider({
1988				range  : true,
1989				animate: true,
1990				min    : min_price,
1991				max    : max_price,
1992				values : [current_min_price, current_max_price],
1993				create : function () {
1994
1995					$('.price_slider_amount #min_price').val(current_min_price);
1996					$('.price_slider_amount #max_price').val(current_max_price);
1997
1998					$(document.body).trigger('price_slider_create', [current_min_price, current_max_price]);
1999				},
2000				slide  : function (event, ui) {
2001
2002					$('input#min_price').val(ui.values[0]);
2003					$('input#max_price').val(ui.values[1]);
2004
2005					$(document.body).trigger('price_slider_slide', [ui.values[0], ui.values[1]]);
2006				},
2007				change : function (event, ui) {
2008
2009					$(document.body).trigger('price_slider_change', [ui.values[0], ui.values[1]]);
2010				}
2011			});
2012		}
2013	};
2014	
2015	imarket.productShowHideFilters = function () {
2016		$('.archive.woocommerce').on('click','.imarket-product-filter-btn',function(e) {
2017			var $this = $(this),
2018			filter_content = $('#imarket-filter-widgets');
2019			$this.toggleClass("active");
2020			filter_content.toggleClass('active');
2021			filter_content.slideToggle('slow');			
2022      });
2023	}
2024	
2025	imarket.productFilterAjax = function () {
2026		if (!imarket.$body.hasClass('imarket-catalog-ajax-filter')) {
2027			return;
2028		}
2029		/* Price range filter*/
2030		$(document.body).on('price_slider_change', function (event, ui) {
2031			var form = $('.price_slider').closest('form').get(0),
2032			$form = $(form),
2033			url = $form.attr('action') + '?' + $form.serialize();
2034			$(document.body).trigger('imarket_shop_filter_ajax', url, $(this));
2035		});
2036		imarket.$body.on('click', '.widget_product_categories ul a, .widget_rating_filter ul a, .widget_layered_nav_filters ul a, .widget_product_tag_cloud a', function (e) {
2037            e.preventDefault();
2038            var url = $(this).attr('href');
2039            $(document.body).trigger('imarket_shop_filter_ajax', url, $(this));
2040        });
2041		imarket.$body.on('click','.products-view a',function(e) {			
2042			e.preventDefault();
2043			var $this = $(this),
2044			url = $this.attr('href');			
2045			$this.siblings().removeClass("active");
2046			$this.addClass('active');
2047			$(document.body).trigger('imarket_shop_filter_ajax', url, $this);
2048		});
2049		
2050		/* Shop paginataion filter*/
2051		$('.archive.woocommerce').on('change','.product-show .show-number',function(e) {			
2052			e.stopPropagation();
2053			var $this = $(this);
2054			var url = window.location.href.replace(/&per_page(=[^&]*)?|^per_page(=[^&]*)?&?/g, '').replace(/\?per_page(=[^&]*)?|^per_page(=[^&]*)?&?/g, '?').replace(/\?$/g, '');
2055
2056			if (url.indexOf('?') !== -1) {
2057				url = url + ('&per_page=' + $this.val());
2058			} else {
2059				url = url + ('?per_page=' + $this.val());
2060			}			
2061			$(document.body).trigger('imarket_shop_filter_ajax', url, $this);
2062		});		
2063		
2064		/* Shop paginataion filter*/
2065		$( document ).on( 'click', '.imarket-pagination .page-numbers:not(.current)', function(e) {
2066			e.preventDefault();
2067			var $this = $(this);
2068			var url = $this.attr('href');
2069			
2070			$(document.body).trigger('imarket_shop_filter_ajax', url, $this);
2071		});
2072		
2073		$('.archive.woocommerce').find('.woocommerce-ordering').off('change');
2074		$('.archive.woocommerce').on('change','.woocommerce-ordering',function(e) {
2075			var $this = $(this);
2076			var $select = $(e.currentTarget).find('.orderby');
2077			var url = window.location.href.replace(/&orderby(=[^&]*)?|^orderby(=[^&]*)?&?/g, '').replace(/\?orderby(=[^&]*)?|^orderby(=[^&]*)?&?/g, '?').replace(/\?$/g, '');
2078
2079			if (url.indexOf('?') !== -1) {
2080				url = url + ('&orderby=' + $select.val());
2081			} else {
2082				url = url + ('?orderby=' + $select.val());
2083			}
2084			$(document.body).trigger('imarket_shop_filter_ajax', url, $this);
2085		});
2086		
2087				
2088		/* Sorting filter*/
2089		$('.archive.woocommerce').on('click','.imarket_widget_product_sorting li',function(e) {
2090			e.preventDefault();
2091			var $this = $(this);
2092			var element = $this.find('a');
2093			var url = $this.find('a').attr('href');
2094			$this.siblings().removeClass("chosen");
2095			if($this.hasClass('chosen')){
2096                $this.removeClass('chosen');
2097            }else{
2098                $this.addClass('chosen');
2099            };
2100			
2101			$(document.body).trigger('imarket_shop_filter_ajax', url, element);
2102			
2103		});
2104		/* Clear filter*/
2105		$('.archive.woocommerce').on('click','.widget_layered_nav_filters a, .imarket-clear-filters-wrapp a',function(e) {
2106			e.preventDefault();
2107			var $this = $(this);
2108			
2109			var url = $this.attr('href');
2110			
2111			$(document.body).trigger('imarket_shop_filter_ajax', url, $this);
2112			
2113		});
2114		/* Attribute/Rating filter*/
2115		$('.archive.woocommerce').on('click','.widget_layered_nav li,.widget_rating_filter li,.widget_layered_nav_filters li',function(e) {
2116			e.preventDefault();
2117			var $this = $(this);
2118			var element = $this.find('a');
2119			var url = $this.find('a').attr('href');
2120			
2121			if($this.hasClass('chosen')){
2122                $this.removeClass('chosen');
2123            }else{
2124                $this.addClass('chosen');
2125            };
2126			
2127			$(document.body).trigger('imarket_shop_filter_ajax', url, element);
2128			
2129		});
2130		
2131		$(document.body).on('imarket_shop_filter_ajax', function (e, url, element) {
2132
2133			var $page_title = $('#page-title'),
2134				$product_container = $('#main-content .products-wrap'),
2135			    $main_content = $('#main-content');
2136				
2137			$('#imarket-filter-widgets').slideUp(200);
2138			if ($product_container.length > 0) {
2139				var position = $('.products').offset().top - 200;
2140				$('html, body').stop().animate({
2141						scrollTop: position
2142					},
2143					1200
2144				);
2145			}
2146			
2147			if ('?' == url.slice(-1)) {
2148				url = url.slice(0, -1);
2149			}
2150
2151			url = url.replace(/%2C/g, ',');
2152
2153			history.pushState(null, null, url);
2154
2155			$(document.body).trigger('imarket_ajax_filter_before_send_request', [url, element]);
2156
2157			if (imarket.ajaxXHR) {
2158				imarket.ajaxXHR.abort();
2159			}
2160	
2161			imarket.ajaxXHR = $.get(url, function (res) {
2162				$main_content.replaceWith($(res).find('#main-content'));
2163                $page_title.replaceWith($(res).find('#page-title').clone());
2164				$(document.body).trigger('imarket_ajax_filter_request_end', [res, url]);
2165			}, 'html');
2166		});
2167		
2168		$(document.body).on('imarket_ajax_filter_before_send_request', function () {
2169			
2170			var $product_container = $('#main-content .products-wrap');
2171			$product_container.addClass('products_overlay');
2172			$product_container.append('<div class="imarket_product_loading loading"></div>');
2173			$('#secondary').removeClass('opened');
2174			$('.imarket-mask-overaly').removeClass('opened');
2175			
2176		});
2177		
2178		$(document.body).on('imarket_ajax_filter_request_end', function () {
2179			imarket.imagelazyload();
2180			imarket.priceSlider();
2181			imarket.imarketOwlCarousel();
2182			imarket.imarketElementorOwlCarousel();
2183			imarket.initAjaxLoad();
2184			imarket.tooltip();
2185			imarket.widgetToggle();
2186			imarket.widgetMenuToggle();
2187			imarket.widgetMaxLimitItem();
2188			imarket.stickySidebar();
2189			imarket.swatchInLoop();
2190			imarket.productQuickView();
2191			imarket.canvasSidebar();
2192			$('.imarket-mask-overaly').removeClass('opened');
2193		});
2194	}	
2195	
2196	imarket.productSwatch = function(){
2197		this.singlePageSwatch();
2198		this.swatchInLoop();
2199	}
2200	imarket.singlePageSwatch = function () {	
2201		
2202		var variationForm;
2203		if( imarket.$doc.find( '.imarket-quick-view form.imarket-swatches-wrap.variations_form' ).length && !imarket.$doc.find( '.imarket-quick-view' ).hasClass( 'slideOutUp' ) ){
2204			variationForm 	= imarket.$doc.find( '.imarket-quick-view form.imarket-swatches-wrap.variations_form' );
2205		}else{
2206			variationForm 	= imarket.$doc.find( 'form.imarket-swatches-wrap.variations_form' );
2207		}
2208		var self 			= this,					
2209			$term 			= variationForm.find( '.swatch-term' ),
2210			$activeTerm 	= variationForm.find( '.swatch-term:not(.swatch-disabled)' );
2211		self.$swatchForm	= variationForm;
2212		
2213		$activeTerm.off( 'click' ).on( 'click', function () {
2214
2215			var $this 		= $( this ),
2216				term 		= $this.attr( 'data-term' ),
2217				attr 		= $this.parent().attr( 'data-attribute' ),
2218				$selectbox 	= self.$swatchForm.find( 'select#' + attr );
2219
2220			if ( $this.hasClass( 'swatch-disabled' ) ) {
2221				return false;
2222			}
2223
2224			$selectbox.val( term ).trigger( 'change' );
2225			$this.closest('.imarket-swatches').find( '.swatch-selected' ).removeClass( 'swatch-selected' );
2226			$this.addClass( 'swatch-selected' );
2227		} );
2228
2229		self.$swatchForm.on( 'woocommerce_update_variation_values',
2230			function () {
2231				
2232				self.$swatchForm.find( 'select' ).each( function () {
2233					var $this 		= $( this );
2234					var $swatch 	= $this.parent().parent().find( '.imarket-swatches' );
2235					
2236					$swatch.find( '.swatch-term' ).removeClass( 'swatch-enabled' ).addClass( 'swatch-disabled' );
2237
2238					$this.find( 'option.enabled' ).each( function () {
2239						var val 	= $( this ).val();
2240						$swatch.find(
2241							'.swatch-term[data-term="' + val + '"]' ).removeClass( 'swatch-disabled' ).addClass( 'swatch-enabled' );
2242					} );
2243				} );
2244			} );
2245
2246		self.$swatchForm.on( 'reset_data', function () {
2247			
2248		/* load default value */
2249		$term.each( function () {
2250			var $this = $( this ),
2251				term = $this.attr( 'data-term' ),
2252				attr = $this.parent().attr( 'data-attribute' ),
2253				$selectbox = self.$swatchForm.find( 'select#' + attr ),
2254				val = $selectbox.val();				
2255			if ( val != '' && term == val ) {				
2256				$( this ).addClass( 'swatch-selected' );
2257			}else{
2258				$( this ).removeClass( 'swatch-selected' );
2259			}
2260		} );
2261		
2262		} );
2263
2264	}
2265	imarket.swatchInLoop = function(){
2266		var self 			= this,
2267		swatchesInLoop 		= imarket.$doc.find( '.product-variations div.imarket-swatches-wrap' );
2268		self.$swatches 		= swatchesInLoop;
2269		self.$swatches.each( function () {
2270			var $swatches 	= $( this ),
2271			$term 			= $swatches.find(
2272				'.swatch-term:not(.swatch-disabled)' ),
2273			$resetBtn 		= $swatches.find(
2274				'.reset_variations--loop' ),
2275			$product 		= $swatches.closest('.product'),
2276			variationData 	= $.parseJSON(
2277			$swatches.attr( 'data-product_variations' ) );
2278			
2279			if ( $swatches.find( '.imarket-swatches' ).length == 0 ) {
2280				$swatches.addClass( 'swatch-empty' );
2281			}
2282			
2283			$term.unbind( 'click' ).on( 'click', function () {
2284
2285				var $this = $( this );
2286
2287				if ( $this.hasClass( 'swatch-disabled' ) ) {
2288					return false;
2289				}
2290
2291				var term = $this.attr( 'data-term' );				
2292				
2293				$product.find( '.swatch-term' ).removeClass( 'swatch-disabled swatch-enabled' );
2294				$this.parent().find( '.swatch-term.swatch-selected' ).removeClass( 'swatch-selected' );
2295
2296				if ( $this.hasClass( 'swatch-selected' ) ) {
2297					$this.parent().removeClass( 'swatch-activated' );
2298					$product.removeClass( 'swatch-product-swatched' );
2299
2300					if ( !$product.find( '.swatch-selected' ).length ) {
2301						$resetBtn.trigger( 'click' );
2302					}
2303				} else {
2304					$this.parent().addClass( 'swatch-activated' );
2305					$this.addClass( 'swatch-selected' );
2306
2307					$product.addClass( 'swatch-product-swatched' );
2308					/* $resetBtn.show(); */
2309				}
2310				
2311				var attributes 			= self.getChosenAttributes(
2312					$swatches ),
2313					currentAttributes 	= attributes.data;
2314				if ( attributes.count === attributes.chosenCount ) {
2315					self.updateAttributes( $swatches, variationData );
2316
2317					var matching_variations = self.findMatchingVariations(
2318						variationData, currentAttributes ),
2319						variation = matching_variations.shift();
2320
2321					if ( variation ) {
2322						/* Found variation */
2323						self.foundVariation( $swatches, variation );
2324					} else {
2325						
2326						$resetBtn.trigger( 'click' );
2327					}
2328				} else {
2329					
2330					self.updateAttributes( $swatches, variationData );
2331				} 
2332
2333			} );
2334			
2335			$resetBtn.unbind( 'click' ).on( 'click', function () {
2336
2337				$product.removeClass( 'swatch-product-swatched' );
2338
2339				$swatches.removeAttr( 'data-variation_id' );
2340				$swatches.find( '.swatch-swatch' ).removeClass( 'swatch-activated' );
2341				$swatches.find( '.swatch-term' ).removeClass(
2342					'swatch-enabled swatch-disabled swatch-selected' );
2343				
2344				/* reset image */
2345				self.variationsImageUpdate( false, $product );
2346
2347				$( this ).hide();
2348
2349				return false;
2350			} );					
2351		});
2352	};
2353	
2354	imarket.getChosenAttributes = function ( $swatches ) {
2355
2356		var data = {},
2357			count = 0,
2358			chosen = 0,
2359			$swatch = $swatches.find( '.imarket-swatches' );
2360
2361		$swatch.each( function () {
2362				var attribute_name = 'attribute_' +
2363						$( this ).attr( 'data-attribute' ),
2364					value = $( this ).find( '.swatch-term.swatch-selected' ).attr( 'data-term' ) || '';
2365
2366				if ( value.length > 0 ) {
2367					chosen++;
2368				}
2369
2370				count++;
2371				data[ attribute_name ] = value;			
2372		} );
2373
2374		return {
2375			'count': count,
2376			'chosenCount': chosen,
2377			'data': data,
2378		};
2379	}
2380	
2381	imarket.updateAttributes = function ( $swatches, variationData ) {
2382
2383		var self = this,
2384			attributes = self.getChosenAttributes( $swatches ),
2385			currentAttributes = attributes.data,
2386			available_options_count = 0,
2387			$swatch = $swatches.find( '.imarket-swatches' );
2388
2389		$swatch.each( function ( idx, el ) {
2390
2391			var current_attr_sw = $( el ),
2392				current_attr_name = 'attribute_' +
2393					current_attr_sw.attr(
2394						'data-attribute' ),
2395				selected_attr_val = current_attr_sw.find(
2396					'.swatch-term.swatch-selected' ).attr( 'data-term' ),
2397				selected_attr_val_valid = true,
2398				checkAttributes = $.extend( true, {},
2399					currentAttributes );
2400			
2401			checkAttributes[ current_attr_name ] = '';
2402			
2403			var variations = self.findMatchingVariations(
2404				variationData, checkAttributes );
2405			
2406			/* Loop through variations. */
2407			for (var num in variations) {
2408				if ( typeof variations[ num ] !== 'undefined' ) {
2409					var variationAttributes = variations[ num ].attributes;
2410
2411					for (var attr_name in variationAttributes) {
2412						if ( variationAttributes.hasOwnProperty(
2413								attr_name ) ) {
2414							var attr_val = variationAttributes[ attr_name ],
2415								variation_active = '';
2416							
2417							if ( attr_name === current_attr_name ) {
2418								if ( variations[ num ].variation_is_active ) {
2419									variation_active = 'enabled';
2420								}
2421								
2422								if ( attr_val ) {
2423									/* available */
2424									current_attr_sw.find(
2425										'.swatch-term[data-term="' + attr_val + '"]' ).addClass( 'swatch-' 
2425+ variation_active );
2426								}
2427								else {
2428									/* apply for all swatches */
2429									current_attr_sw.find( '.swatch-term' ).addClass( 'swatch-' + variation_active );
2430								}
2431							}
2432						}
2433					}
2434				}
2435			}
2436
2437			available_options_count = current_attr_sw.find(
2438				'.swatch-term.swatch-enabled' ).length;
2439
2440			if ( selected_attr_val && (
2441					available_options_count === 0 || current_attr_sw.find(
2442						'.swatch-term.swatch-enabled[data-term="' +
2443						self.addSlashes( selected_attr_val ) + '"]' ).length ===
2444					0
2445				) ) {
2446				selected_attr_val_valid = false;
2447			}
2448
2449			/* Disable terms not available */
2450			current_attr_sw.find( '.swatch-term:not(.swatch-enabled)' ).addClass( 'swatch-disabled' );
2451
2452			/* Choose selected value. */
2453			if ( selected_attr_val ) {
2454				/* If the previously selected value is no longer available,
2455				fall back to the placeholder (it's going to be there). */
2456				if ( !selected_attr_val_valid ) {
2457					current_attr_sw.find( '.swatch-term.swatch-selected' ).removeClass( 'swatch-selected' );
2458				}
2459			}
2460			else {
2461				current_attr_sw.find( '.swatch-term.swatch-selected' ).removeClass( 'swatch-selected' );
2462			}
2463		} );
2464	}
2465	
2466	imarket.addSlashes = function ( string ) {
2467		string = string.replace( /'/g, '\\\'' );
2468		string = string.replace( /"/g, '\\\"' );
2469		return string;
2470	}
2471
2472	imarket.findMatchingVariations = function ( variationData, settings ) {
2473		var matching = [];
2474		for (var i = 0; i < variationData.length; i++) {
2475			var variation = variationData[ i ];
2476
2477			if ( this.isMatch( variation.attributes, settings ) ) {
2478				matching.push( variation );
2479			}
2480		}
2481		return matching;
2482	}
2483
2484	imarket.isMatch = function ( variation_attributes, attributes ) {
2485		var match = true;
2486		for (var attr_name in variation_attributes) {
2487			if ( variation_attributes.hasOwnProperty( attr_name ) ) {
2488				var val1 = variation_attributes[ attr_name ];
2489				var val2 = attributes[ attr_name ];
2490				if ( val1 !== undefined && val2 !== undefined &&
2491					val1.length !== 0 && val2.length !== 0 &&
2492					val1 !== val2 ) {
2493					match = false;
2494				}
2495			}
2496		}
2497		return match;
2498	}
2499
2500	imarket.foundVariation = function ( $swatches, variation ) {
2501
2502		var self = this,
2503		$product = $swatches.closest( '.product' );
2504		/* add variation id */
2505		$swatches.attr( 'data-variation_id', variation.variation_id );
2506
2507		/* update image */
2508		self.variationsImageUpdate( variation, $product );
2509		
2510	}
2511
2512	/**
2513	 * Stores a default attribute for an element so it can be reset later
2514	 */
2515	imarket.setVariationAttr = function ( $el, attr, value ) {
2516		if ( undefined === $el.attr( 'data-o_' + attr ) ) {
2517			$el.attr( 'data-o_' + attr, (
2518				!$el.attr( attr )
2519			) ? '' : $el.attr( attr ) );
2520		}
2521		if ( false === value ) {
2522			$el.removeAttr( attr );
2523		}
2524		else {
2525			$el.attr( attr, value );
2526		}
2527	}
2528
2529	/**
2530	 * Reset a default attribute for an element so it can be reset later
2531	 */
2532	imarket.resetVariationAttr = function ( $el, attr ) {
2533		if ( undefined !== $el.attr( 'data-o_' + attr ) ) {
2534			$el.attr( attr, $el.attr( 'data-o_' + attr ) );
2535		}
2536	}
2537
2538	imarket.variationsImageUpdate = function ( variation, $product ) {
2539
2540		var self = this,
2541			$product_img = $product.find( 'img.front-image' );
2542		
2543		if ( variation && variation.image_src && variation.image.src && variation.image_src.length > 1 ) {			
2544			self.setVariationAttr( $product_img, 'src',
2545				variation.image_src[ 0 ] );
2546			self.setVariationAttr( $product_img, 'srcset',
2547				variation.image_srcset );
2548			self.setVariationAttr( $product_img, 'sizes',
2549				variation.image_sizes );
2550		} else {
2551			self.resetVariationAttr( $product_img, 'src' );
2552			self.resetVariationAttr( $product_img, 'srcset' );
2553			self.resetVariationAttr( $product_img, 'sizes' );
2554		}
2555
2556	}
2557	
2558	imarket.initAjaxLoad = function(){ 
2559		var button = $( '.imarket-ajax-load' );
2560
2561		button.each( function( i, val ) {
2562			var _option = $( this ).data();
2563			
2564			if ( _option !== undefined ) {
2565				var page      = _option.total_page,
2566					container = _option.container,
2567					container_element = _option.container_element,
2568					layout    = _option.layout,
2569					load_more_label    = _option.load_more_label,
2570					loading_finished_msg    = _option.loading_finished_msg,
2571					loading_msg    = imarket_options.js_translate_text.loading_txt,					
2572					isLoading = false,
2573					anchor    = $( val ).find( 'a' ),
2574					next      = $( anchor ).attr( 'href' ),
2575					i         = 2;
2576
2577				if ( layout == 'load-more-button' ) {
2578					$( val ).on( 'click', 'a', function( e ) {
2579						e.preventDefault();
2580						anchor = $( val ).find( 'a' );
2581						next   = $( anchor ).attr( 'href' );
2582
2583						$( anchor ).html( '<span class="loading"> '+loading_msg+'</span>' );
2584						
2585						getData();
2586					});
2587				}  else if( layout == 'infinity-scroll' ) {
2588					var waiting = false,
2589						endScrollHandle;
2590						imarket.$window.on('scroll', function () {
2591							
2592							if (imarket.$body.find('.infinity-scroll').is(':in-viewport')) {
2593								
2594								imarket.$body.find('.infinity-scroll a').trigger('click');
2595							}
2596						}).trigger('scroll');
2597						
2598						imarket.$body.on('click', '.imarket-pagination a.button', function (e) {
2599							if ( waiting ) {
2600								return;
2601							}
2602							waiting = true;
2603							e.preventDefault();
2604							
2605							var $el = $(this);
2606							$el.html( '<span class="loading"> '+loading_msg+'</span>' );
2607							if ($el.data('requestRunning')) {
2608								return;
2609							}
2610
2611							$el.data('requestRunning', true);
2612
2613							var $pagination = $el.closest('.imarket-pagination'),								
2614								container = _option.container,
2615								container_element = _option.container_element,
2616								$products = $pagination.prev('.'+container),
2617								href = $el.attr('href');
2618							
2619							
2620							$.get(
2621								href,
2622								function (response) {
2623									
2624									var content = $(response).find('#primary .'+ container).children('.'+container_element),
2625										$pagination_html = $(response).find('.imarket-pagination').html();
2626
2627									$pagination.html($pagination_html);
2628
2629									if ($('.masonry-grid').length > 0) {
2630							
2631										$products.append(content).isotope( 'appended', content );
2632										$products.imagesLoaded().progress(function() {
2633											$products.isotope('layout');
2634										});
2635									
2636									}else{
2637										$products.append(content);
2638									}
2639						
2640									$pagination.find('a').data('requestRunning', false);
2641									waiting = false;
2642									imarket.initMagnaficPopup();
2643									/* imarket.priceSlider(); */
2644									imarket.imarketOwlCarousel();
2645									imarket.imarketElementorOwlCarousel();
2646									imarket.tooltip();
2647									imarket.imagelazyload();
2648									imarket.widgetToggle();
2649									imarket.widgetMenuToggle();
2650									imarket.widgetMaxLimitItem();
2651									imarket.canvasSidebar();
2652									imarket.stickySidebar();
2653									imarket.ProductLoopQuantityField();
2654									imarket.productQuickView();
2655									imarket.addToCompare();
2656									imarket.productSwatch();
2657									$(document.body).trigger('imarket_shop_ajax_loading_end');
2658								}
2659							);
2660						});
2661				} 
2662				var getData = function() {
2663					$.get( next + '', function( data ) {
2664						var content    = $( '.' + container, data ).wrapInner( '' ).html(),
2665							newElement = $( '.' + container, data ).find( '.' + container_element );
2666						next = $( anchor, data ).attr( 'href' );
2667						if ($('.masonry-grid').length > 0) {
2668							
2669							$( '.'+ container ).append(newElement).isotope( 'appended', newElement );
2670						$( '.'+ container ).imagesLoaded().progress(function() {
2671							$( '.'+ container ).isotope('layout');
2672						});
2673						
2674						}else{
2675							$( '.' + container ).append(newElement);
2676						}
2677						$( anchor ).text( load_more_label );
2678
2679						if ( page > i ) {
2680							if ( imarket_options.permalink == 'plain' ) {
2681								var link = next.replace( /paged=+[0-9]+/gi, 'paged=' + ( i + 1 ) );
2682							} else {
2683								var link = next.replace( /page\/+[0-9]+\//gi, 'page/' + ( i + 1 ) + '/' );
2684							}
2685
2686							$( anchor ).attr( 'href', link );
2687						} else {
2688							$( anchor ).text( loading_finished_msg );
2689							$( anchor ).attr( 'href', 'javascript:void(0);' ).addClass( 'disabled' );
2690						}
2691						isLoading = false;
2692						i++;
2693						imarket.initMagnaficPopup();
2694						imarket.imarketOwlCarousel();
2695						imarket.imarketElementorOwlCarousel();
2696						imarket.tooltip();
2697						imarket.imagelazyload();
2698						imarket.widgetToggle();
2699						imarket.widgetMenuToggle();
2700						imarket.widgetMaxLimitItem();
2701						imarket.canvasSidebar();
2702						imarket.stickySidebar();
2703						imarket.ProductLoopQuantityField();
2704						imarket.productQuickView();
2705						imarket.addToCompare();
2706						imarket.productSwatch();
2707						$(document).trigger('yith_wcwl_reload_fragments'); /* Fixed wishlist icon afer ajax*/
2708					});
2709				}
2710			}
2711		});
2712	}
2713	
2714	imarket.loadmoreProducts = function(){
2715		var load_more_products_button = $('.imarket-products-load-more');
2716		$('.imarket-products-load-more .imarket-load-more').on('click',function(){
2717			
2718			var load_more_btn = $(this);
2719			var page = parseInt(load_more_btn.parent().attr('data-page'));
2720			var data_attr = load_more_btn.parent().data();
2721			var	atts = data_attr.attribute;
2722			var post_wrap = load_more_btn.closest('.imarket-element').find('.products-wrap');
2723            var wrap_id = load_more_btn.closest('.imarket-element').attr('id');
2724			var data = {
2725				action: 'imarket_loadmore_product',
2726				nonce: imarket_options.nonce,
2727				attr: atts,
2728				page: page,
2729			};
2730			if(load_more_btn.hasClass('loading')){ return false;}
2731			imarket.loadAjaxPost(load_more_btn,data,post_wrap,wrap_id);
2732		});
2733		var animationFrame = function () {
2734			$('.imarket-products-load-more a.infinity-scroll').each(function (i, val) {
2735				var load_more_btn = $(this);
2736				var page = parseInt(load_more_btn.parent().attr('data-page'));
2737				var atts = load_more_btn.parent().attr('data-attribute');
2738				var post_wrap = load_more_btn.closest('.imarket-element').find('.products-wrap');
2739				var wrap_id = load_more_btn.closest('.imarket-element').attr('id');
2740				var bottomOffset = post_wrap.offset().top + post_wrap.height() - $(window).scrollTop();
2741				if (bottomOffset < window.innerHeight && bottomOffset > 0) {
2742					
2743					var page = parseInt(load_more_btn.parent().attr('data-page'));
2744					if(!load_more_btn.hasClass('imarket-loadmore-disabled')){ 
2745						if(!imarket.isPostLoading){
2746							imarket.isPostLoading = true;
2747							load_more_btn.trigger('click');
2748						}
2749					}
2750				}
2751			});
2752		}
2753		
2754		var scrollHandler = function () {
2755			requestAnimationFrame(animationFrame);
2756		};                    
2757		$(window).scroll(scrollHandler);		
2758	}
2759	
2760	imarket.loadAjaxPost = function( btn, data, element_wrap, parantElement ){
2761		var load_more_label = btn.parent().data('load_more_label');
2762		var loading_finished_msg = btn.parent().data('loading_finished_msg');
2763		var label_txt = '';
2764		btn.addClass('process');
2765		if(btn.hasClass('imarket-loadmore-disabled')){
2766			return;
2767		}
2768		btn.html('<span class="loading"> '+imarket_options.js_translate_text.loading_txt+'</span>');
2769		$.ajax({
2770			url: imarket_options.ajax_url,
2771			data: data,
2772			dataType: 'json',
2773			method: 'POST',
2774			success: function(response) {
2775				var items = $('' + response['html'] + '');
2776				if ($.trim(response['success']) == 'ok') {
2777					if ($('.masonry-grid').length > 0) {
2778												
2779						 setTimeout(function () {
2780						  element_wrap.imagesLoaded().masonry().append(items).masonry( 'appended', items).masonry('layout');
2781						 }, 500);
2782						 
2783						 
2784					}else{
2785						element_wrap.append(items);
2786					}
2787					
2788					if ($.trim(response['show_bt']) == '0') {
2789						$('#' +parantElement + ' .imarket-load-more').addClass('disabled imarket-loadmore-disabled').html(loading_finished_msg);
2790					} else {
2791						$('#' +parantElement + ' .imarket-load-more').parent().attr('data-page', data['page'] + 1);
2792						btn.html(load_more_label);
2793					}
2794				}
2795			},
2796			error: function(data) {
2797				console.log('ajax error');
2798			},
2799			complete: function() {
2800				imarket.isPostLoading = false;
2801				imarket.imagelazyload();
2802				imarket.initMagnaficPopup();
2803				imarket.swatchInLoop();
2804				imarket.ProductLoopQuantityField();
2805				imarket.tooltip();
2806				imarket.productQuickView();
2807				imarket.productSaleCountdown();
2808				btn.removeClass('process');
2809			},
2810		});
2811	}
2812	
2813	imarket.tooltip = function () {
2814		var tooltip_left = ('.products.product-style-3 .whishlist-button a,.products.product-style-3 .yith-wcwl-add-to-wishlist .yith-wcwl-wishlistaddedbrowse a');
2815		/* Bootstrap tooltips */
2816		$(tooltip_left).tooltip({
2817			animation: false,
2818			container: 'body',
2819			trigger : 'hover',
2820			placement : !imarket.isCheckRTL() ? 'left':'right',
2821			title: function() {
2822				return $(this).text();
2823			}
2824		});
2825		$('.products:not(.product-style-3) .whishlist-button a,.products:not(.product-style-3) .yith-wcwl-add-to-wis
2825hlist .yith-wcwl-wishlistaddedbrowse a, .product-style-3:not(.list-view) .product-buttons .cart-button,.product-buttons .compare-button a,.imarket-tooltip').tooltip({
2826			animation: false,
2827			container: 'body',
2828			trigger : 'hover',
2829			title: function() {
2830				if( $(this).find('.added_to_cart').length > 0 ) return $(this).find('.add_to_cart_button').text();
2831				return $(this).text();
2832			}
2833		});	 
2834				
2835	}
2836	
2837	imarket.productGallerySummarySticky = function () {
2838		/*
2839		* Single Product Gallary & Summary Sticky
2840		*/
2841		if ( $( window ).width() <= 767 || ( ! $('.imarket-product-sticky').length > 0 ) || 'undefined' === typeof ($.fn.stick_in_parent) ) {
2842			return;
2843		}
2844		
2845		var $wrapper 	= $( '.imarket-product-sticky' );
2846		var $gallery 	= $wrapper.find( '.woocommerce-product-gallery' );
2847		var $summary 	= $wrapper.find( '.entry-summary' );
2848		var offset 		= 50;
2849		
2850		if ( 0 === $wrapper.length ) {
2851			return;
2852		}
2853		
2854		setTimeout(function () {
2855			if( imarket_options.sticky_product_image || imarket_options.sticky_product_summary ){
2856				if ( $summary.outerHeight() < $gallery.outerHeight() ) {
2857					stickySummary();
2858				} else {
2859					stickyGallery();
2860				}
2861						
2862				$( window ).resize( function() {
2863					if ( $( window ).width() <= 767 ) {
2864						$gallery.trigger('sticky_kit:detach');
2865						$summary.trigger('sticky_kit:detach');
2866					}else{
2867						if ($summary.outerHeight() < $gallery.outerHeight()) {
2868							stickySummary();
2869						} else {
2870							stickyGallery();
2871						}
2872					}
2873				});
2874			}
2875		}, 100);
2876		
2877		function stickyGallery(){
2878			
2879			if( ! imarket_options.sticky_product_image ) { return; }
2880			
2881			$gallery.stick_in_parent({
2882				offset_top  : offset,
2883				sticky_class: 'imarket-is-stucked'
2884			});
2885		}
2886		
2887		function stickySummary(){
2888			
2889			if( ! imarket_options.sticky_product_summary ){ return; }
2890			
2891			$summary.stick_in_parent({
2892				offset_top  : offset,
2893				sticky_class: 'imarket-is-stucked'
2894			});
2895		}
2896	}
2897	
2898	imarket.productGallerySlider = function() {
2899		/*
2900		 * Product Gallery  & Thumnails slider
2901		 */
2902		if ( ! $.isFunction($.fn.slick) ) {
2903			return;
2904		}
2905		
2906		/* Product Gallery Slider */
2907		if( $('.woocommerce-product-gallery').find( '.single-product-gallery' ).length > 0 ) {
2908			$( '.single-product-gallery' ).not( '.slick-initialized' ).slick({
2909				slidesToShow	: ( 'product-gallery-horizontal' == imarket_options.product_gallery_layout ) ? 2 : 1,
2910				slidesToScroll	: 1,
2911				asNavFor		: ( 'product-gallery-left' == imarket_options.product_gallery_layout || 'product-gallery-bottom' == imarket_options.product_gallery_layout ) ? '.single-product-thumbnails' : '',
2912				fade			: ( 'product-gallery-left' == imarket_options.product_gallery_layout || 'product-gallery-bottom' == imarket_options.product_gallery_layout ) ? true : false,
2913				dots			: ( 'product-gallery-horizontal' == imarket_options.product_gallery_layout || 'product-gallery-center' == imarket_options.product_gallery_layout ) ? true : false,
2914				infinite 		: false,
2915				adaptiveHeight	: true,
2916				rtl				: ( imarket.isCheckRTL() ) ? true : false,
2917				responsive		:[
2918					{
2919						breakpoint	: 639,
2920						settings	: {
2921							dots 			: true
2922						}
2923					}
2924				]
2925			});
2926		}
2927		
2928		/* Product Thumbnails Silder */
2929		if( $('.woocommerce-product-gallery').find( '.single-product-thumbnails' ).length > 0 ) {
2930			$( '.single-product-thumbnails' ).not( '.slick-initialized' ).slick({
2931				slidesToShow	: 4,
2932				slidesToScroll	: 1,
2933				asNavFor		: '.single-product-gallery',
2934				infinite 		: false,
2935				arrows			: true,
2936				focusOnSelect	: true,
2937				vertical		: ( 'product-gallery-left' == imarket_options.product_gallery_layout ) ? true : false,			
2938				rtl				: ( 'product-gallery-bottom' == imarket_options.product_gallery_layout && imarket.isCheckRTL() ) ? true : false,
2939				responsive		:[
2940					{
2941						breakpoint	: 639,
2942						settings	: {
2943							slidesToShow 	: 4,
2944							infinite 		: false,
2945							vertical		: false,
2946							rtl				: ( imarket.isCheckRTL() ) ? true : false,
2947						}
2948					}
2949				]
2950			});
2951		}
2952					
2953		/* Reset the index of image on product variation */
2954		$(document).on( 'found_variation', '.variations_form', function( es, variation ) {		
2955			if ( variation && variation.image && variation.image.src && variation.image.src.length > 1 ) {
2956				$( '.single-product-gallery, .single-product-thumbnails' ).slick( 'slickGoTo', 0 );
2957				setTimeout(function () {
2958					var $product_img = $(document).find( '.imarket-quick-view .woocommerce-product-gallery__wrapper  .slick-current.slick-active img' );
2959					imarket.setVariationAttr( $product_img, 'src',
2960					variation.image.src );
2961					imarket.setVariationAttr( $product_img, 'srcset',
2962					variation.image.srcset );
2963					imarket.setVariationAttr( $product_img, 'sizes',
2964					variation.image.sizes );
2965				}, 300);
2966			}
2967		}).on('reset_image', function () {
2968			$( '.single-product-gallery, .single-product-thumbnails').slick( 'slickGoTo', 0 );
2969			setTimeout(function () {
2970				var $product_img = $(document).find( '.imarket-quick-view .woocommerce-product-gallery__wrapper  .slick-current.slick-active img' );
2971				imarket.resetVariationAttr( $product_img, 'src' );
2972				imarket.resetVariationAttr( $product_img, 'srcset' );
2973				imarket.resetVariationAttr( $product_img, 'sizes' );
2974			}, 300);
2975		});
2976	};
2977	
2978	imarket.productImageZoom = function(){
2979		/*
2980		 * Single Product image zoom
2981		 */
2982		if ( imarket_options.product_image_zoom ) {
2983			var $wc_gallery = $( '.woocommerce-product-gallery' ),
2984			    zoomTarget = imarket_options.product_PhotoSwipe ? $wc_gallery.find( '.woocommerce-product-gallery__image > a' ) : $wc_gallery.find( '.woocommerce-product-gallery__image' ),
2985				width 		= zoomTarget.children('img').attr( 'data-large_image_width' ),
2986				/* zoom option */
2987				zoom_options = $.extend( {
2988					touch: false
2989				});
2990				
2991			/* On Click Zoom */
2992			if ('ontouchstart' in document.documentElement) {
2993				zoom_options.on = 'click';
2994			}			
2995			
2996			setTimeout(function () {
2997				zoomTarget.parent().trigger('zoom.destroy').children('.zoomImg').remove();
2998			}, 500);			
2999			
3000			/* Zoom */
3001			if ( 'undefined' != typeof width && zoomTarget.width() < width ) {
3002				zoomTarget.trigger( 'zoom.destroy' );
3003				zoomTarget.zoom(zoom_options);
3004				
3005				/* show zoom on hover */
3006				zoomTarget.find(':hover').length && zoomTarget.trigger('mouseover');
3007			}
3008		}
3009	};
3010	
3011	imarket.productPhotoSwipe = function () {
3012		/*
3013		 * Single Product Photo Swipe
3014		 */
3015		if ( imarket_options.product_PhotoSwipe ) {
3016			if( $( '.woocommerce-product-gallery' ).length === 0 ){
3017				return;
3018			}
3019			/* var self = this; */
3020			var $wc_gallery = $( '.woocommerce-product-gallery' );	
3021			
3022			setTimeout( function () {
3023				/* If woocommmerce product gallery is undefined, create it */
3024				typeof $wc_gallery.data('product_gallery') == 'undefined' && $wc_gallery.wc_product_gallery();
3025				this.$wc_gallery = $wc_gallery;
3026				this.wc_gallery = $wc_gallery.data('product_gallery');
3027			
3028				/* Remove woocommerce zoom triggers */
3029				$wc_gallery.children('.woocommerce-product-gallery__trigger').remove();
3030				
3031				/* Prevent going to image link */
3032				$wc_gallery
3033					.off('click', '.woocommerce-product-gallery__image a')
3034					.on('click', imarket.preventDefault);
3035								
3036				$wc_gallery.on('click', '.woocommerce-product-gallery__image a, .woocommerce-product-gallery__image', imarket.openPhotoswipe.bind(this));
3037				$wc_gallery.on('click', '.imarket-product-image-full', imarket.openPhotoswipe.bind(this));
3038			}, 100 );
3039		}else{
3040			$('.woocommerce-product-gallery__image a').on('click', function(e){
3041				e.preventDefault();
3042			});			
3043		}		
3044	};
3045	
3046	imarket.openPhotoswipe = function (e) {
3047		if (wc_single_product_params.photoswipe_options) {	
3048			/* Slick slider index */
3049			var slider = this.$wc_gallery.find('.single-product-gallery').slick("getSlick");
3050			if (slider) {
3051				wc_single_product_params.photoswipe_options.index = slider.currentSlide;
3052			}		
3053
3054			this.wc_gallery.openPhotoswipe(e);			
3055			e.stopPropagation();	
3056		}
3057	}
3058	
3059	imarket.productSaleCountdown = function() {
3060		/*
3061		 * Product Sale CountDown
3062		 */
3063		
3064		$('.product-countdown,.imarket-countdown-timer').each(function(){
3065			
3066			var $this 	= $(this),
3067				template 	= '',
3068				end_date = $this.data('end-date');
3069			
3070			if( $this.data('countdown-style') == 'countdown-box' ) {
3071				template = '<span class="days">%-D<span>'+imarket_options.js_translate_text.days_text+'</span></span><span class="hour">%H<span>'+imarket_options.js_translate_text.hours_text+'</span></span><span class="minute">%M<span>'+imarket_options.js_translate_text.mins_text+'</span></span><span class="second">%S<span>'+imarket_options.js_translate_text.secs_text+'</span></span>';
3072			}else{
3073				template = '%-D'+imarket_options.js_translate_text.sdays_text+' : %H'+imarket_options.js_translate_text.shours_text+' : %M'+imarket_options.js_translate_text.smins_text+' : %S'+imarket_options.js_translate_text.ssecs_text;
3074			}
3075			if ( typeof ( $.fn.countdown ) != 'undefined' ) {
3076				/* initialize  */
3077				$this.countdown( end_date, function(event) {
3078					 $(this).html(event.strftime(template));
3079				});
3080			}
3081		});
3082	};
3083	
3084	imarket.productReviewLink = function() {
3085		/*
3086		 * Scroll Show Product Review Tab
3087		 */
3088		
3089		$('.woocommerce-product-rating .rating-counts').on('click', function (e) {
3090			$('.woocommerce-review-link').trigger('click');
3091			 var tabpanel = '#tab-title-reviews';
3092			 $('html,body').animate({scrollTop:$(tabpanel).offset().top-100}, 750);
3093		});
3094	};
3095		
3096	imarket.getProductSizeChart = function () {
3097		/*
3098		 * Get Product Size Chart
3099		 */	
3100		$('.imarket-ajax-size-chart').on('click', function (e) {
3101			e.preventDefault();
3102			 var id = $(this).data('id'); /* get post value */
3103			 var data = {
3104				action			: 'imarket_ajax_get_size_chart',
3105				'id'			: id,
3106				nonce   		: imarket_options.nonce,
3107			};
3108			var chart_btn = $(this);
3109			if(chart_btn.hasClass('loading')){
3110				return false;
3111			}
3112			chart_btn.addClass('loading');
3113			$.ajax({
3114				type: 'post',
3115				url: imarket_options.ajax_url,
3116				data: data,
3117				beforeSend: function (response) {
3118					
3119				},
3120				complete: function (response) {
3121					chart_btn.removeClass('loading');
3122				},
3123				success: function (response) {
3124					$(this).magnificPopup({
3125						removalDelay: 500,
3126						items: {
3127							src: response,
3128							type: 'inline'
3129						},
3130						callbacks: {
3131							open: function () {
3132								var popupWrap = $( '.imarket-product-sizechart' );
3133								popupWrap.addClass('animated fadeInLeft');						
3134							},							
3135							beforeClose: function() {
3136								var popupWrap = $( '.imarket-product-sizechart' );
3137								popupWrap.removeClass('fadeInLeft').addClass('fadeOutRight');
3138							}, 
3139							close: function() {
3140								var popupWrap = $( '.imarket-product-sizechart' );
3141								popupWrap.removeClass('animated fadeOutRight');
3142								
3143							}
3144						},
3145					}).magnificPopup('open');
3146				},
3147			});
3148			
3149      });
3150	}
3151	
3152	imarket.getAjaxBlock = function () {
3153		/*
3154		 * Get Product Size Chart
3155		 */	
3156		$('.imarket-ajax-block').on('click', function (e) {
3157			e.preventDefault();
3158			 var id = $(this).data('id'); /* get block value */
3159			 var title = $(this).data('title'); /* title */
3160			 var data = {
3161				action			: 'imarket_ajax_get_block',
3162				'id'			: id,
3163				'title'			: title,
3164				nonce   		: imarket_options.nonce,
3165			};
3166			var chart_btn = $(this);
3167			if(chart_btn.hasClass('loading')){
3168				return false;
3169			}
3170			chart_btn.addClass('loading');
3171			$.ajax({
3172				type: 'post',
3173				url: imarket_options.ajax_url,
3174				data: data,
3175				beforeSend: function (response) {
3176					
3177				},
3178				complete: function (response) {
3179					chart_btn.removeClass('loading');
3180				},
3181				success: function (response) {
3182					$(this).magnificPopup({
3183						removalDelay: 500,
3184						items: {
3185							src: response,
3186							type: 'inline'
3187						},
3188						callbacks: {
3189							open: function () {
3190								var popupWrap = $( '.imarket-ajax-blok-content' );
3191								popupWrap.addClass('animated slideInDown');						
3192							},							
3193							beforeClose: function() {
3194								var popupWrap = $( '.imarket-ajax-blok-content' );
3195								popupWrap.removeClass('slideInDown').addClass('slideOutUp');
3196							}, 
3197							close: function() {
3198								var popupWrap = $( '.imarket-ajax-blok-content' );
3199								popupWrap.removeClass('animated slideOutUp');
3200								
3201							}
3202						},
3203					}).magnificPopup('open');
3204				},
3205			});
3206			
3207      });
3208	}
3209	
3210	imarket.productQuantityPlusMinus = function() {
3211		/*
3212		 * Product Quantity Plus/Minus
3213		 */
3214		$( document ).on( 'click', '.quantity .plus, .quantity .minus', function() {
3215            /* Get values */
3216            var $qty        = $( this ).closest( '.quantity' ).find( '.qty'),
3217                currentVal  = parseFloat( $qty.val() ),
3218                max         = parseFloat( $qty.attr( 'max' ) ),
3219                min         = parseFloat( $qty.attr( 'min' ) ),
3220                step        = $qty.attr( 'step' );
3221
3222            /* Format values */
3223            if ( ! currentVal || currentVal === '' || currentVal === 'NaN' ) currentVal = 0;
3224            if ( max === '' || max === 'NaN' ) max = '';
3225            if ( min === '' || min === 'NaN' ) min = 0;
3226            if ( step === 'any' || step === '' || step === undefined || parseFloat( step ) 
3226=== 'NaN' ) step = '1';
3227
3228            /* Change the value */
3229            if ( $( this ).is( '.plus' ) ) {
3230                if ( max && ( max == currentVal || currentVal > max ) ) {
3231                    $qty.val( max );
3232                } else {
3233                    $qty.val( currentVal + parseFloat( step ) );
3234                }
3235            } else {
3236                if ( min && ( min == currentVal || currentVal < min ) ) {
3237                    $qty.val( min );
3238                } else if ( currentVal > 0 ) {
3239                    $qty.val( currentVal - parseFloat( step ) );
3240                }
3241            }
3242
3243            /* Trigger change event */
3244            $qty.trigger( 'change' );
3245        });
3246	};
3247	
3248	imarket.productQuickShop = function () {
3249		/*
3250		 * Product Buy Now Button click
3251		 */
3252		$('body').on('click', '.imarket_quick_buy_button', function() {
3253			if (imarket_options.enable_add_to_cart_ajax) {
3254				$('.single_add_to_cart_button').addClass('quick-buy-proceed');
3255			}
3256			var $this = $(this);
3257			var product_id = $(this).attr('data-imarket-product-id');
3258			var product_type = $(this).attr('data-product-type');
3259			var selected = $('form.cart input#imarket_quick_buy_product_' + product_id);
3260			var productform = selected.parent();
3261			
3262			var submit_btn = productform.find('[type="submit"]');
3263			var is_disabled = submit_btn.is(':disabled');
3264			
3265			if(!$(this).closest('.woocommerce-variation-add-to-cart').hasClass('woocommerce-variation-add-to-cart-disabled')){
3266				$this.addClass('loading');
3267			}
3268			
3269			if ( is_disabled ) {
3270				$('html, body').animate({
3271					scrollTop: submit_btn.offset().top - 200
3272				}, 900);
3273			} else {
3274				if(!$this.hasClass('disable')){
3275					productform.append('<input type="hidden" value="true" name="imarket_quick_buy" />');
3276				}
3277				productform.find('.single_add_to_cart_button').trigger('click');
3278			} 
3279		});
3280		
3281		$('form.cart').change(function () {
3282			var is_submit_disabled = $(this).find('[type="submit"]').is(':disabled');
3283			if ( is_submit_disabled ) {
3284				$('.imarket_quick_buy_button').attr('disabled', 'disable');
3285			} else {
3286				$('.imarket_quick_buy_button').removeAttr('disabled');
3287			}
3288		});
3289	}
3290	
3291	imarket.productBoughtTogetherInit = function(){ 
3292		/* Procut Bought Together */
3293		
3294		if ( imarket.$body.find('.imarket-bought-together-products').length === 0 ) {
3295			return;
3296		}
3297		
3298		var self = this;
3299		/* check box click */
3300		$('body').on('click', '.imarket-bought-together-products .product-checkbox input[type=checkbox]', function() {
3301			if ($(this).is(":checked")) {
3302				$(this).closest('.product-wrapper').removeClass('imarket-disable-product');				
3303			}else{
3304				$(this).closest('.product-wrapper').addClass('imarket-disable-product');
3305			}
3306			self.productBoughtTogetherChangeEvent();
3307		});
3308		/* check all */
3309		self.productBoughtTogetherCheckAllItems();
3310		/* add to cart */
3311		self.productBoughtTogetherAddToCart();
3312		
3313		$( 'body' ).on( 'found_variation', function( event, variation ) {
3314			$('.imarket-bought-together-products .current-item .item-price').each(function() {				
3315				if( $(this).data( 'type' ) == 'variable' ) {
3316					$(this).data( 'itemprice', variation.display_price );
3317					$(this).html(self.imarket_woo_formated_price(variation.display_price));
3318					self.productBoughtTogetherChangeEvent();
3319				}
3320			});
3321		});
3322	}
3323	imarket.productBoughtTogetherChangeEvent = function() {
3324		var self = this;
3325		$('.add-items-to-cart').addClass('loading');
3326		
3327		var total_price = self.product_bought_together_get_total_price();
3328		var addon_total_price = self.product_addons_get_total_price();
3329		var total_addon = self.product_bought_together_product_count();
3330		if(total_addon){
3331			$('.add-items-to-cart').removeAttr("disabled");
3332		}else{
3333			$('.add-items-to-cart').attr("disabled", true);
3334		}
3335		$( '.addons-item .addon-count' ).html( total_addon );
3336				$( '.addons-item span.items-price' ).html( self.imarket_woo_formated_price(addon_total_price) );
3337				$( '.items-total span.total-price' ).html( self.imarket_woo_formated_price(total_price) );
3338		$('.add-items-to-cart').removeClass('loading');
3339	}
3340	
3341	imarket.imarket_woo_formated_price = function(number){
3342		var self = this;
3343		return self.imarket_formated_price(number, imarket_options.price_thousand_separator,
3344		imarket_options.price_decimal_separator, imarket_options.price_decimals, 
3345		imarket_options.currency_symbol,imarket_options.price_format);
3346	}
3347	
3348	imarket.imarket_formated_price = function(number, thousand_sep, decimal_sep, tofixed, symbol, woo_price_format){
3349		  var before_text = '';
3350        var after_text = '';
3351        number = number || 0;
3352        tofixed = !isNaN(tofixed = Math.abs(tofixed)) ? tofixed : 2;
3353        symbol = symbol !== undefined ? symbol : "$";
3354        thousand_sep = thousand_sep || ",";
3355        decimal_sep = decimal_sep || ".";
3356        var negative = number < 0 ? "-" : "",
3357            i = parseInt(number = Math.abs(+number || 0).toFixed(tofixed), 10) + "",
3358            j = (j = i.length) > 3 ? j % 3 : 0;
3359        
3360        symbol = '<span class="woocommerce-Price-currencySymbol">' + symbol + '</span>';
3361        
3362        switch (woo_price_format) {
3363            case '%1$s%2$s':
3364                /* left */
3365                before_text += symbol;
3366                break;
3367            case '%1$s %2$s':
3368                /* left with space */
3369                before_text += symbol + ' ';
3370                break;
3371            case '%2$s%1$s':
3372                /* right */
3373                after_text += symbol;
3374                break;
3375            case '%2$s %1$s':
3376                /* right with space */
3377                after_text += ' ' + symbol;
3378                break;
3379            default:
3380                /* default */
3381                before_text += symbol;
3382        }       
3383        
3384        var woo_price_return = before_text +
3385            negative + (j ? i.substr(0, j) + thousand_sep : "" ) +
3386            i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand_sep) +
3387            (tofixed ? decimal_sep + Math.abs(number - i).toFixed(tofixed).slice(2) : "") +
3388            after_text;
3389        
3390        woo_price_return = '<span class="woocommerce-Price-amount amount">' + woo_price_return + '</span>';
3391        
3392        return woo_price_return;
3393	}
3394	
3395	imarket.productBoughtTogetherCheckAllItems = function(){
3396		var self = this;
3397		$('body').on('click', '.check-all-items', function(){
3398			$('.imarket-together-product:checkbox').not(this).prop('checked', this.checked);
3399			if ($(this).is(":checked")) {
3400				$('.imarket-together-product:checkbox').prop('checked', true);  
3401			} else {
3402				$('.imarket-together-product:checkbox').prop("checked", false);
3403			}
3404
3405			self.productBoughtTogetherChangeEvent();
3406		});
3407	}
3408	
3409	imarket.BoughtTogetherIsVariationProduct = function(){
3410		
3411		var product_type = $('.imarket-bought-together-products .current-item .item-price').data('type');
3412		if( product_type == 'variable'){
3413			return true
3414		}
3415		return false;
3416	}
3417	
3418	imarket.BoughtTogetherCurrentProductid = function(){
3419				
3420		var product_id = $('.imarket-bought-together-products .current-item .item-price').data('id');
3421		
3422		return 	product_id;
3423	}
3424	
3425	imarket.BoughtTogetherVariationAvailable = function(){
3426		if( $(".single_add_to_cart_button").length === 0 || $(".single_add_to_cart_button").hasClass("disabled") || $(".single_add_to_cart_button").hasClass("wc-variation-is-unavailable") ) {
3427			return false;
3428		}
3429		return true;
3430	}
3431	
3432	imarket.productBoughtTogetherAddToCart = function(){
3433		var self = this;
3434		$('body').on('click', '.add-items-to-cart:not(.loading)', function(e){
3435			e.preventDefault();
3436			
3437			var is_variation_product = imarket.BoughtTogetherIsVariationProduct();
3438			var variation_product_id = imarket.BoughtTogetherCurrentProductid();
3439			
3440			if(is_variation_product && imarket.BoughtTogetherVariationAvailable() === false){
3441				alert(imarket_options.js_translate_text.variation_unavailable);
3442				return;
3443			}
3444			
3445			var self_this = $(this);
3446			self_this.addClass('loading');
3447			
3448			var all_product_ids = self.product_bought_together_get_checked_product_ids();
3449			var msg='';
3450			if( all_product_ids.length === 0 ) {
3451				msg = imarket_options.bought_together_error;
3452			} else {
3453				
3454				setTimeout(function () {
3455					for (var i = 0; i < all_product_ids.length; i++ ) {
3456						if( is_variation_product && all_product_ids[i] == variation_product_id ){							
3457							var variation_id  = $('.variations_form .variations_button').find('input[name^=variation_id]').val();
3458							var variation = {};
3459							if( $( '.variations_form' ).find('select[name^=attribute]').length ) {
3460								$( '.variations_form' ).find('select[name^=attribute]').each(function() {
3461									var attribute = $(this).attr("name");
3462									var attributevalue = $(this).val();
3463									variation[attribute] = attributevalue;
3464								});
3465							} else {
3466
3467								$( '.variations_form' ).find('.select').each(function() {
3468									var attribute = $(this).attr("data-attribute-name");
3469									var attributevalue = $(this).find('.selected').attr('data-name');
3470									variation[attribute] = attributevalue;
3471								});
3472
3473							}
3474							$.ajax({
3475								type: "POST",
3476								async: false,
3477								url: imarket_options.ajax_url,
3478								data: {
3479									'product_id': all_product_ids[i],
3480									'variation_id': variation_id, 
3481									'variation': variation,
3482									'action': 'imarket_all_add_to_cart'
3483								},
3484								success : function( response ) {
3485									self.product_bought_together_refresh_fragments( response );
3486								}
3487							}); 
3488						} else {
3489							$.ajax({
3490								type: "POST",
3491								async: false,
3492								url: imarket_options.ajax_url,
3493								data: {
3494									'product_id': all_product_ids[i],
3495									'action': 'imarket_all_add_to_cart'
3496								},
3497								success : function( response ) {
3498									self.product_bought_together_refresh_fragments( response );
3499								}
3500							}); 
3501						}
3502					}
3503					var miniCartSidebar = $('.imarket-minicart-slide');
3504					var closeSidebar 	= $('.imarket-mask-overaly');
3505					if ( ! miniCartSidebar.hasClass('opened') ) {
3506						miniCartSidebar.addClass('opened');
3507						closeSidebar.addClass('opened');
3508						self.initNanoScroller();
3509					}
3510					self_this.removeClass('loading');
3511				}, 300); 
3512				
3513			}
3514			if(msg != ''){
3515				$( '.imarket-wc-message' ).html(msg).show(100);
3516				self_this.removeClass('loading');
3517				setTimeout(function () {
3518					$( '.imarket-wc-message' ).slideUp(500);
3519					
3520				}, 3000);				
3521			}
3522			
3523		});
3524	}
3525	
3526	imarket.product_bought_together_get_total_price = function(){
3527		var tprice = 0,itemprice =0;
3528		itemprice = $('.items-total-price .item-price').data('itemprice');
3529		tprice = parseFloat(itemprice);
3530		$('.imarket-bought-together-products .product-checkbox input[type=checkbox]').each(function() {
3531			if( $(this).is(':checked') ) {
3532				tprice += parseFloat( $(this).data( 'price' ) );
3533			}
3534		});
3535		return tprice;
3536	}
3537	imarket.product_addons_get_total_price = function(){
3538		var tprice = 0;
3539		
3540		$('.imarket-bought-together-products .product-checkbox input[type=checkbox]').each(function() {
3541			if( $(this).is(':checked') ) {
3542				tprice += parseFloat( $(this).data( 'price' ) );
3543			}
3544		});
3545		return tprice;
3546	}
3547	imarket.product_bought_together_product_count = function(){
3548		var pcount = 0;
3549		$('.imarket-bought-together-products .product-checkbox input[type=checkbox]').each(function() {
3550			if ($(this).is(':checked')) {
3551				pcount++;
3552			}
3553		});
3554		return pcount;
3555	}
3556	
3557	/* get checked product ids */
3558	imarket.product_bought_together_get_checked_product_ids = function(){
3559		var pids = [],pidd;
3560		pidd = $('.items-total-price .item-price').data('id');
3561		
3562		pids.push( pidd);
3563		$('.imarket-bought-together-products .product-checkbox input[type=checkbox]').each(function() {
3564			if( $(this).is(':checked') ) {
3565				pids.push( $(this).data( 'id' ) );
3566			}
3567		});
3568		return pids;
3569	}
3570	
3571	/* get checked product ids */
3572	imarket.product_bought_together_refresh_fragments = function(response){
3573		var frags = response.fragments;
3574
3575            /* Block fragments class */
3576            if ( frags ) {
3577                $.each( frags, function( key ) {
3578                    $( key ).addClass( 'updating' );
3579                });
3580            }
3581            if ( frags ) {
3582                $.each( frags, function( key, value ) {
3583                    $( key ).replaceWith( value );
3584                });
3585            }
3586	}
3587	
3588	imarket.wooProductTabsAccordian = function(){
3589		if( ( $('.woocommerce-tabs.accordion-layout').length > 0 ) || ( $('.woocommerce-tabs.tabs-layout').length > 0 ) ){
3590			
3591			var $accordion = $('.tab-content-wrap');
3592			var hash  = window.location.hash;
3593			var url   = window.location.href;
3594		
3595			if ( hash.toLowerCase().indexOf( 'comment-' ) >= 0 || hash === '#reviews' || hash === '#tab-reviews' ) {
3596				$accordion.find('.title-reviews').addClass('open');
3597			} else if ( url.indexOf( 'comment-page-' ) > 0 || url.indexOf( 'cpage=' ) > 0 ) {
3598				$accordion.find('.title-reviews').addClass('open');
3599			}else if ( hash === '#tab-additional_information' ) {
3600				$accordion.find('.title-additional_information').addClass('open');
3601			}  else {
3602				$accordion.find('.accordion-title').first().addClass('open');
3603			}
3604			$accordion.on('click', '.accordion-title', function( e ) {
3605				e.preventDefault();
3606				$(this).parent().siblings().find('.woocommerce-Tabs-panel').slideUp('fast');
3607				$(".accordion-title").not($(this)).removeClass("open");
3608				$(this).toggleClass("open").next().slideToggle('fast');
3609			});
3610			$(document).on('click', 'a.woocommerce-review-link', function(e) {
3611				$accordion.find('.accordion-title').removeClass("open");
3612				$accordion.find('.title-reviews').addClass("open");
3613			});
3614		}
3615	}
3616	
3617	imarket.wooProductTabsToggle = function(){
3618		if($('.woocommerce-tabs.toggle-layout').length > 0){
3619			var $accordion = $('.tab-content-wrap');
3620			
3621			$accordion.find('.accordion-title').addClass('open');
3622			$accordion.find('.woocommerce-Tabs-panel').css("display", "block");
3623			$accordion.on('click', '.accordion-title', function( e ) {
3624				e.preventDefault();				
3625				var accordion = $(this);
3626				var accordionContent = accordion.next('.woocommerce-Tabs-panel');				
3627				accordion.toggleClass("open");
3628				accordionContent.slideToggle(250);				
3629			});
3630			$(document).on('click', 'a.woocommerce-review-link', function(e) {
3631				e.stopPropagation();
3632			});
3633		}
3634	}
3635	
3636	imarket.wcfm_vendor = function(){
3637		//*******************************************************************
3638		//* WCFM Vendor
3639		//*******************************************************************/
3640		if ($('#_themejr_product_ids').length <= 0) {
3641            return false;
3642        }
3643        if (typeof $wcfm_product_select_args === 'undefined') {
3644            return false;
3645        }
3646
3647        $('#_themejr_product_ids').select2($wcfm_product_select_args);
3648	};
3649	
3650	imarket.MiniCartUpdateQuantity = function(){
3651		/* Update Minicart item quantity */
3652		$(document).on('change', '.woocommerce-mini-cart .qty', function(){
3653			var quantity = parseFloat($(this).val());
3654			var max = parseFloat($(this).attr('max'));
3655			if( max !== 'NaN' && max < quantity ){
3656				quantity = max;
3657				$(this).val( max );
3658			}
3659			
3660			$(this).parents('.woocommerce-mini-cart-item').addClass('loading');
3661			var cart_item_key = $(this).parents('.woocommerce-mini-cart-item').attr('data-cart_item_key');
3662			
3663			var data = {
3664				quantity: quantity,
3665				cart_item_key: cart_item_key,
3666				nonce: imarket_options.nonce,
3667				action: 'imarket_update_cart_widget_quantity',
3668			};
3669			$.ajax({
3670				url: imarket_options.ajax_url,
3671				data: data,
3672				dataType: 'json',
3673				method: 'POST',
3674				success: function (response) {
3675					if( !response ){
3676						return;
3677					}
3678					$(document.body).trigger('wc_fragment_refresh');
3679				}				
3680			});
3681		});
3682	};
3683	
3684	imarket.autoCartUpdate = function(){
3685		if( ! imarket_options.cart_auto_update || $('.woocommerce-cart-form').length <= 0){
3686			return;
3687		}
3688		$(document).on('change','.woocommerce-cart-form .product-quantity',function(e) {
3689			$("[name='update_cart']").removeAttr('disabled');
3690			$("[name='update_cart']").trigger("click"); 
3691        });
3692	};
3693	
3694	imarket.checkoutUpdateQuantity = function(){
3695		
3696		/* Update Minicart item quantity */
3697		
3698		if( ! imarket_options.checkout_product_quantity || $('.woocommerce-checkout-review-order-table').length <= 0){
3699			return;
3700		}
3701		
3702		$(document).on('change', '.woocommerce-checkout-review-order-table .qty', function(){
3703			var $form = $( 'form.checkout' );
3704			var form_data =  $( 'form.checkout' ).serialize();
3705			$(".woocommerce-checkout-payment, .woocommerce-checkout-review-order-table").block({
3706                message: null,
3707                overlayCSS: {
3708                    opacity: 0.6
3709                }
3710            })						
3711			var data = {
3712				action 		: 'imarket_update_checkout_quantity',
3713				form_data 	: form_data,
3714				nonce		: imarket_options.nonce,
3715			};
3716			$.ajax({
3717				url: imarket_options.ajax_url,
3718				data: data,
3719				dataType: 'json',
3720				method: 'POST',
3721				success: function (response) {
3722					if( !response ){
3723						location.reload();
3724					}
3725					$.each( response.fragments, function( key, value ) {
3726						$( key ).replaceWith( value );
3727					});			
3728					$( 'body' ).trigger( 'update_checkout' );
3729				},
3730				error: function (jqXHR, exception) {
3731					console.log("Error: Something went wrong.");
3732					$(".woocommerce-checkout-payment, .woocommerce-checkout-review-order-table").unblock();
3733				}
3734			});
3735		});
3736	};
3737	
3738	imarket.getVisitorCount = function(){
3739		
3740		var min,max,delay;
3741		var visitor_elm = $('.imarket-visitor-change');
3742		if(  visitor_elm.length <= 0){
3743			return;
3744		}
3745		min 	= parseInt( visitor_elm.data('min') );
3746		max 	= parseInt( visitor_elm.data('max') );
3747		delay 	= parseInt( visitor_elm.data('delay') );
3748		setInterval(function() {
3749		  var variation = imarketGetRandomInt(min, max );
3750		  visitor_elm.find('.product-visitor-count').html(variation);
3751		}, delay * 1000 );
3752		function imarketGetRandomInt(min, max) {			
3753			let difference = max - min;
3754			let rand = Math.random();
3755			rand = Math.floor( rand * difference);
3756			rand = rand + min;
3757			return rand;
3758		}
3759	}
3760	
3761	imarket.askQuestionsForm = function(){
3762		
3763		var ask_questions_form = $('.imarket-ask-questions-ajax');
3764		if(  ask_questions_form.length <= 0){
3765			return;
3766		}
3767		$('.imarket-ask-questions').magnificPopup({
3768			type: 'inline',
3769			preloader: false,			
3770			removalDelay: 500,
3771			items: {
3772				src: '#imarket-ask-questions-popup' ,					
3773			},
3774			/* mainClass: 'animated bounceIn', */
3775			callbacks: {
3776				open: function() {
3777					var closeSidebar 	= $('.imarket-mask-overaly');
3778					var mobileSidebar = $('.imarket-mobile-menu');
3779					closeSidebar.removeClass('opened');
3780					mobileSidebar.removeClass('opened');
3781					$('.imarket-ask-questions-popup').addClass('animated slideInDown');
3782				},
3783				beforeClose: function() {
3784						var popupWrap = $( '.imarket-ask-questions-popup' );
3785						popupWrap.removeClass('slideInDown').addClass('slideOutUp');
3786					}, 
3787				close: function() {
3788					$('.imarket-ask-questions-popup').removeClass('animated slideOutUp');
3789				}
3790			} 
3791		});
3792		
3793	}
3794	
3795	imarket.imarketEqualTabsHeight = function(){
3796		//*******************************************************************
3797		//* Equal tabs height
3798		//*******************************************************************/
3799		setTimeout(function () {
3800			$('.products-tab-content').each(function () {
3801				var $this = $(this);
3802				if ($this.find('.tab-content').length) {
3803					$this.find('.tab-content').css({
3804						'height': 'auto'
3805					});
3806					var elem_height = 0;
3807					$this.find('.tab-content').each(function () {
3808						var this_elem_h = $(this).height();
3809						if (elem_height < this_elem_h) {
3810							elem_height = this_elem_h;
3811						}
3812					});
3813					$this.find('.tab-content').height(elem_height);
3814				}
3815			});
3816		}, 4000);
3817	};
3818	
3819	imarket.imarketAjaxtab = function() {
3820		/* Ajax tabs */
3821		var category_tab_cache = [];
3822		$(document).on('click', '.products-tabs.enable-ajax .nav-tabs a', function (e) {			
3823			e.preventDefault();			
3824			var $_this 		= $(this),			
3825			data_attr 		= $_this.parent().data(),
3826			atts 			= data_attr.attribute,
3827			data_href 		= $_this.data('href'),
3828			$tab_content 	= $_this.closest('.imarket-element').find('.tab-content'),
3829			element_wrap 	= $_this.closest('.imarket-element').find('.tab-content .products');
3830			
3831			if(category_tab_cache[data_href] != undefined ){
3832				$tab_content.addClass('loading');
3833				var items = category_tab_cache[data_href];
3834				element_wrap.trigger('destroy.owl.carousel').removeClass('owl-loaded');
3835				element_wrap.html(items).fadeIn(600);
3836				$tab_content.removeClass('loading');
3837				imarket.imagelazyload();
3838				imarket.initMagnaficPopup();
3839				imarket.swatchInLoop();
3840				imarket.ProductLoopQuantityField();
3841				imarket.tooltip();
3842				imarket.productQuickView();
3843				imarket.productSaleCountdown();
3844				imarket.imarketElementorOwlCarousel();
3845				return;
3846			}
3847			var data = {
3848					attr: atts,
3849					nonce: imarket_options.nonce,
3850					action: 'imarket_category_tab_product',
3851				};
3852			if($_this.hasClass('process')){ return false;}
3853			$_this.addClass('process');
3854			$tab_content.addClass('loading');
3855			$.ajax({
3856				url: imarket_options.ajax_url,
3857				data: data,
3858				dataType: 'json',
3859				method: 'POST',
3860				success: function(response) {
3861					var items = $('' + response['html'] + '');
3862					category_tab_cache[data_href] = items;
3863					element_wrap.trigger('destroy.owl.carousel').removeClass('owl-loaded');
3864					if ($.trim(response['success']) == 'ok') {						
3865						element_wrap.html(items).fadeIn(600);						
3866					} 
3867				},
3868				error: function(data) {
3869					console.log('ajax error');
3870				},
3871				complete: function() {
3872					imarket.isPostLoading = false;
3873					imarket.imagelazyload();
3874					imarket.initMagnaficPopup();
3875					imarket.swatchInLoop();
3876					imarket.ProductLoopQuantityField();
3877					imarket.tooltip();
3878					imarket.productQuickView();
3879					imarket.productSaleCountdown();
3880					imarket.imarketElementorOwlCarousel();
3881					$_this.removeClass('process');
3882					$tab_content.removeClass('loading');
3883				},
3884			});
3885		} );
3886	}
3887	
3888	imarket.imarketResponsiveTab = function() {
3889		/* Responsive tabs */
3890		$(document).on('click', '[data-trigger="tab"]', function (event) {
3891			var href = $( this ).attr( 'href' );
3892			event.preventDefault();
3893			$( '[data-toggle="tab"][href="' + href + '"]' ).trigger( 'click' );
3894		} );
3895
3896	}
3897	
3898	imarket.imarketProgressbar = function() {
3899		/*
3900		* Progress Bar
3901		*/		
3902		$('.progress .progress-bar').each(function(){
3903			if (typeof ($.fn.waypoint) != 'undefined') {
3904				$(this).waypoint(function(){
3905					var width = $(this).attr('data-value');
3906					$(this).animate({
3907							width: width+'%'
3908						},
3909						{
3910							duration: 1000,
3911							easing: 'swing'
3912						}
3913					);
3914				}, { offset: '100%', triggerOnce: true });
3915			}
3916		});	
3917	}
3918	
3919	imarket.imarketCounterUp = function() {
3920		/*
3921		* Counter Up
3922		*/	
3923		if ( ! $.isFunction($.fn.counterUp) ) {
3924			return;
3925		}
3926		jQuery('.counter').counterUp({
3927            delay: 20,
3928            time: 2000
3929        });
3930	}
3931	
3932	imarket.imageGaleryMasonry = function (){
3933		
3934		/*
3935		* Image Gallery Masonry
3936		*/
3937		
3938		if ( ! $('.imarket-image-gallery.image-gallery-masonry-grid').length > 0 ) return;
3939		var $layoutMode='masonry';
3940		
3941		if($( '.imarket-image-gallery.image-gallery-masonry-grid' ).length){
3942			$( '.imarket-image-gallery.image-gallery-masonry-grid' ).each(function(){
3943				
3944				var image_gallery_container = $( this );
3945				/* initialize Masonry after all images have loaded */
3946                image_gallery_container.imagesLoaded(function() {
3947					image_gallery_container.isotope({
3948						itemSelector: '.imarket-gallery',
3949						isOriginLeft: ! $('body').hasClass('rtl'),
3950						layoutMode: $layoutMode
3951					});
3952				 });
3953			});			
3954		}		
3955	};
3956	
3957	/*
3958	 * Document ready
3959	 */ 
3960	$(document).ready(function(){ 
3961		imarket.init();		
3962    });
3963	
3964	$(document).ready(function(){ 
3965		$(window).on('vc_reload', function () {
3966           imarket.init();            
3967        });	
3968    });
3969	
3970	$( window ).on('load', function () {
3971		var imarket_pre_loader = $( '.imarket-site-preloader' );
3972		if ( imarket_pre_loader.length ) {
3973            imarket_pre_loader.fadeOut( 800 );
3974		}
3975	});
3976	
3977	var ElementorCounterUp = function($scope, $) {
3978		var $this = $scope.find('.counter');
3979		$this.counterUp({
3980            delay: 20,
3981            time: 2000
3982        });
3983	};
3984	
3985	var ElementorImaeGalleryMasonary = function($scope, $) {	
3986		var $layoutMode = 'masonry';
3987		var image_gallery_container = $scope.find('.image-gallery-masonry-grid');
3988		
3989		if(image_gallery_container.length){
3990			/* initialize Masonry after all images have loaded */
3991			image_gallery_container.imagesLoaded(function() {
3992				image_gallery_container.isotope({
3993					itemSelector: '.imarket-gallery',
3994					isOriginLeft: ! $('body').hasClass('rtl'),
3995					layoutMode: $layoutMode
3996				});
3997			});	
3998		}		
3999	};
4000	
4001	var Elementorcountdown = function($scope, $) {
4002		var $this = $scope.find('.imarket-countdown-timer'),
4003			template 	= '',
4004			end_date = $this.data('end-date');
4005			
4006		if( $this.data('countdown-style') == 'countdown-box' ) {
4007			template = '<span class="days">%-D<span>'+imarket_options.js_translate_text.days_text+'</span></span><span class="hour">%H<span>'+imarket_options.js_translate_text.hours_text+'</span></span><span class="minute">%M<span>'+imarket_options.js_translate_text.mins_text+'</span></span><span class="second">%S<span>'+imarket_options.js_translate_text.secs_text+'</span></span>';
4008		}else{
4009			template = '%-D'+imarket_options.js_translate_text.sdays_text+':%H'+imarket_options.js_translate_text.shours_text+':%M'+imarket_options.js_translate_text.smins_text+':%S'+imarket_options.js_translate_text.ssecs_text;
4010		}
4011		
4012		/* initialize  */
4013		$this.countdown( end_date, function(event) {
4014			 $(this).html(event.strftime(template));
4015		});
4016	};
4017	
4018	imarket.imarketElementorOwlCarousel = function() {
4019		function add_owl_overlayclass(){
4020			$('.owl-stage-outer .product-wrapper').mouseenter(function(){
4021			var slider_elemnt = $(this).closest('.products.imarket-carousel');
4022			slider_elemnt.find('.owl-stage-outer').addClass('overlay');
4023		}).mouseleave(function(){
4024			var slider_elemnt = $(this).closest('.products.imarket-carousel');
4025			slider_elemnt.find('.owl-stage-outer').removeClass('overlay');
4026		});
4027		}
4028		setTimeout(function() {add_owl_overlayclass()}, 1000);
4029		
4030		setTimeout( function(){
4031			jQuery( '.owl-carousel.imarket-carousel' ).each( function () {
4032				var $carousel = jQuery(this),
4033				owlCarouselArg = ( $carousel.attr('data-owl_options')) ? $carousel.data('owl_options') : {};
4034				
4035				var loop 				= ( owlCarouselArg.slider_loop ) ? true : false,
4036				autoplay 			= ( owlCarouselArg.slider_autoplay ) ? true : false,							
4037				autoplayHoverPause 	= ( autoplay && owlCarouselArg.slider_autoplayHoverPause ) ? true : false,
4038				autoplaytimeout 	= owlCarouselArg.slider_autoplaytimeout,
4039				smartspeed 			= parseInt(owlCarouselArg.slider_smartspeed),
4040				
4041				rewind 				= ( owlCarouselArg.slider_rewind ) ? true : false,
4042				nav 				= ( owlCarouselArg.slider_nav ) ? true : false,		
4043				nav_mobile			= ( owlCarouselArg.slider_nav_mobile ) ? true : false,			
4044				center 				= ( owlCarouselArg.slider_center ) ? true : false,				
4045				dots 				= ( owlCarouselArg.slider_dots ) ? true : false,
4046				autoHeight 			= ( owlCarouselArg.slider_autoHeight ) ? true : false,
4047				touchDrag			= ( owlCarouselArg.slider_touchDrag ) ? true : false,
4048				touchDrag_mobile	= ( owlCarouselArg.slider_touchDrag_mobile ) ? true : false,
4049				animateIn 			= owlCarouselArg.slider_animatein,
4050				animateOut 			= owlCarouselArg.slider_animateout,
4051				margin 				= owlCarouselArg.slider_margin,
4052				rs_extra_large 		= ( owlCarouselArg.rs_extra_large > 0 ) ? owlCarouselArg.rs_extra_large : 5,
4053				rs_large 			= ( owlCarouselArg.rs_large > 0 ) ? owlCarouselArg.rs_large : 4,
4054				rs_medium 			= ( owlCarouselArg.rs_medium > 0 ) ? owlCarouselArg.rs_medium : 3,
4055				rs_small 			= ( owlCarouselArg.rs_small > 0 ) ? owlCarouselArg.rs_small : 2,
4056				rs_extra_small 		= ( owlCarouselArg.rs_extra_small > 0 ) ? owlCarouselArg.rs_extra_small : 2,
4057				numItems 			= null,
4058				slider_element 		= jQuery(this);
4059				numItems 			= slider_element.children().length;
4060								
4061				slider_element.owlCarousel({				
4062					autoplay			: autoplay,
4063					autoplayHoverPause	: autoplayHoverPause,
4064					autoplayTimeout		: autoplaytimeout,
4065					smartSpeed 			: smartspeed,
4066					rewind				: rewind,				
4067					nav					: nav,
4068					center				: center,
4069					navText				: ['',''],
4070					dots				: dots,
4071					autoHeight			: autoHeight,
4072					touchDrag			: touchDrag,				
4073					animateIn			: animateIn,
4074					animateOut			: animateOut,
4075					margin				: margin,
4076					rtl 				: ( imarket.isCheckRTL() ) ? true : false,
4077					responsive			: {
4078						0:{
4079							items	: rs_extra_small,
4080							loop	: ( numItems >= rs_extra_small && loop ) ? true : false,
4081							nav		: nav_mobile,
4082							mouseDrag: false,
4083							touchDrag: touchDrag_mobile						
4084						},
4085						576:{
4086							items	: rs_small,
4087							loop	: ( numItems >= rs_small && loop ) ? true : false,
4088							nav		: nav_mobile,
4089							mouseDrag: false,
4090							touchDrag: touchDrag_mobile	
4091						},
4092						768:{
4093							items	: rs_medium,
4094							loop	: ( numItems >= rs_medium && loop) ? true : false,
4095							nav		: nav_mobile,
4096						},
4097						1025:{
4098							items	: rs_large,
4099							loop	: ( numItems >= rs_large && loop) ? true : false,
4100						},					
4101						1200:{
4102							items 	: rs_extra_large,
4103							loop	: ( numItems >= rs_extra_large && loop) ? true : false,
4104						}
4105					},
4106					onInitialized: function(){
4107						slider_element.addClass('owl-theme');
4108					}
4109				}).on('changed.owl.carousel', function(event) {
4110					imarket.imagelazyload();
4111				});	
4112			
4113			});
4114		}, 300 );
4115	}
4116	
4117	imarket.BackgroundParallax = function(){
4118		/*
4119		* Parallax Background
4120		*/		
4121		if ($(window).width() <= 1024) {
4122			return;
4123		}
4124		$('.imarket-parallax-background').each(function() {			
4125			$this.parallax("50%", 0.3);
4126		});
4127	};
4128	
4129	/* Elementor Elements*/
4130	$( window ).on( 'elementor/frontend/init', function () {
4131		if (!elementorFrontend.isEditMode()) {
4132			return;
4133		}
4134		
4135		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_counter.default', ElementorCounterUp)
4136		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_countdown.default', Elementorcountdown);
4137		
4138		
4139		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_image_gallery.default', function($wrapper, $) {
4140			imarket.imarketElementorOwlCarousel($wrapper, $);
4141			ElementorImaeGalleryMasonary($wrapper, $);
4142		});
4143		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_progress_bar.default', function($wrapper, $) {
4144			imarket.imarketProgressbar();
4145		});
4146		
4147		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_testimonials.default', function($wrapper, $) {
4148			imarket.imarketElementorOwlCarousel($wrapper, $);
4149		});
4150		
4151		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_team.default', function($wrapper, $) {
4152			imarket.imarketElementorOwlCarousel($wrapper, $);
4153		});
4154		
4155		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_banner_carousel.default', function($wrapper, $) {
4156			imarket.imarketElementorOwlCarousel($wrapper, $);
4157		});
4158		
4159		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_product_categories_thumbnail.default', function($wrapper, $) {
4160			imarket.imarketElementorOwlCarousel($wrapper, $);
4161		});
4162		
4163		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_product_categories.default', function($wrapper, $) {
4164			imarket.imarketElementorOwlCarousel($wrapper, $);
4165		});
4166		
4167		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_products_widget.default', function($wrapper, $) {
4168			imarket.imarketElementorOwlCarousel($wrapper, $);
4169		});
4170		
4171		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_product_brands.default', function($wrapper, $) {
4172			imarket.imarketElementorOwlCarousel($wrapper, $);
4173		});		
4174		
4175		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_products_grid_carousel.default', function($wrapper, $) {
4176			imarket.imarketElementorOwlCarousel($wrapper, $);
4177			imarket.productSaleCountdown();
4178			imarket.tooltip();
4179			imarket.imagelazyload();
4180			imarket.productSwatch();
4181			imarket.productQuickView();
4182			imarket.addToCompare();
4183		});
4184		
4185		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_hot_deal_products.default', function($wrapper, $) {
4186			imarket.imarketElementorOwlCarousel($wrapper, $);
4187			Elementorcountdown($wrapper, $);
4188			imarket.productSaleCountdown();
4189		});
4190		
4191		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_products_and_categories_box.default', function($wrapper, $) {
4192			imarket.imarketElementorOwlCarousel($wrapper, $);
4193		});
4194		
4195		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_products_recently_viewed.default', function($wrapper, $) {
4196			imarket.imarketElementorOwlCarousel($wrapper, $);
4197		});
4198		
4199		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_products_with_banner.default', function($wrapper, $) {
4200			imarket.imarketElementorOwlCarousel($wrapper, $);
4201		});
4202		
4203		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_products_tabs.default', function($wrapper, $) {
4204			imarket.imarketElementorOwlCarousel($wrapper, $);
4205		});
4206		
4207		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_blog.default', function($wrapper, $) {
4208			imarket.MasonryGrid();
4209		});		
4210		
4211		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_blog_carousel.default', function($wrapper, $) {
4212			imarket.imarketElementorOwlCarousel($wrapper, $);
4213		});
4214		
4215		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_portfolio.default', function($wrapper, $) {
4216			 imarket.portfolioFilters();
4217				imarket.portfolioLoadMore();
4218		});
4219		
4220		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_portfolio_carousel.default', function($wrapper, $) {			
4221			imarket.imarketElementorOwlCarousel($wrapper, $);
4222		});
4223		
4224		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_wcfm_vendors.default', function($wrapper, $) {
4225			imarket.imarketElementorOwlCarousel($wrapper, $);
4226		});
4227		
4228		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_dokan_vendors.default', function($wrapper, $) {
4229			imarket.imarketElementorOwlCarousel($wrapper, $);
4230		});
4231		
4232		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_wcmp_vendors.default', function($wrapper, $) {
4233			imarket.imarketElementorOwlCarousel($wrapper, $);
4234		});
4235		
4236		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_wc_vendors.default', function($wrapper, $) {
4237			imarket.imarketElementorOwlCarousel($wrapper, $);
4238		});
4239		
4240		elementorFrontend.hooks.addAction('frontend/element_ready/imarket_instagram.default', function($wrapper, $) {
4241			imarket.imarketElementorOwlCarousel($wrapper, $);
4242		});
4243		
4244	});
4245})(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.