// source --> https://www.thegodjourney.com/wp-content/plugins/wp-responsive-menu/assets/js/wprmenu.js?ver=3.2.1 
( function( window ) {

'use strict';

function classReg( className ) {
  return new  ("(^|\\s+)" + className + "(\\s+|$)");
}
// classList support for class management
// although to be fair, the api sucks because it won't accept multiple classes at once
var hasClass, addClass, removeClass;

if ( 'classList' in document.documentElement ) {
  hasClass = function( elem, c ) {
    return elem.classList.contains( c );
  };
  addClass = function( elem, c ) {
    elem.classList.add( c );
  };
  removeClass = function( elem, c ) {
    elem.classList.remove( c );
  };
}
else {
  hasClass = function( elem, c ) {
    return classReg( c ).test( elem.className );
  };
  addClass = function( elem, c ) {
    if ( !hasClass( elem, c ) ) {
      elem.className = elem.className + ' ' + c;
    }
  };
  removeClass = function( elem, c ) {
    elem.className = elem.className.replace( classReg( c ), ' ' );
  };
}

function toggleClass( elem, c ) {
  var fn = hasClass( elem, c ) ? removeClass : addClass;
  fn( elem, c );
}

window.classie = {
  // full names
  hasClass: hasClass,
  addClass: addClass,
  removeClass: removeClass,
  toggleClass: toggleClass,
  // short names
  has: hasClass,
  add: addClass,
  remove: removeClass,
  toggle: toggleClass
};

})( window );

