/******************
	:: Indexes
*******************
Window -> Load
:: Progress Bar
*******************
	:: Indexes
*******************/
( function($){
	"use strict"
	$( document ).ready( function($) {
		$( '.search-popup-modal' ).magnificPopup({
			type: 'inline',
			preloader: false,
			modal: true
		});
		$("#cns-nav-top").click(function () {
			$("#cns-side-nav").addClass("active");
		});
		$("#cns-nav-close").click(function () {
			   $("#cns-side-nav").removeClass("active");
		});
		$(document).on('click', '.popup-modal-dismiss', function (e) {
			e.preventDefault();
			$.magnificPopup.close();
		});
		var header_offset    = $( '.header-stickable' ).offset();
		var header_position  = header_offset.top;
		var window_width     = $( window ).width();
		if ( $( 'body' ).hasClass( 'admin-bar' ) && window_width >= 992 ) {
			$( '.site-header-container' ).addClass( 'admin-bar-enabled' );
		}
		$( window ).scroll(
			function(event) {
			var current_position = $( window ).scrollTop();
			if ( current_position > header_position ) {
				$( '.header-stickable' ).addClass( 'sigma-sticky-header' );
				var offset_px = 0;
				if( $('#wpadminbar').length > 0 && (self===top) ){
					offset_px = jQuery('#wpadminbar').height();
				}
				$('.header-stickable').css('top', offset_px + "px");
			} else {
				$('.header-stickable' ).removeClass( 'sigma-sticky-header' );
				$('.header-stickable').removeAttr('style');
			}
		});
		$('.popup-sigma a').magnificPopup({
			disableOn: 700,
			type: 'iframe',
			mainClass: 'mfp-fade',
			removalDelay: 160,
			preloader: false,
			fixedContentPos: false
		});
		$('.popup-video').magnificPopup({
			disableOn: 700,
			type: 'iframe',
			mainClass: 'mfp-fade',
			removalDelay: 160,
			preloader: false,
			fixedContentPos: false
		});
		$( '#primary-menu' ).slicknav({
			'label' : ' ',
			'closedSymbol': '+',
			'openedSymbol': '-',
			appendTo : '#site-navigation-mobile'
		});
		// Window Scroll
		$(window).on('scroll', function () {
			// Scroll to top
			var scrolled = $(window).scrollTop();
			if (scrolled > 300) $('.go-top').addClass('active');
			if (scrolled < 300) $('.go-top').removeClass('active');
		});
		$('.go-top').on('click', function () {
			$('html, body').animate(
				{
					scrollTop: '0',
				},
				1200
			);
		});
	});
})( jQuery );
