(function($){
		
		"use strict"; 
		 $('.parallax').each(function() {
			var $parallaxSection = $(this);
			var parallaxFunc = function(){
				if ($(window).width() >= 768) {
					var offset = $parallaxSection.offset().top;
					var scrollTop = $(window).scrollTop();
					var yPos = -(offset - scrollTop)/2;
					var coords = 'center '+ yPos + 'px';
					$parallaxSection.css( { backgroundPosition: coords});
				} else {
					$parallaxSection.css( {
						backgroundPosition: 'center',
					});
				}
			};
			parallaxFunc(); 
			$(window).on('scroll', function (){
				parallaxFunc();
			});
		});
		
		if( $('#fullpage').length > 0){
			var fr_section = $('.post-content div.fr_section');
			var fr_total_section = fr_section.length;
			var lightlogo = $('#logo').attr('data-lightlogo');
			var darklogo = $('#logo').attr('data-darklogo');
			$('.post-content').css('height','calc(100vh*'+fr_total_section+')');
			
			$('#fullpage').fullpage({
				anchors: ['firstPage', 'secondPage', '3rdPage', '4thpage', '5thpage'],
				sectionsColor: ['#C63D0F', '#1BBC9B', '#7E8F7C'],
				navigation: true,
				navigationPosition: 'right',
				scrollOverflow: true,
				afterLoad: function(anchor, index){
				   if($('.fp-section.active').hasClass('dark')) {
					  $('body').addClass('light_header_colorFont');					 
					  $('#logo').attr('src', lightlogo );
				   }else{
						$('body').addClass('dark_header_colorFont');
						$('#logo').attr('src', darklogo );
					}
				},
				onLeave: function(anchor, index){
				   if($('.fp-section.active').hasClass('dark')) {
						$('body').removeClass('dark_header_colorFont');
						$('body').addClass('light_header_colorFont');
						$('#logo').attr('src', lightlogo );						
				   }else{
						$('body').addClass('dark_header_colorFont');
						$('body').removeClass('light_header_colorFont');
						 $('#logo').attr('src', darklogo );
				   }
				}
			});				 
		}
		
		if( $('.rotate').length > 0){
		var bodyHeight = $("body").height()-$(window).height();
		$(window).on('scroll', function() {
			 var deg = -$(window).scrollTop()*(360/bodyHeight);
			$(".rotate img").css({
				 "transform": "rotate("+deg+"deg)",
			});
		});
		}
		
		$(window).on('scroll', function() {
			var scroll_position = $(document).scrollTop();
			if(scroll_position > 500) {
				$(".home #menu_container").addClass("small_header");
				if($('#header-outer').length > 0){
					$('#header-outer').addClass("dark_header_colorFont");
				}
			} else {
				$(".home #menu_container").removeClass("small_header");
				if($('#header-outer').length > 0){
					$('#header-outer').removeClass("dark_header_colorFont");
				}
			}
		});
		
		var isMobile = {
			Android: function() {
				return navigator.userAgent.match(/Android/i);
			},
			BlackBerry: function() {
				return navigator.userAgent.match(/BlackBerry/i);
			},
			iOS: function() {
				return navigator.userAgent.match(/iPhone|iPad|iPod/i);
			},
			Opera: function() {
				return navigator.userAgent.match(/Opera Mini/i);
			},
			Windows: function() {
				return navigator.userAgent.match(/IEMobile/i);
			},
			any: function() {
				return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
			}
		};
		
		
		$(window).on('load', function() {
			setTimeout(function() {
			  $('.loader').fadeOut('slow', function() {});
			}, 400);
		});

		var menu_flip_speed = 200,
		recent_work_opacity_speed = 400,
		featured_controllers_opacity_speed = 500,
		featured_bar_animation_speed = 500,
		featured_bar_animation_easing = 'easeOutExpo',
		$mobile_nav_button = $('#mobile_nav'),
		$main_menu = $('.menu_wrap ul.nav').add('#mobile_menu').add('.fr_left_menu ul.nav').add('.menu_wrap ul.menu'),
		$featured = $('#fr_showcase_slider'),
		$featured_controllers_container = $('#featured-controllers'),
		$featured_control_item = $featured_controllers_container.find('li'),
		container_width = $('#container').innerWidth(),
		$footer_widget = $('.footer-widget'),
		$cloned_nav,
		slider_settings,
		sd_slider_autospeed,
		slider,
		$recent_work_thumb = $('#recent-work .thumb'),
		$gallery_slider = $('.post_gallery_slider');		
		
		$main_menu.superfish({ 
			delay:       300,                            // one second delay on mouseout 
			animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
			speed:       'fast',                          // faster animation speed 
			autoArrows:  true,                           // disable generation of arrow mark-up 
			dropShadows: false                            // disable drop shadows 
		});
		
		
	
		//MOBILE MENU
		
		$cloned_nav = $mobile_nav_button.find('#mobile_menu');
		
		$mobile_nav_button.on('click', function(){
			if ( $(this).hasClass('closed') ){
				$(this).removeClass( 'closed' ).addClass( 'opened' );
				$('#mobile_menu').slideDown( 500 );
			} else {				
				$(this).removeClass( 'opened' ).addClass( 'closed' );
				$('#mobile_menu').slideUp( 500 );
			}
			return false;	
		} );
	
   
	   $('#mobile_menu').find('.menu-item-has-children').each( function(){						
			$(this).append( '<span class="mobile_toogle"></span>' );							
		});
		
		$(".mobile_toogle").on('click', function(event){
			if($(this).hasClass('mobile_toogle_open')){
				$(this).removeClass('mobile_toogle_open')
			}else{
				$(this).addClass('mobile_toogle_open');
			}
			
			if(false == $(this).siblings().is(':visible')) {
				$('.sub-menu').slideUp(280);			
			}
			$(this).prev().slideToggle(280); 		
			event.stopPropagation();		
		});
	
	
		$mobile_nav_button.find('a').on('click', function(event){
			event.stopPropagation();
		} );
		
		//MOBILE MENU
	
		$.fn.clickToggle = function(func1, func2) {
        var funcs = [func1, func2];
        this.data('toggleclicked', 0);
        this.on('click', function() {
            var data = $(this).data();
            var tc = data.toggleclicked;
            $.proxy(funcs[tc], this)();
            data.toggleclicked = (tc + 1) % 2;
            return false;
        });
        return this;
		};
	
		if( $('.fr_left_menu').length > 0){
			$( "#menu-switch" ).clickToggle(function() {
				$('#menu').animate({right: 0}, 'normal');
			}, function() {
				$('#menu.fr_left_menu').animate({right: -500}, 'normal');
			});
			
			const menu = document.getElementById("menu_icon");
			menu.addEventListener("click", morph);

			function morph() {
			  menu.classList.toggle("open");
			}
		}
		
		// ONE-PAGE MENU SETTINGS
		if( $('.frgn_onepage').length > 0){
		   $("#main-menu").find("a").on('click',function(){
				var elem = $(this).attr("href");
				$('html, body').animate({ scrollTop: $(elem).offset().top - 110 }, 1000);
		   });
		}
		// ONE-PAGE MENU SETTINGS
			
		if( $('.portfolio_metro').length > 0){
			$('.portfolio_metro .featured_box').each(function(i){
				$(this).css('backgroundImage', 'url('+$(this).find('img').attr('src')+')');
				$(this).find('img').remove();
			});
		}
		
		if( $('.portfolio_ajax').length > 0){
			$('.least-gallery').least();
		}
		
		if( $(window).width() > 1024){
			if( $('.fr_frgn_parallax_block').add('.fr_frgn_parallax').length > 0){
				(function() {
				skrollr.init({
				forceHeight: true,
				smoothScrolling: false
			  });
			}).call(this);
			}
		}
		
		if($(window).width() > 600){
			$(window).load(function(){
			if( $('.portfolio_metro').length > 0){
				jQuery(window).load(function(){
					 $('.portfolio_metro').isotope({
					 masonry: {
						columnWidth: $(this).find('article').width(),
						gutter: 5,
					 },
					 itemSelector:'.entry',
					 percentPosition: true,
					 });
				});
			}
			});
			
			$(function() {
				if($(".sticky-sidebar").length > 0){
				var $sidebar   = $(".sticky-sidebar"), 
					$window    = $(window),
					$footer    = $("#footer"), // use your footer ID here
					offset     = $sidebar.offset(),
					foffset    = $footer.offset(),
					threshold = foffset.top - $sidebar.height() - 20,
					topPadding = 15;

				$window.scroll(function() {
					if ($window.scrollTop() > threshold) {
						$sidebar.stop().animate({
							marginTop: threshold
						});
					} else if ($window.scrollTop() > offset.top) {
						$sidebar.stop().animate({
							marginTop: $window.scrollTop() - offset.top
						});
					} else {
						$sidebar.stop().animate({
							marginTop: 0
						});
					}
				});
				}
			});
		}
		
		if( $('.post_gallery_slider').length > 0){
			$('.post_gallery_slider:visible').find('li>a').attr('data-lightbox','lightbox');
		}
	
	
	$(window).scroll(function() {
		var scroll_position = $(document).scrollTop();
		if($(window).width() < 600 ){
			if(scroll_position > 46 ) {
				$(".mobile_menu_wrap").addClass("mobile_header_top");
				$("#mobile_menu").addClass("mobile_menu_top");
			} else {
				$(".mobile_menu_wrap").removeClass("mobile_header_top");
				$("#mobile_menu").removeClass("mobile_menu_top");
			}
		}
	});	
	
	$('#fr_to_top').on('click', function(){
       $('html, body').animate({scrollTop:0}, 'slow');
   });
   
   $('.offscreen-content-toggle').on('click', function(){
       $('.aside').animate({left:0}, 'slow');
	   $('.aside_overlay').fadeIn('fast');
	   $('body').css('overflowY','hidden');
   });
   $('.aside_overlay').add('.aside_close').on('click', function(){
       $('.aside').animate({left:-320}, 'slow');
	    $('.aside_overlay').fadeOut('fast');
	   $('body').css('overflowY','scroll');
   });
   
   if( $('.team_member').add('.team_member_img').length > 0){
		$('.team_info').find('a').each(function(){
			if($(this).attr('href') == ''){
				 $(this).hide();
			}else{
				$(this).show();
			}
		});
	}
	
	// init Isotope
	if( $('.masonry_layout').length > 0){
		jQuery(window).on('load',function(){
			var $grid = $('.masonry_layout').isotope({
				layoutMode: 'masonry',
				masonry: {
					columnWidth: $(this).find('.entry').width(),
					gutter: 40,
				},
				itemSelector: '.entry', 
				percentPosition: true,	
				fitWidth: true			
			});		
			
			// init Infinite Scroll
			if($('.loadmore').length > 0){
			
				// get Isotope instance
				var iso = $grid.data('isotope');
			
				$grid.infiniteScroll({
					path: '#pagination a',
					append: '.masonry_layout .entry',
					loadOnScroll: false,
					button: '.loadmore',
					scrollThreshold: false,
					status: '.page-load-status',
					history: false,
					outlayer: iso,  
				});
				
				var $viewMoreButton = $('.loadmore');		
				$viewMoreButton.on( 'click', function() {		 
				  $grid.infiniteScroll('loadNextPage');			  
				  $grid.infiniteScroll( 'option', {
					loadOnScroll: true,
				  });
				})
			}			
		});
	}   
         
})(jQuery);