jQuery( document ).ready( function( $ ) {
	
  var	Mgwprm = document.getElementById( 'mg-wprm-wrap' );
	var	wprm_menuDir = document.getElementById( 'wprMenu' );
	body = document.body;
  
  /**
  ----------------------------------------
  * 
  * Body slide from one side ( left, right or top )
  *
  ----------------------------------------
  **/
  if( jQuery('.wprmenu_bar').hasClass('bodyslide') )
    jQuery('body').addClass('cbp-spmenu-push');

	jQuery('.wprmenu_bar').click( function(e) {
		if( $(e.target).hasClass('bar_logo') )
			return;
    
    

		classie.toggle( this, 'active' );
		jQuery(this).find('div.hamburger').toggleClass('is-active');
    
		if( jQuery(this).hasClass('active') ) {
		  jQuery('html').addClass('wprmenu-body-fixed');
      
			if( wprmenu.enable_overlay == '1' ) {
			 jQuery('div.wprm-wrapper').find('.wprm-overlay').addClass('active');
       
       
			}
		}
		else {
			jQuery('html').removeClass('wprmenu-body-fixed');
      
			if( wprmenu.enable_overlay == '1' ) {
				jQuery('div.wprm-wrapper').find('.wprm-overlay').removeClass('active');
			}

      
		}

    /**
    ----------------------------------------
    * 
    * Right side body push
    *
    ----------------------------------------
    **/
		if ( !jQuery(this).hasClass('normalslide') && jQuery(this).hasClass('left')) {
			doc_width = jQuery(document).width() * (wprmenu.menu_width/100);
			push_width = (wprmenu.push_width != '' && wprmenu.push_width < doc_width) ? wprmenu.push_width : doc_width;
			classie.toggle(body, 'cbp-spmenu-push-toright');
			
      if( jQuery('body').hasClass('cbp-spmenu-push-toright') )
				jQuery('body').css('left', push_width + 'px');
			else
				$('body').css('left','0px');
		}

		 /**
    ----------------------------------------
    * 
    * Left side body push
    *
    ----------------------------------------
    **/
		if ( !jQuery(this).hasClass('normalslide') && jQuery(this).hasClass('right')) {
			doc_width = jQuery(document).width() * (wprmenu.menu_width/100);
			push_width = (wprmenu.push_width != '' && wprmenu.push_width < doc_width) ? wprmenu.push_width : doc_width;
			classie.toggle(body, 'cbp-spmenu-push-toleft');
			
      if( jQuery('body').hasClass('cbp-spmenu-push-toleft') )
				jQuery('body').css('left','-'+push_width+'px');
			else
				jQuery('body').css('left','0px');
		}
    
		classie.toggle(Mgwprm, 'cbp-spmenu-open');

    var wprmenuDemoId = wprmenu.wprmenuDemoId;
    
    if ( wprmenuDemoId ==  15 ) {
      
      jQuery('div.wprm-wrapper').addClass('wp-responsive-menu-demo15');
      
    }else if ( wprmenuDemoId ==  16 ) {

      jQuery('div.wprm-wrapper').addClass('wp-responsive-menu-demo16');
      
    }else if ( wprmenuDemoId ==  17 ) {

      jQuery('div.wprm-wrapper').addClass('wp-responsive-menu-demo17');
     
    }

		close_sub_uls();

	});

  /**
  -------------------------------------------------------------
  * 
  * Fix the scaling issue by adding/replacing viewport metatag
  *
  -------------------------------------------------------------
  **/
  var mt = $('meta[name=viewport]');
  mt = mt.length ? mt : $('<meta name="viewport" />').appendTo('head');
  if(wprmenu.zooming == 0) {
    mt.attr('content', 'user-scalable=no, width=device-width, maximum-scale=1, minimum-scale=1');
  } else {
    mt.attr('content', 'user-scalable=yes, width=device-width, initial-scale=1.0, minimum-scale=1');
  }

	/**
  ----------------------------------------
  * 
  * Click on body to remove the menu
  *
  ----------------------------------------
  **/
  $('body').click( function( event ) {
    if ( $( '#wprmenu_bar' ).hasClass( 'active' ) ) {
      $('#wprmenu_bar .wprmenu_icon').addClass('open');
    } 
    else {
      $('#wprmenu_bar .wprmenu_icon').removeClass('open');
    }
  });

	var menu = jQuery('#mg-wprm-wrap');
	var menu_ul = jQuery('#wprmenu_menu_ul'); //the menu ul

	jQuery(document).mouseup(function (e) {
		if ( ($(e.target).hasClass('wprmenu_bar') || $(e.target).parents('.wprmenu_bar').length == 0) && 
			($(e.target).hasClass('cbp-spmenu') || $(e.target).parents('.cbp-spmenu').length == 0)) {
    		if(menu.is(':visible') ) {
				$('.hamburger.is-active').trigger('click');
			}
		}
	});

	//add arrow element to the parent li items and chide its child uls
	menu.find('ul.sub-menu').each(function() {
		var sub_ul = $(this),
		parent_a = sub_ul.prev('a'),
		parent_li = parent_a.parent('li').first();

		parent_a.addClass('wprmenu_parent_item');
		parent_li.addClass('wprmenu_parent_item_li');

		var expand = parent_a.before('<span class="wprmenu_icon wprmenu_icon_par icon_default"></span> ').find('.wprmenu_icon_par');
		sub_ul.hide();
	});


	//expand / collapse action (SUBLEVELS)
	$('.wprmenu_icon_par').on('click',function() {
		var t = $(this),
		child_ul = t.parent('li').find('ul.sub-menu').first(); 
		child_ul.slideToggle('300');
		t.toggleClass('wprmenu_par_opened');
		t.parent('li').first().toggleClass('wprmenu_no_border_bottom');
	});

	//helper - close all submenus when menu is hiding
	function close_sub_uls() {
		menu.find('ul.sub-menu').each(function() {
			var ul = $(this),
			icon = ul.parent('li').find('.wprmenu_icon_par'),
			li = ul.parent('li');

			if(ul.is(':visible')) ul.slideUp(300);
			icon.removeClass('wprmenu_par_opened');
			li.removeClass('wprmenu_no_border_bottom');
		});
	}

	//submenu opened
	function open_sub_uls() {
		menu.find('ul.sub-menu').each(function() {
			var ul = $(this),
			icon = ul.parent('li').find('.wprmenu_icon_par'),
			li = ul.parent('li');

			ul.slideDown(300);
			icon.removeClass('wprmenu_par_opened');
			icon.addClass('wprmenu_par_opened');
		});
	}

	if( menu.hasClass('cbp-spmenu-top') && $('body').hasClass('cbp-spmenu-push') ){
		$('body').prepend(menu);
		//show / hide the menu
		$('#wprmenu_bar,#custom_menu_icon').on('click', function(e) {
			if( $(e.target).hasClass('bar_logo') )
				return;
			//scroll window top
			$("html, body").animate({ scrollTop: 0 }, 300);

			close_sub_uls();
			menu.stop(true, false).slideToggle(300);
		});
	}
	if( wprmenu.parent_click == 'yes' ) {
		$('a.wprmenu_parent_item').on('click', function( event ){
			event.preventDefault();
      var t = $(this);
      // Find the corresponding menu icon and trigger its click
      t.parent('li').find('.wprmenu_icon_par').first().trigger('click');
		});
	}
	$('#wprmenu_menu_ul a').click(function(){
		if( wprmenu.parent_click !='yes' || (wprmenu.parent_click == 'yes' && !$(this).hasClass('wprmenu_parent_item')) )
			$('.hamburger.is-active').trigger('click');
	});


  /**
  ----------------------------------------
  * 
  * Swipe Enable Function
  *
  ----------------------------------------
  **/
	if( wprmenu.swipe == '1' ) {
    jQuery('body').swipe({
      excludedElements: "button, input, select, textarea, .noSwipe",
      longTapThreshold: 200,
      swipe:function(event, direction, distance, duration, fingerCount, fingerData) {
        menu_el = $('.wprmenu_bar .hamburger, .wprmenu_bar .wpr-custom-menu');
        if( direction =='left' && menu_el.hasClass('is-active') )
          menu_el.trigger('click');
        
        
        if( direction =='right' && !menu_el.hasClass('is-active') )
          menu_el.trigger('click');
        
        }
    });
  }

  function toggle_sub_uls($action) {
    $('#mg-wprm-wrap').find('ul.sub-menu').each(function() {
      var ul = $(this),
      icon = ul.parent('li').find('.wprmenu_icon_par'),
      li = ul.parent('li');

      if( $action == 'open' ) {
        ul.slideDown(300);
        icon.removeClass( wprmenu.submenu_open_icon ).addClass( wprmenu.submenu_close_icon );
      }
      else {
        if(ul.is(':visible')) ul.slideUp(300);
        icon.removeClass( wprmenu.submenu_close_icon ).addClass( wprmenu.submenu_open_icon );
        li.removeClass('wprmenu_no_border_bottom');
      }
      
    });
  }

});
// source --> https://www.thegodjourney.com/wp-content/themes/palo-alto/js/jquery.tjg.js?ver=1 
// This script is for IE and Opera only
// Basically, this applies the 'sfhover'
// class to li elements in the 'nav' id'd
// ul element when they are 'moused over'
// and removes it, using a regular expression,
// when 'moused out'.
// See http://www.htmldog.com/articles/suckerfish/dropdowns/

