/**
 * File navigation.js.
 *
 * Handles toggling the navigation menu for small screens and enables TAB key
 * navigation support for dropdown menus.
 */
( function() {
	var container, button, menu, links, i, len;

	container = document.getElementById( 'site-navigation' );
	if ( ! container ) {
		return;
	}

	button = container.getElementsByTagName( 'button' )[0];
	if ( 'undefined' === typeof button ) {
		return;
	}

	menu = container.getElementsByTagName( 'ul' )[0];

	// Hide menu toggle button if menu is empty and return early.
	if ( 'undefined' === typeof menu ) {
		button.style.display = 'none';
		return;
	}

	menu.setAttribute( 'aria-expanded', 'false' );
	if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
		menu.className += ' nav-menu';
	}

	button.onclick = function() {
		if ( -1 !== container.className.indexOf( 'toggled' ) ) {
			container.className = container.className.replace( ' toggled', '' );
			button.setAttribute( 'aria-expanded', 'false' );
			menu.setAttribute( 'aria-expanded', 'false' );
		} else {
			container.className += ' toggled';
			button.setAttribute( 'aria-expanded', 'true' );
			menu.setAttribute( 'aria-expanded', 'true' );
		}
	};

	// Get all the link elements within the menu.
	links    = menu.getElementsByTagName( 'a' );

	// Each time a menu link is focused or blurred, toggle focus.
	for ( i = 0, len = links.length; i < len; i++ ) {
		links[i].addEventListener( 'focus', toggleFocus, true );
		links[i].addEventListener( 'blur', toggleFocus, true );
	}

	/**
	 * Sets or removes .focus class on an element.
	 */
	function toggleFocus() {
		var self = this;

		// Move up through the ancestors of the current link until we hit .nav-menu.
		while ( -1 === self.className.indexOf( 'nav-menu' ) ) {

			// On li elements toggle the class .focus.
			if ( 'li' === self.tagName.toLowerCase() ) {
				if ( -1 !== self.className.indexOf( 'focus' ) ) {
					self.className = self.className.replace( ' focus', '' );
				} else {
					self.className += ' focus';
				}
			}

			self = self.parentElement;
		}
	}

	/**
	 * Toggles `focus` class to allow submenu access on tablets.
	 */
	( function( container ) {
		var touchStartFn, i,
			parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );

		if ( 'ontouchstart' in window ) {
			touchStartFn = function( e ) {
				var menuItem = this.parentNode, i;

				if ( ! menuItem.classList.contains( 'focus' ) ) {
					e.preventDefault();
					for ( i = 0; i < menuItem.parentNode.children.length; ++i ) {
						if ( menuItem === menuItem.parentNode.children[i] ) {
							continue;
						}
						menuItem.parentNode.children[i].classList.remove( 'focus' );
					}
					menuItem.classList.add( 'focus' );
				} else {
					menuItem.classList.remove( 'focus' );
				}
			};

			for ( i = 0; i < parentLink.length; ++i ) {
				parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
			}
		}
	}( container ) );
} )();

/**
 * File skip-link-focus-fix.js.
 *
 * Helps with accessibility for keyboard only users.
 *
 * Learn more: https://git.io/vWdr2
 */
(function() {
	var isIe = /(trident|msie)/i.test( navigator.userAgent );

	if ( isIe && document.getElementById && window.addEventListener ) {
		window.addEventListener( 'hashchange', function() {
			var id = location.hash.substring( 1 ),
				element;

			if ( ! ( /^[A-z0-9_-]+$/.test( id ) ) ) {
				return;
			}

			element = document.getElementById( id );

			if ( element ) {
				if ( ! ( /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) ) {
					element.tabIndex = -1;
				}

				element.focus();
			}
		}, false );
	}
})();

