/**
 * Eighteen tags class
 * @developer http://wpdevelopment.me <shramee@wpdevelopment.me>
 */

/*!
 * imagesLoaded PACKAGED v4.1.0
 * JavaScript is all like "You images are done yet or what?"
 * MIT License
 */

!function(t,e){"function"==typeof define&&define.amd?define("ev-emitter/ev-emitter",e):"object"==typeof module&&module.exports?module.exports=e():t.EvEmitter=e()}(this,function(){function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var i=this._events=this._events||{},n=i[t]=i[t]||[];return-1==n.indexOf(e)&&n.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var i=this._onceEvents=this._onceEvents||{},n=i[t]=i[t]||[];return n[e]=!0,this}},e.off=function(t,e){var i=this._events&&this._events[t];if(i&&i.length){var n=i.indexOf(e);return-1!=n&&i.splice(n,1),this}},e.emitEvent=function(t,e){var i=this._events&&this._events[t];if(i&&i.length){var n=0,o=i[n];e=e||[];for(var r=this._onceEvents&&this._onceEvents[t];o;){var s=r&&r[o];s&&(this.off(t,o),delete r[o]),o.apply(this,e),n+=s?0:1,o=i[n]}return this}},t}),function(t,e){"use strict";"function"==typeof define&&define.amd?define(["ev-emitter/ev-emitter"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("ev-emitter")):t.imagesLoaded=e(t,t.EvEmitter)}(window,function(t,e){function i(t,e){for(var i in e)t[i]=e[i];return t}function n(t){var e=[];if(Array.isArray(t))e=t;else if("number"==typeof t.length)for(var i=0;i<t.length;i++)e.push(t[i]);else e.push(t);return e}function o(t,e,r){return this instanceof o?("string"==typeof t&&(t=document.querySelectorAll(t)),this.elements=n(t),this.options=i({},this.options),"function"==typeof e?r=e:i(this.options,e),r&&this.on("always",r),this.getImages(),h&&(this.jqDeferred=new h.Deferred),void setTimeout(function(){this.check()}.bind(this))):new o(t,e,r)}function r(t){this.img=t}function s(t,e){this.url=t,this.element=e,this.img=new Image}var h=t.jQuery,a=t.console;o.prototype=Object.create(e.prototype),o.prototype.options={},o.prototype.getImages=function(){this.images=[],this.elements.forEach(this.addElementImages,this)},o.prototype.addElementImages=function(t){"IMG"==t.nodeName&&this.addImage(t),this.options.background===!0&&this.addElementBackgroundImages(t);var e=t.nodeType;if(e&&d[e]){for(var i=t.querySelectorAll("img"),n=0;n<i.length;n++){var o=i[n];this.addImage(o)}if("string"==typeof this.options.background){var r=t.querySelectorAll(this.options.background);for(n=0;n<r.length;n++){var s=r[n];this.addElementBackgroundImages(s)}}}};var d={1:!0,9:!0,11:!0};return o.prototype.addElementBackgroundImages=function(t){var e=getComputedStyle(t);if(e)for(var i=/url\((['"])?(.*?)\1\)/gi,n=i.exec(e.backgroundImage);null!==n;){var o=n&&n[2];o&&this.addBackground(o,t),n=i.exec(e.backgroundImage)}},o.prototype.addImage=function(t){var e=new r(t);this.images.push(e)},o.prototype.addBackground=function(t,e){var i=new s(t,e);this.images.push(i)},o.prototype.check=function(){function t(t,i,n){setTimeout(function(){e.progress(t,i,n)})}var e=this;return this.progressedCount=0,this.hasAnyBroken=!1,this.images.length?void this.images.forEach(function(e){e.once("progress",t),e.check()}):void this.complete()},o.prototype.progress=function(t,e,i){this.progressedCount++,this.hasAnyBroken=this.hasAnyBroken||!t.isLoaded,this.emitEvent("progress",[this,t,e]),this.jqDeferred&&this.jqDeferred.notify&&this.jqDeferred.notify(this,t),this.progressedCount==this.images.length&&this.complete(),this.options.debug&&a&&a.log("progress: "+i,t,e)},o.prototype.complete=function(){var t=this.hasAnyBroken?"fail":"done";if(this.isComplete=!0,this.emitEvent(t,[this]),this.emitEvent("always",[this]),this.jqDeferred){var e=this.hasAnyBroken?"reject":"resolve";this.jqDeferred[e](this)}},r.prototype=Object.create(e.prototype),r.prototype.check=function(){var t=this.getIsImageComplete();return t?void this.confirm(0!==this.img.naturalWidth,"naturalWidth"):(this.proxyImage=new Image,this.proxyImage.addEventListener("load",this),this.proxyImage.addEventListener("error",this),this.img.addEventListener("load",this),this.img.addEventListener("error",this),void(this.proxyImage.src=this.img.src))},r.prototype.getIsImageComplete=function(){return this.img.complete&&void 0!==this.img.naturalWidth},r.prototype.confirm=function(t,e){this.isLoaded=t,this.emitEvent("progress",[this,this.img,e])},r.prototype.handleEvent=function(t){var e="on"+t.type;this[e]&&this[e](t)},r.prototype.onload=function(){this.confirm(!0,"onload"),this.unbindEvents()},r.prototype.onerror=function(){this.confirm(!1,"onerror"),this.unbindEvents()},r.prototype.unbindEvents=function(){this.proxyImage.removeEventListener("load",this),this.proxyImage.removeEventListener("error",this),this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},s.prototype=Object.create(r.prototype),s.prototype.check=function(){this.img.addEventListener("load",this),this.img.addEventListener("error",this),this.img.src=this.url;var t=this.getIsImageComplete();t&&(this.confirm(0!==this.img.naturalWidth,"naturalWidth"),this.unbindEvents())},s.prototype.unbindEvents=function(){this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},s.prototype.confirm=function(t,e){this.isLoaded=t,this.emitEvent("progress",[this,this.element,e])},o.makeJQueryPlugin=function(e){e=e||t.jQuery,e&&(h=e,h.fn.imagesLoaded=function(t,e){var i=new o(this,t,e);return i.jqDeferred.promise(h(this))})},o.makeJQueryPlugin(),o});

/**
 * Public end styling
 * @author shramee <shramee.srivastav@gmail.com>
 * @package eighteen-tags pro
 */
jQuery( document ).ready( function ( $ ) {
	var $window = $( window ),
		windowWidth = $window.width(),
		$body = $( 'body' ),
		$layoutButts = $( '.layout-buttons' ),
		$products = $('.post-type-archive-product .products' ),
		gutter = parseInt( $products.children( '.product:first' ).css( 'margin-right' ) );

//Fixing mega menu in multi line nav
	$( '.main-navigation' ).find( 'li.mega-menu' ).each( function() {
		var $t = $( this ),
			$offset = $t.offset().top - $t.closest('.main-navigation').offset().top + $t.height();
		$t.children('.sub-menu' ).css( 'top', $offset );
	} );

//Skrollr
	if (
		! ( /Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i )
			.test( navigator.userAgent || navigator.vendor || window.opera )
	) {
		skrollr.init( { forceHeight : false } );
	}

	if ( windowWidth > 767 ) {

		var $navbar = $( '#site-navigation' ),
				$navSearch = $navbar.children( '.etp-nav-search' );
		if ( $navbar.children( '.primary-navigation' ).length ) {
			var navHi = $navbar.innerHeight();
			$navbar.find( '.etp-search ul' ).hide();
			$navbar.css( 'height', navHi );

			$( window ).resize( function() {
				navHi = $navbar.innerHeight();
				$navbar.css( 'height', navHi );
			} );

			toggleSearch = function () {
				$navbar.toggleClass( 'show-search' );
				$navbar.children( '.primary-navigation, .site-header-cart' ).slideToggle( { easing : 'linear' } );
				$navSearch
					.css( 'top', ( navHi - $navSearch.innerHeight() ) / 2 )
					.slideToggle( { easing : 'linear' } )
					.find( '.search-field' ).val( '' );
			};

			if ( ! $body.hasClass('etp-nav-styleleft-vertical') ) {
				$navbar.find( '.etp-nav-search-close, .etp-search a' ).click( toggleSearch );
			}
		}
	}

//Hamburger Menu
	$('.header-toggle, .hamburger-overlay' ).click( function(){
		$( '#masthead' ).toggleClass( 'hamburger-open' );
		$( '.hamburger-overlay' ).fadeToggle( 200 );
	} );

//Mobile menu
	$('.menu-toggle' ).on( 'click touchend', function( e ){
		e.stopPropagation();
		e.preventDefault();
		var $t = $( this ),
			$handheld = $t.siblings( '.handheld-navigation' );
		if ( 0 == $handheld.length ) {
			$handheld = $t.siblings( 'div.menu' );
			if ( 2 == $handheld.length ) {
				$handheld = $handheld.eq( 1 );
			} else {
				$handheld = $handheld.eq( 0 );
			}
			$handheld = $handheld.find( 'ul' );
		}
		$handheld.slideToggle();
	} );


	$( ".main-navigation .handheld-navigation .menu-item.menu-item-has-children > a" ).click( function ( e ) {
		console.log( e.offsetX + ' ' + e.currentTarget.clientWidth, e.offsetX > e.currentTarget.clientWidth );
		if ( e.offsetX > e.currentTarget.clientWidth ) {
			e.preventDefault();
			jQuery( this ).closest( 'li' ).toggleClass( 'submenu-toggle' );
		}
	} );

} );

/**
 * navigation.js
 * eighteen-tags navigation js to add nav-menu class to first ul in site-navigation
 */
(
	function () {
		var container, button, menu;
		container = document.getElementById( 'site-navigation' );
		if ( ! container ) { return; }
		menu = container.getElementsByTagName( 'ul' )[0];
		if ( 'undefined' === typeof menu ) { return; }
		menu.setAttribute( 'aria-expanded', 'false' );
		if ( - 1 === menu.className.indexOf( 'nav-menu' ) ) { menu.className += ' nav-menu'; }
	}
)();