sfHover = function() {
  var sfEls = document.getElementById("menu-main-menu").getElementsByTagName("LI");
  for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function() {
      this.className+=" sfhover";
    }
    sfEls[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
  }
}

if (window.attachEvent) window.attachEvent("onload", sfHover);


// as the page loads, call these scripts
jQuery(document).ready( function($) {
  $('.header-image-quote li:odd').addClass('left');
  $('.header-image-quote li:even').addClass('right');

  $('.header-image-quote ul').hide().delay(3000).fadeIn().cycle({delay:3000, timeout:7000});


  var menuWidth = $('.menu-main-menu-container').width();
  $('#menu-main-menu .sub-menu').each(function(){
    var subMenuWidth = $(this).outerWidth();
    var parentPos = $(this).parent().position();
    if (menuWidth < (subMenuWidth + parentPos.left + 20)) { // 20 for fudge factor
      var a = (menuWidth - subMenuWidth)/2;
      $(this).parent().hover(function() {
          $(this).find('.sub-menu').css({
            'left': a
          })
        },
         function(){
           $(this).find('.sub-menu').css({
            'left': '-999em'
          })
      });
    }
  });
});
// source --> https://www.thegodjourney.com/wp-content/themes/palo-alto/js/jquery.cycle.lite.js?ver=1 
/*!
 * jQuery Cycle Lite Plugin
 * http://malsup.com/jquery/cycle/lite/
 * Copyright (c) 2008-2012 M. Alsup
 * Version: 1.7 (20-FEB-2013)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires: jQuery v1.3.2 or later
 */