/* global wc_cart_params */
jQuery( function( $ ) {
	"use strict";
	
	// wc_cart_params is required to continue, ensure the object exists
	if ( typeof wc_cart_params === 'undefined' ) {
		return false;
	}

	// Utility functions for the file.

	/**
	 * Gets a url for a given AJAX endpoint.
	 *
	 * @param {String} endpoint The AJAX Endpoint
	 * @return {String} The URL to use for the request
	 */
	var get_url = function( endpoint ) {
		return wc_cart_params.wc_ajax_url.toString().replace(
			'%%endpoint%%',
			endpoint
		);
	};

	/**
	 * Check if a node is blocked for processing.
	 *
	 * @param {JQuery Object} $node
	 * @return {bool} True if the DOM Element is UI Blocked, false if not.
	 */
	var is_blocked = function( $node ) {
		return $node.is( '.processing' ) || $node.parents( '.processing' ).length;
	};

	/**
	 * Block a node visually for processing.
	 *
	 * @param {JQuery Object} $node
	 */
	var block = function( $node ) {
		if ( ! is_blocked( $node ) ) {
			$node.addClass( 'processing' ).block( {
				message: null,
				overlayCSS: {
					background: '#fff',
					opacity: 0.6
				}
			} );
		}
	};

	/**
	 * Unblock a node after processing is complete.
	 *
	 * @param {JQuery Object} $node
	 */
	var unblock = function( $node ) {
		$node.removeClass( 'processing' ).unblock();
	};

	/**
	 * Update the .woocommerce div with a string of html.
	 *
	 * @param {String} html_str The HTML string with which to replace the div.
	 * @param {bool} preserve_notices Should notices be kept? False by default.
	 */
	var update_wc_div = function( html_str, preserve_notices ) {
		var $html       = $.parseHTML( html_str );
		var $new_form   = $( '.woocommerce-cart-form', $html );
		var $new_totals = $( '.cart_totals', $html );
		var $notices    = $( '.woocommerce-error, .woocommerce-message, .woocommerce-info', $html );

		// No form, cannot do this.
		if ( $( '.woocommerce-cart-form' ).length === 0 ) {
			window.location.href = window.location.href;
			return;
		}

		// Remove errors
		if ( ! preserve_notices ) {
			$( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove();
		}

		if ( $new_form.length === 0 ) {
			// If the checkout is also displayed on this page, trigger reload instead.
			if ( $( '.woocommerce-checkout' ).length ) {
				window.location.href = window.location.href;
				return;
			}

			// No items to display now! Replace all cart content.
			var $cart_html = $( '.cart-empty', $html ).closest( '.woocommerce' );
			$( '.woocommerce-cart-form__contents' ).closest( '.woocommerce' ).replaceWith( $cart_html );

			// Display errors
			if ( $notices.length > 0 ) {
				show_notice( $notices, $( '.cart-empty' ).closest( '.woocommerce' ) );
			}
		} else {
			// If the checkout is also displayed on this page, trigger update event.
			if ( $( '.woocommerce-checkout' ).length ) {
				$( document.body ).trigger( 'update_checkout' );
			}

			$( '.woocommerce-cart-form' ).replaceWith( $new_form );
			$( '.woocommerce-cart-form' ).find( 'input[name="update_cart"]' ).prop( 'disabled', true );

			if ( $notices.length > 0 ) {
				show_notice( $notices );
			}

			update_cart_totals_div( $new_totals );
		}

		$( document.body ).trigger( 'updated_wc_div' );
	};

	/**
	 * Update the .cart_totals div with a string of html.
	 *
	 * @param {String} html_str The HTML string with which to replace the div.
	 */
	var update_cart_totals_div = function( html_str ) {
		$( '.cart_totals' ).replaceWith( html_str );
		$( document.body ).trigger( 'updated_cart_totals' );
	};

	/**
	 * Clear previous notices and shows new one above form.
	 *
	 * @param {Object} The Notice HTML Element in string or object form.
	 */
	var show_notice = function( html_element, $target ) {
		if ( ! $target ) {
			$target = $( '.woocommerce-cart-form' );
		}
		$target.before( html_element );
	};


	/**
	 * Object to handle AJAX calls for cart shipping changes.
	 */
	var cart_shipping = {

		/**
		 * Initialize event handlers and UI state.
		 */
		init: function( cart ) {
			this.cart                       = cart;
			this.toggle_shipping            = this.toggle_shipping.bind( this );
			this.shipping_method_selected   = this.shipping_method_selected.bind( this );
			this.shipping_calculator_submit = this.shipping_calculator_submit.bind( this );

			$( document ).on(
				'click',
				'.shipping-calculator-button',
				this.toggle_shipping
			);
			$( document ).on(
				'change',
				'select.shipping_method, input[name^=shipping_method]',
				this.shipping_method_selected
			);
			$( document ).on(
				'submit',
				'form.woocommerce-shipping-calculator',
				this.shipping_calculator_submit
			);

			$( '.shipping-calculator-form' ).hide();
		},

		/**
		 * Toggle Shipping Calculator panel
		 */
		toggle_shipping: function() {
			$( '.shipping-calculator-form' ).slideToggle( 'slow' );
			return false;
		},

		/**
		 * Handles when a shipping method is selected.
		 *
		 * @param {Object} evt The JQuery event.
		 */
		shipping_method_selected: function( evt ) {
			var target = evt.currentTarget;

			var shipping_methods = {};

			$( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function() {
				shipping_methods[ $( target ).data( 'index' ) ] = $( target ).val();
			} );

			block( $( 'div.cart_totals' ) );

			var data = {
				security: wc_cart_params.update_shipping_method_nonce,
				shipping_method: shipping_methods
			};

			$.ajax( {
				type:     'post',
				url:      get_url( 'update_shipping_method' ),
				data:     data,
				dataType: 'html',
				success:  function( response ) {
					update_cart_totals_div( response );
				},
				complete: function() {
					unblock( $( 'div.cart_totals' ) );
					$( document.body ).trigger( 'updated_shipping_method' );
				}
			} );
		},

		/**
		 * Handles a shipping calculator form submit.
		 *
		 * @param {Object} evt The JQuery event.
		 */
		shipping_calculator_submit: function( evt ) {
			evt.preventDefault();

			var $form = $( evt.currentTarget );

			block( $( 'div.cart_totals' ) );
			block( $form );

			// Provide the submit button value because wc-form-handler expects it.
			$( '<input />' ).attr( 'type', 'hidden' )
							.attr( 'name', 'calc_shipping' )
							.attr( 'value', 'x' )
							.appendTo( $form );

			// Make call to actual form post URL.
			$.ajax( {
				type:     $form.attr( 'method' ),
				url:      $form.attr( 'action' ),
				data:     $form.serialize(),
				dataType: 'html',
				success:  function( response ) {
					update_wc_div( response );
				},
				complete: function() {
					unblock( $form );
					unblock( $( 'div.cart_totals' ) );
				}
			} );
		}
	};

	/**
	 * Object to handle cart UI.
	 */
	var cart = {
		/**
		 * Initialize cart UI events.
		 */
		init: function() {
			this.update_cart_totals    = this.update_cart_totals.bind( this );
			this.input_keypress        = this.input_keypress.bind( this );
			this.cart_submit           = this.cart_submit.bind( this );
			this.submit_click          = this.submit_click.bind( this );
			this.apply_coupon          = this.apply_coupon.bind( this );
			this.remove_coupon_clicked = this.remove_coupon_clicked.bind( this );
			this.quantity_update       = this.quantity_update.bind( this );
			this.item_remove_clicked   = this.item_remove_clicked.bind( this );
			this.update_cart           = this.update_cart.bind( this );

			$( document ).on(
				'wc_update_cart',
				this.update_cart );
			$( document ).on(
				'click',
				'.woocommerce-cart-form input[type=submit]',
				this.submit_click );
			$( document ).on(
				'keypress',
				'.woocommerce-cart-form input[type=number]',
				this.input_keypress );
			$( document ).on(
				'submit',
				'.woocommerce-cart-form',
				this.cart_submit );
			$( document ).on(
				'click',
				'a.woocommerce-remove-coupon',
				this.remove_coupon_clicked );
			$( document ).on(
				'click',
				'.woocommerce-cart-form .product-remove > a',
				this.item_remove_clicked );
			$( document ).on(
				'change input',
				'.woocommerce-cart-form .cart_item :input',
				this.input_changed );

			$( '.woocommerce-cart-form input[name="update_cart"]' ).prop( 'disabled', true );
		},

		/**
		 * After an input is changed, enable the update cart button.
		 */
		input_changed: function() {
			$( '.woocommerce-cart-form input[name="update_cart"]' ).prop( 'disabled', false );
		},

		/**
		 * Update entire cart via ajax.
		 */
		update_cart: function( preserve_notices ) {
			var $form = $( '.woocommerce-cart-form' );

			block( $form );
			block( $( 'div.cart_totals' ) );

			// Make call to actual form post URL.
			$.ajax( {
				type:     $form.attr( 'method' ),
				url:      $form.attr( 'action' ),
				data:     $form.serialize(),
				dataType: 'html',
				success:  function( response ) {
					update_wc_div( response, preserve_notices );
				},
				complete: function() {
					unblock( $form );
					unblock( $( 'div.cart_totals' ) );
				}
			} );
		},

		/**
		 * Update the cart after something has changed.
		 */
		update_cart_totals: function() {
			block( $( 'div.cart_totals' ) );

			$.ajax( {
				url:      get_url( 'get_cart_totals' ),
				dataType: 'html',
				success:  function( response ) {
					update_cart_totals_div( response );
				},
				complete: function() {
					unblock( $( 'div.cart_totals' ) );
				}
			} );
		},

		/**
		 * Handle the <ENTER> key for quantity fields.
		 *
		 * @param {Object} evt The JQuery event
		 *
		 * For IE, if you hit enter on a quantity field, it makes the
		 * document.activeElement the first submit button it finds.
		 * For us, that is the Apply Coupon button. This is required
		 * to catch the event before that happens.
		 */
		input_keypress: function( evt ) {

			// Catch the enter key and don't let it submit the form.
			if ( 13 === evt.keyCode ) {
				evt.preventDefault();
				this.cart_submit( evt );
			}
		},

		/**
		 * Handle cart form submit and route to correct logic.
		 *
		 * @param {Object} evt The JQuery event
		 */
		cart_submit: function( evt ) {
			var $submit = $( document.activeElement );
			var $clicked = $( 'input[type=submit][clicked=true]' );
			var $form = $( evt.currentTarget );

			// For submit events, currentTarget is form.
			// For keypress events, currentTarget is input.
			if ( ! $form.is( 'form' ) ) {
				$form = $( evt.currentTarget ).parents( 'form' );
			}

			if ( 0 === $form.find( '.woocommerce-cart-form__contents' ).length ) {
				return;
			}

			if ( is_blocked( $form ) ) {
				return false;
			}

			if ( $clicked.is( 'input[name="update_cart"]' ) || $submit.is( 'input.qty' ) ) {
				evt.preventDefault();
				this.quantity_update( $form );

			} else if ( $clicked.is( 'input[name="apply_coupon"]' ) || $submit.is( '#coupon_code' ) ) {
				evt.preventDefault();
				this.apply_coupon( $form );
			}
		},

		/**
		 * Special handling to identify which submit button was clicked.
		 *
		 * @param {Object} evt The JQuery event
		 */
		submit_click: function( evt ) {
			$( 'input[type=submit]', $( evt.target ).parents( 'form' ) ).removeAttr( 'clicked' );
			$( evt.target ).attr( 'clicked', 'true' );
		},

		/**
		 * Apply Coupon code
		 *
		 * @param {JQuery Object} $form The cart form.
		 */
		apply_coupon: function( $form ) {
			block( $form );

			var cart = this;
			var $text_field = $( '#coupon_code' );
			var coupon_code = $text_field.val();

			var data = {
				security: wc_cart_params.apply_coupon_nonce,
				coupon_code: coupon_code
			};

			$.ajax( {
				type:     'POST',
				url:      get_url( 'apply_coupon' ),
				data:     data,
				dataType: 'html',
				success: function( response ) {
					$( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove();
					show_notice( response );
					$( document.body ).trigger( 'applied_coupon', [ coupon_code ] );
				},
				complete: function() {
					unblock( $form );
					$text_field.val( '' );
					cart.update_cart( true );
				}
			} );
		},

		/**
		 * Handle when a remove coupon link is clicked.
		 *
		 * @param {Object} evt The JQuery event
		 */
		remove_coupon_clicked: function( evt ) {
			evt.preventDefault();

			var cart     = this;
			var $wrapper = $( evt.currentTarget ).closest( '.cart_totals' );
			var coupon   = $( evt.currentTarget ).attr( 'data-coupon' );

			block( $wrapper );

			var data = {
				security: wc_cart_params.remove_coupon_nonce,
				coupon: coupon
			};

			$.ajax( {
				type:    'POST',
				url:      get_url( 'remove_coupon' ),
				data:     data,
				dataType: 'html',
				success: function( response ) {
					$( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove();
					show_notice( response );
					$( document.body ).trigger( 'removed_coupon', [ coupon ] );
					unblock( $wrapper );
				},
				complete: function() {
					cart.update_cart( true );
				}
			} );
		},

		/**
		 * Handle a cart Quantity Update
		 *
		 * @param {JQuery Object} $form The cart form.
		 */
		quantity_update: function( $form ) {
			block( $form );
			block( $( 'div.cart_totals' ) );

			// Provide the submit button value because wc-form-handler expects it.
			$( '<input />' ).attr( 'type', 'hidden' )
							.attr( 'name', 'update_cart' )
							.attr( 'value', 'Update Cart' )
							.appendTo( $form );

			// Make call to actual form post URL.
			$.ajax( {
				type:     $form.attr( 'method' ),
				url:      $form.attr( 'action' ),
				data:     $form.serialize(),
				dataType: 'html',
				success:  function( response ) {
					update_wc_div( response );
				},
				complete: function() {
					unblock( $form );
					unblock( $( 'div.cart_totals' ) );
				}
			} );
		},

		/**
		 * Handle when a remove item link is clicked.
		 *
		 * @param {Object} evt The JQuery event
		 */
		item_remove_clicked: function( evt ) {
			evt.preventDefault();

			var $a = $( evt.currentTarget );
			var $form = $a.parents( 'form' );

			block( $form );
			block( $( 'div.cart_totals' ) );

			$.ajax( {
				type:     'GET',
				url:      $a.attr( 'href' ),
				dataType: 'html',
				success: update_wc_div,
				complete: function() {
					unblock( $form );
					unblock( $( 'div.cart_totals' ) );
				}
			} );
		}
	};

	cart_shipping.init( cart );
	cart.init();
} );

(function ($) {
    "use strict";
    
    var screenHeight = $(document).height();
    var screenWidth = $(window).width();
    var $rtl = false;
    if (jQuery("html").attr("dir") === 'rtl') {
        $rtl = true;
    }
    var midStackEl = $('.site-header.mid-stack.fixed .bot-section-wrap');
    if (midStackEl.length > 0) {
        var sticky = new Waypoint.Sticky({
            element: $('.site-header.mid-stack.fixed .bot-section-wrap')[0]
        });
    }

    var midInlineEl = $('.site-header.mid-inline.fixed .middle-section-wrap');
    if (midInlineEl.length > 0) {
        var sticky = new Waypoint.Sticky({
            element: $('.site-header.mid-inline.fixed .middle-section-wrap')[0]
        });
    }

    var leftInlineEl = $('.site-header.left-inline.fixed .middle-section-wrap');
    if (leftInlineEl.length > 0) {
        var sticky = new Waypoint.Sticky({
            element: $('.site-header.left-inline.fixed .middle-section-wrap')[0]
        });
    }

    var leftStackEl = $('.site-header.left-stack.fixed .bot-section-wrap');
    if (leftStackEl.length > 0) {
        var sticky = new Waypoint.Sticky({
            element: $('.site-header.left-stack.fixed .bot-section-wrap')[0]
        });
    }

    $('.widget_nav_menu .menu-item-has-children > a').on('click', function (e) {
        e.preventDefault();
        $(this).next('.sub-menu').first().slideToggle('fast');
    });

    if (typeof nbfoody === 'undefined') {
        return;
    }

    function menuPosition() {
        if ($('.main-navigation ul.sub-menu').length) {
            $('.main-navigation ul.sub-menu').each(function () {
                $(this).removeAttr("style");
                var $containerWidth = $("body").outerWidth();
                var $menuwidth = $(this).outerWidth();
                var $parentleft = $(this).parent().offset().left;
                var $parentright = $(this).parent().offset().left + $(this).parent().outerWidth();
                if ($(this).parents('.sub-menu').length) {
                    var $menuleft = $parentleft - $(this).outerWidth();
                    var $menuright = $parentright + $(this).outerWidth();
                    if ($rtl) {
                        if ($menuleft < 0) {
                            if ($menuright > $containerWidth) {
                                if ($parentleft > ($containerWidth - $parentright)) {
                                    $(this).css({
                                        'width': $parentleft + 'px',
                                        'left': 'auto',
                                        'right': '100%'
                                    });
                                    $(this).removeClass('sub-menu-right');
                                    $(this).addClass('sub-menu-left');
                                } else {
                                    $(this).css({
                                        'width': ($containerWidth - $parentright) + 'px',
                                        'left': '100%',
                                        'right': 'auto'
                                    });
                                    $(this).removeClass('sub-menu-left');
                                    $(this).addClass('sub-menu-right');
                                }
                            } else {
                                $(this).css({
                                    'left': '100%',
                                    'right': 'auto'
                                });
                                $(this).removeClass('sub-menu-left');
                                $(this).addClass('sub-menu-right');
                            }
                        } else {
                            $(this).css({
                                'left': 'auto',
                                'right': '100%'
                            });
                            $(this).removeClass('sub-menu-right');
                            $(this).addClass('sub-menu-left');
                        }
                    } else {
                        if ($menuright > $containerWidth) {
                            if ($menuleft < 0) {
                                if ($parentleft > ($containerWidth - $parentright)) {
                                    $(this).css({
                                        'width': $parentleft + 'px',
                                        'left': 'auto',
                                        'right': '100%'
                                    });
                                    $(this).removeClass('sub-menu-right');
                                    $(this).addClass('sub-menu-left');
                                } else {
                                    $(this).css({
                                        'width': ($containerWidth - $parentright) + 'px',
                                        'left': '100%',
                                        'right': 'auto'
                                    });
                                    $(this).removeClass('sub-menu-left');
                                    $(this).addClass('sub-menu-right');
                                }
                            } else {
                                $(this).css({
                                    'left': 'auto',
                                    'right': '100%'
                                });
                                $(this).removeClass('sub-menu-right');
                                $(this).addClass('sub-menu-left');
                            }
                        } else {
                            $(this).css({
                                'left': '100%'
                            });
                            $(this).removeClass('sub-menu-left');
                            $(this).addClass('sub-menu-right');
                        }
                    }
                } else {
                    var $menuleft = $parentright - $(this).outerWidth();
                    var $menuright = $parentleft + $(this).outerWidth();
                    if ($rtl) {
                        if ($menuleft < 0) {
                            if ($menuright > $containerWidth) {
                                $(this).offset({
                                    'left': ($containerWidth - $menuwidth) / 2
                                });
                            } else {
                                $(this).offset({
                                    'left': $parentleft
                                });
                            }
                        } else {
                            $(this).offset({
                                'left': $menuleft
                            });
                        }
                    } else {
                        if ($menuright > $containerWidth) {
                            if ($menuleft < 0) {
                                $(this).offset({
                                    'left': ($containerWidth - $menuwidth) / 2
                                });
                            } else {
                                $(this).offset({
                                    'left': $menuleft
                                });
                            }
                        } else {
                            $(this).offset({
                                'left': $parentleft
                            });
                        }
                    }
                }
            });
        }
    }
    function menuShow() {
        $('.main-navigation .menu-main-menu-wrap').addClass('active');
    }
    function menuHide() {
        $('.main-navigation .menu-main-menu-wrap').removeClass('active');
        $('.main-navigation .menu-item-has-children').removeClass('open');
    }
    function menuResponsive() {
        var screenHeight = jQuery(document).height();
        var screenWidth = jQuery(window).width();
        if ($('.navigation_right .menu-sub-menu-container').length) {
            if (screenWidth < nbfoody.menu_resp) {
                $('.navigation_right #menu-sub-menu').appendTo('.navigation_left .menu-main-menu-container');
                $('.main-navigation').appendTo('.navigation_right');
            } else {
                $('.main-navigation').appendTo('.navigation_left');
                $('.navigation_left #menu-sub-menu').appendTo('.navigation_right .menu-sub-menu-container');
            }
        } else {
            if ($('.main-menu-section .nb-header-sub-menu').length) {
                $('.main-menu-section .nb-header-sub-menu > li').appendTo('.nb-navbar');
                $('.main-menu-section .sub-navigation').remove();
            }
        }
        if (screenWidth < nbfoody.menu_resp) {
            $('.site-header').addClass('header-mobile');
            $('.main-navigation').removeClass('main-desktop-navigation');
            $('.main-navigation').addClass('main-mobile-navigation');
        } else {
            $('.site-header').removeClass('header-mobile');
            $('.main-navigation').removeClass('main-mobile-navigation');
            $('.main-navigation').addClass('main-desktop-navigation');
            $('.main-navigation .menu-main-menu-wrap').removeAttr('style');
            $('.main-navigation .menu-item-has-children').removeClass('open');
            menuPosition();
        }
    }
    menuResponsive();
    $('.main-navigation .mobile-toggle-button').on('click', function () {
        menuShow();
    });
    $('.main-navigation .icon-cancel-circle').on('click', function () {
        menuHide();
    });
    $('.main-navigation .menu-item-has-children').on('click', function () {
        $(this).toggleClass('open');

    });
    $('.main-navigation .menu-item-has-children > *').on('click', function (e) {
        e.stopPropagation();
    });
    $(window).on('resize', function () {
        menuResponsive();
    });

    $('.blog .masonry').isotope({
        itemSelector: '.post'
    });

    var d = 0;
    var $numbertype = null;

    var quantityButton = function () {
        $(".quantity-plus, .quantity-minus").mousedown(function () {
            var $el = $(this).closest('.nb-quantity').find('.qty');
            $numbertype = parseInt($el.val());
            d = $(this).is(".quantity-minus") ? -1 : 1;
            $numbertype = $numbertype + d;
            if ($numbertype > 0) {
                $el.val($numbertype);
            }

        });
    };
    quantityButton();

    if (jQuery().magnificPopup) {
        $('.featured-gallery').magnificPopup({
            delegate: 'img',
            type: 'image',
            gallery: {
                enabled: true
            },
            callbacks: {
                elementParse: function (item) {
                    item.src = item.el.attr('src');
                }
            }
        });
        $('.popup-search').magnificPopup({
            type: 'inline',
            focus: '.search-field',
            // modal: true,
            // midClick: true
            mainClass: 'mfp-search',
            callbacks: {
                beforeOpen: function () {
                    if ($(window).width() < 700) {
                        this.st.focus = false;
                    } else {
                        this.st.focus = '.search-field';
                    }
                }
            }
        });
        $(document).on('click', '.popup-modal-dismiss', function (e) {
            e.preventDefault();
            $.magnificPopup.close();
        });
    }

    var $upsells = $('.upsells .products');
    var $upsellsCells = $upsells.find('.product');

    if ($upsellsCells.length <= nbfoody.upsells_columns) {
        $upsells.addClass('hiding-nav-ui');
    }

    var $related = $('.related .products');
    var $relatedCells = $related.find('.product');

    if ($relatedCells.length <= nbfoody.related_columns) {
        $related.addClass('hiding-nav-ui');
    }

    var $crossSells = $('.cross-sells .products');
    var $crossSellsCells = $crossSells.find('.product');

    if ($crossSellsCells.length <= nbfoody.cross_sells_columns) {
        $crossSells.addClass('hiding-nav-ui');
    }

    if (jQuery().accordion) {
        $('.shop-main.accordion-tabs .wc-tabs').accordion({
            header: ".accordion-title-wrap",
            heightStyle: "content"
        });
    }

    $('.header-cart-wrap').on({
        mouseenter: function () {
            $(this).find('.mini-cart-section').stop().fadeIn('fast');
        },
        mouseleave: function () {
            $(this).find('.mini-cart-section').stop().fadeOut('fast');
        }
    });

    $('.header-account-wrap').on({
        mouseenter: function () {
            $(this).find('.nb-account-dropdown').stop().fadeIn('fast');
        },
        mouseleave: function () {
            $(this).find('.nb-account-dropdown').stop().fadeOut('fast');
        }
    });

    $(document.body).on('added_to_cart', function () {
        $(".cart-notice-wrap").addClass("active").delay(5000).queue(function (next) {
            $(this).removeClass("active");
            next();
        });
    });

    $('.cart-notice-wrap span').on('click', function () {
        $(this).closest('.cart-notice-wrap').removeClass('active');
    });

    var $sticky = $('.sticky-wrapper.sticky-sidebar');

    if ($sticky.length > 0) {
        $($sticky).stick_in_parent({
            offset_top: 45
        });

        $(window).on('resize', function () {
            $($sticky).trigger('sticky_kit:detach');
        });
    }

    if ($('#back-to-top-button').length) {
        var scrollTrigger = 500; // px
        var backToTop = function () {
            var scrollTop = $(window).scrollTop();
            if (scrollTop > scrollTrigger) {
                $('#back-to-top-button').addClass('show');
            } else {
                $('#back-to-top-button').removeClass('show');
            }
        };
        backToTop();
        $(window).on('scroll', function () {
            backToTop();
        });
        $('#back-to-top-button').on('click', function (e) {
            e.preventDefault();
            $('html,body').animate({
                scrollTop: 0
            }, 700);
        });
    }
    if ($('.related .swiper-container').length) {
        var slidesm = 2;
        var slidemd = 2;
        var slidelg = 3;
        if (nbfoody.related_columns == 2) {
            slidesm = 1;
            slidemd = 1;
        }
        var related = new Swiper('.related .swiper-container', {
            slidesPerView: nbfoody.related_columns,
            spaceBetween: 0,
            pagination: '.swiper-pagination',
            paginationClickable: true,
            breakpoints: {
                1199: {
                    slidesPerView: slidelg
                },
                991: {
                    slidesPerView: slidemd
                },
                767: {
                    slidesPerView: slidesm
                },
                575: {
                    slidesPerView: 1
                }
            }
        });
    }
    if ($('.upsells .swiper-container').length) {
        var slidesm = 2;
        var slidemd = 3;
        if (nbfoody.upsells_columns == 2) {
            slidesm = 1;
            slidemd = 1;
        }
        var upsells = new Swiper('.upsells .swiper-container', {
            slidesPerView: nbfoody.upsells_columns,
            spaceBetween: 0,
            pagination: '.swiper-pagination',
            paginationClickable: true,
            breakpoints: {
                991: {
                    slidesPerView: slidemd
                },
                767: {
                    slidesPerView: slidesm
                },
                575: {
                    slidesPerView: 1
                }
            }
        });
    }
    if ($('.cross-sells .swiper-container').length) {
        var slidemd = 3;
        var slidelg = 4;
        if (nbfoody.cross_sells_columns == 3) {
            slidemd = 2;
            slidelg = 3;
        }
        var crossSells = new Swiper('.cross-sells .swiper-container', {
            slidesPerView: nbfoody.cross_sells_columns,
            spaceBetween: 30,
            pagination: '.swiper-pagination',
            paginationClickable: true,
            breakpoints: {
                1199: {
                    slidesPerView: slidelg
                },
                991: {
                    slidesPerView: slidemd
                },
                767: {
                    slidesPerView: 2
                },
                575: {
                    slidesPerView: 1
                }
            }
        });
    }
    var swiperInit = function () {
        if ($('.featured-gallery').length && $('.thumb-gallery').length) {
            var featuredObj = {};

            if (nbfoody.thumb_pos !== 'right-dots') {
                featuredObj.nextButton = '.swiper-button-next';
                featuredObj.prevButton = '.swiper-button-prev';

                var galleryTop = new Swiper('.featured-gallery', featuredObj);

                var thumbObj = {
                    spaceBetween: 30,
                    centeredSlides: true,
                    slidesPerView: 3,
                    touchRatio: 0.2,
                    slideToClickedSlide: true
                };

                if (nbfoody.thumb_pos === 'left-thumb' || nbfoody.thumb_pos === 'inside-thumb') {
                    thumbObj.direction = 'vertical';
                }

                var galleryThumbs = new Swiper('.thumb-gallery', thumbObj);
                galleryTop.params.control = galleryThumbs;
                galleryThumbs.params.control = galleryTop;
            } else {
                featuredObj.pagination = '.featured-gallery .swiper-pagination';
                featuredObj.paginationClickable = true;

                var galleryTop = new Swiper('.featured-gallery', featuredObj);
            }
        }
    };
    swiperInit();

    var isMobile = false;
    var $variation_form = $('.variations_form');
    var $product_variations = $variation_form.data('product_variations');
    $('body').on('click touchstart', 'li.swatch-item', function () {
        var current = $(this);
        var value = current.attr('data-optionvalue');
        var selector_name = current.closest('ul').attr('data-id');
        if ($("select#" + selector_name).find('option[value="' + value + '"]').length > 0)
        {
            $(this).closest('ul').children('li').each(function () {
                $(this).removeClass('selected');
                $(this).removeClass('disable');
            });
            if (!$(this).hasClass('selected'))
            {
                current.addClass('selected');
                $("select#" + selector_name).val(value).change();
                $("select#" + selector_name).trigger('change');
                $variation_form.trigger('wc_variation_form');
                $variation_form
                        .trigger('woocommerce_variation_select_change')
                        .trigger('check_variations', ['', false]);
            }
        } else {
            current.addClass('disable');
        }
    });

    $variation_form.on('wc_variation_form', function () {
        $(this).on('click', '.reset_variations', function (event) {
            $(this).parents('.variations').eq(0).find('ul.swatch li').removeClass('selected');
        });
    });
    var $single_variation_wrap = $variation_form.find('.single_variation_wrap');
    $single_variation_wrap.on('show_variation', function (event, variation) {
        var $product = $variation_form.closest('.product');
        if (variation.image_link)
        {
            var variation_image = variation.image_link;
            $product.find('.main-image a').attr('href', variation_image);
            $product.find('.main-image a img').attr('src', variation.image_src);
            $product.find('.main-image a img').attr('srcset', variation.image_srcset);
            $product.find('.main-image a img').attr('alt', variation.image_alt);
            $product.find('.main-image a img').attr('title', variation.image_title);
            $product.find('.main-image a img').attr('sizes', variation.image_sizes);
            $product.find('.main-image img').attr('data-large', variation_image);
        }
    });

    var qv_modal = $(document).find('#yith-quick-view-modal'),
            qv_overlay = qv_modal.find('.yith-quick-view-overlay'),
            qv_content = qv_modal.find('#yith-quick-view-content'),
            qv_close = qv_modal.find('#yith-quick-view-close'),
            qv_wrapper = qv_modal.find('.yith-wcqv-wrapper'),
            qv_wrapper_w = qv_wrapper.width(),
            qv_wrapper_h = qv_wrapper.height(),
            center_modal = function () {

                var window_w = $(window).width(),
                        window_h = $(window).height(),
                        width = ((window_w - 60) > qv_wrapper_w) ? qv_wrapper_w : (window_w - 60),
                        height = ((window_h - 120) > qv_wrapper_h) ? qv_wrapper_h : (window_h - 120);

                qv_wrapper.css({
                    'left': ((window_w / 2) - (width / 2)),
                    'top': ((window_h / 2) - (height / 2)),
                    'width': width + 'px',
                    'height': height + 'px'
                });
            };

    /*==================
     *MAIN BUTTON OPEN
     ==================*/

    $.fn.yith_quick_view = function () {

        $(document).off('click', '.yith-wcqv-button').on('click', '.yith-wcqv-button', function (e) {
            e.preventDefault();

            var t = $(this),
                    product_id = t.data('product_id');

            t.block({
                message: null,
                overlayCSS: {
                    background: '#fff url(' + nbfoody.loader + ') no-repeat center',
                    opacity: 0.5,
                    cursor: 'none'
                }
            });

            t.addClass('loading');

            setTimeout(function () {
                t.removeClass('loading');
            }, 3000);

            if (!qv_modal.hasClass('loading')) {
                qv_modal.addClass('loading');
            }

            // stop loader
            $(document).trigger('qv_loading');
            ajax_call(t, product_id, true);
        });
    };

    /*================
     * MAIN AJAX CALL
     ================*/

    var ajax_call = function (t, product_id, is_blocked) {

        $.ajax({
            url: nbfoody.ajaxurl,
            data: {
                action: 'yith_load_product_quick_view',
                product_id: product_id
            },
            dataType: 'html',
            type: 'POST',
            success: function (data) {

                qv_content.html(data);

                // quantity fields for WC 2.2
                if (nbfoody.is2_2) {
                    qv_content.find('div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)').addClass('buttons_added').append('<input type="button" value="+" class="plus" />').prepend('<input type="button" value="-" class="minus" />');
                }

                // Variation Form
                var form_variation = qv_content.find('.variations_form');

                form_variation.wc_variation_form();
                form_variation.trigger('check_variations');

                if (typeof $.fn.yith_wccl !== 'undefined') {
                    form_variation.yith_wccl();
                }

                // Init prettyPhoto
                if (typeof $.fn.prettyPhoto !== 'undefined') {
                    qv_content.find("a[data-rel^='prettyPhoto'], a.zoom").prettyPhoto({
                        hook: 'data-rel',
                        social_tools: false,
                        theme: 'pp_woocommerce',
                        horizontal_padding: 20,
                        opacity: 0.8,
                        deeplinking: false
                    });
                }

                if (!qv_modal.hasClass('open')) {
                    qv_modal.removeClass('loading').addClass('open');
                    if (is_blocked)
                        t.unblock();
                }

                // stop loader
                $(document).trigger('qv_loader_stop');
                swiperInit();
                quantityButton();
            }
        });
    };

    /*===================
     * CLOSE QUICK VIEW
     ===================*/

    var close_modal_qv = function () {

        // Close box by click overlay
        qv_overlay.on('click', function (e) {
            close_qv();
        });
        // Close box with esc key
        $(document).keyup(function (e) {
            if (e.keyCode === 27)
                close_qv();
        });
        // Close box by click close button
        qv_close.on('click', function (e) {
            e.preventDefault();
            close_qv();
        });

        var close_qv = function () {
            qv_modal.removeClass('open').removeClass('loading');

            setTimeout(function () {
                qv_content.html('');
            }, 1000);
        };
    };

    close_modal_qv();


    center_modal();
    $(window).on('resize', center_modal);

    // START
    $.fn.yith_quick_view();

    $(document).on('yith_infs_adding_elem yith-wcan-ajax-filtered', function () {
        // RESTART
        $.fn.yith_quick_view();
    });

    // $('.add_to_wishlist').on('click', function() {
    // $(this).find('.icon-heart').hide();
    // });

    if ("function" !== typeof window.vc_prettyPhoto) {
        var vc_prettyPhoto = function () {
            try {
                $ && $.fn && $.fn.prettyPhoto && $('a.prettyphoto').prettyPhoto({
                    animationSpeed: "normal",
                    hook: "data-rel",
                    padding: 15,
                    opacity: .7,
                    default_width: 300,
                    showTitle: !0,
                    allowresize: !1,
                    counter_separator_label: "/",
                    hideflash: !1,
                    deeplinking: !1,
                    modal: !1,
                    callback: function () {
                        location.href.indexOf("#!prettyPhoto") > -1 && (location.hash = "");
                    },
                    social_tools: ""
                });
            } catch (err) {
                window.console && window.console.log && console.log(err);
            }
        };
        vc_prettyPhoto();
    }
})(jQuery);