;(function($) {
"use strict";

var ver = 'Lite-1.7';
var msie = /MSIE/.test(navigator.userAgent);

$.fn.cycle = function(options) {
    return this.each(function() {
        options = options || {};
        
        if (this.cycleTimeout) 
            clearTimeout(this.cycleTimeout);

        this.cycleTimeout = 0;
        this.cyclePause = 0;
        
        var $cont = $(this);
        var $slides = options.slideExpr ? $(options.slideExpr, this) : $cont.children();
        var els = $slides.get();
        if (els.length < 2) {
            if (window.console)
                console.log('terminating; too few slides: ' + els.length);
            return; // don't bother
        }

        // support metadata plugin (v1.0 and v2.0)
        var opts = $.extend({}, $.fn.cycle.defaults, options || {}, $.metadata ? $cont.metadata() : $.meta ? $cont.data() : {});
        var meta = $.isFunction($cont.data) ? $cont.data(opts.metaAttr) : null;
        if (meta)
            opts = $.extend(opts, meta);
            
        opts.before = opts.before ? [opts.before] : [];
        opts.after = opts.after ? [opts.after] : [];
        opts.after.unshift(function(){ opts.busy=0; });
            
        // allow shorthand overrides of width, height and timeout
        var cls = this.className;
        opts.width = parseInt((cls.match(/w:(\d+)/)||[])[1], 10) || opts.width;
        opts.height = parseInt((cls.match(/h:(\d+)/)||[])[1], 10) || opts.height;
        opts.timeout = parseInt((cls.match(/t:(\d+)/)||[])[1], 10) || opts.timeout;

        if ($cont.css('position') == 'static') 
            $cont.css('position', 'relative');
        if (opts.width) 
            $cont.width(opts.width);
        if (opts.height && opts.height != 'auto') 
            $cont.height(opts.height);

        var first = 0;
        $slides.css({position: 'absolute', top:0}).each(function(i) {
            $(this).css('z-index', els.length-i);
        });
        
        $(els[first]).css('opacity',1).show(); // opacity bit needed to handle reinit case
        if (msie) 
            els[first].style.removeAttribute('filter');

        if (opts.fit && opts.width) 
            $slides.width(opts.width);
        if (opts.fit && opts.height && opts.height != 'auto') 
            $slides.height(opts.height);
        if (opts.pause) 
            $cont.hover(function(){this.cyclePause=1;}, function(){this.cyclePause=0;});

        var txFn = $.fn.cycle.transitions[opts.fx];
        if (txFn)
            txFn($cont, $slides, opts);
        
        $slides.each(function() {
            var $el = $(this);
            this.cycleH = (opts.fit && opts.height) ? opts.height : $el.height();
            this.cycleW = (opts.fit && opts.width) ? opts.width : $el.width();
        });

        if (opts.cssFirst)
            $($slides[first]).css(opts.cssFirst);

        if (opts.timeout) {
            // ensure that timeout and speed settings are sane
            if (opts.speed.constructor == String)
                opts.speed = {slow: 600, fast: 200}[opts.speed] || 400;
            if (!opts.sync)
                opts.speed = opts.speed / 2;
            while((opts.timeout - opts.speed) < 250)
                opts.timeout += opts.speed;
        }
        opts.speedIn = opts.speed;
        opts.speedOut = opts.speed;

        opts.slideCount = els.length;
        opts.currSlide = first;
        opts.nextSlide = 1;

        // fire artificial events
        var e0 = $slides[first];
        if (opts.before.length)
            opts.before[0].apply(e0, [e0, e0, opts, true]);
        if (opts.after.length > 1)
            opts.after[1].apply(e0, [e0, e0, opts, true]);
        
        if (opts.click && !opts.next)
            opts.next = opts.click;
        if (opts.next)
            $(opts.next).unbind('click.cycle').bind('click.cycle', function(){return advance(els,opts,opts.rev?-1:1);});
        if (opts.prev)
            $(opts.prev).unbind('click.cycle').bind('click.cycle', function(){return advance(els,opts,opts.rev?1:-1);});

        if (opts.timeout)
            this.cycleTimeout = setTimeout(function() {
                go(els,opts,0,!opts.rev);
            }, opts.timeout + (opts.delay||0));
    });
};

function go(els, opts, manual, fwd) {
    if (opts.busy) 
        return;
    var p = els[0].parentNode, curr = els[opts.currSlide], next = els[opts.nextSlide];
    if (p.cycleTimeout === 0 && !manual) 
        return;

    if (manual || !p.cyclePause) {
        if (opts.before.length)
            $.each(opts.before, function(i,o) { o.apply(next, [curr, next, opts, fwd]); });
        var after = function() {
            if (msie)
                this.style.removeAttribute('filter');
            $.each(opts.after, function(i,o) { o.apply(next, [curr, next, opts, fwd]); });
            queueNext(opts);
        };

        if (opts.nextSlide != opts.currSlide) {
            opts.busy = 1;
            $.fn.cycle.custom(curr, next, opts, after);
        }
        var roll = (opts.nextSlide + 1) == els.length;
        opts.nextSlide = roll ? 0 : opts.nextSlide+1;
        opts.currSlide = roll ? els.length-1 : opts.nextSlide-1;
    } else {
      queueNext(opts);
    }

    function queueNext(opts) {
        if (opts.timeout)
            p.cycleTimeout = setTimeout(function() { go(els,opts,0,!opts.rev); }, opts.timeout);
    }
}

// advance slide forward or back
function advance(els, opts, val) {
    var p = els[0].parentNode, timeout = p.cycleTimeout;
    if (timeout) {
        clearTimeout(timeout);
        p.cycleTimeout = 0;
    }
    opts.nextSlide = opts.currSlide + val;
    if (opts.nextSlide < 0) {
        opts.nextSlide = els.length - 1;
    }
    else if (opts.nextSlide >= els.length) {
        opts.nextSlide = 0;
    }
    go(els, opts, 1, val>=0);
    return false;
}

$.fn.cycle.custom = function(curr, next, opts, cb) {
    var $l = $(curr), $n = $(next);
    $n.css(opts.cssBefore);
    var fn = function() {$n.animate(opts.animIn, opts.speedIn, opts.easeIn, cb);};
    $l.animate(opts.animOut, opts.speedOut, opts.easeOut, function() {
        $l.css(opts.cssAfter);
        if (!opts.sync)
            fn();
    });
    if (opts.sync)
        fn();
};

$.fn.cycle.transitions = {
    fade: function($cont, $slides, opts) {
        $slides.not(':eq(0)').hide();
        opts.cssBefore = { opacity: 0, display: 'block' };
        opts.cssAfter  = { display: 'none' };
        opts.animOut = { opacity: 0 };
        opts.animIn = { opacity: 1 };
    },
    fadeout: function($cont, $slides, opts) {
        opts.before.push(function(curr,next,opts,fwd) {
            $(curr).css('zIndex',opts.slideCount + (fwd === true ? 1 : 0));
            $(next).css('zIndex',opts.slideCount + (fwd === true ? 0 : 1));
        });
        $slides.not(':eq(0)').hide();
        opts.cssBefore = { opacity: 1, display: 'block', zIndex: 1 };
        opts.cssAfter  = { display: 'none', zIndex: 0 };
        opts.animOut = { opacity: 0 };
        opts.animIn = { opacity: 1 };
    }
};

$.fn.cycle.ver = function() { return ver; };

// @see: http://malsup.com/jquery/cycle/lite/
$.fn.cycle.defaults = {
    animIn:        {},
    animOut:       {},
    fx:           'fade',
    after:         null,
    before:        null,
    cssBefore:     {},
    cssAfter:      {},
    delay:         0,
    fit:           0,
    height:       'auto',
    metaAttr:     'cycle',
    next:          null,
    pause:         false,
    prev:          null,
    speed:         1000,
    slideExpr:     null,
    sync:          true,
    timeout:       4000
};

})(jQuery);