jQuery(document).ready(function($){

	// ON SCROLL
	$(window).scroll(function(){

		var $wScroll = $(this).scrollTop();

		// Periscope
		var $periscope_el = $('.nperiscope');
		if ( $periscope_el.length ) {
			$periscope_el.each(function () {
				var $periscope_el_tint = $(this).find('.nperiscope-tint');
				if($wScroll > $(this).offset().top - $(window).height()){
					$(this).css({'background-position-y': ($wScroll - $(this).offset().top) +'px'});
					var opacity = ($wScroll - $(this).offset().top + 400) / ($wScroll / 5);
					$periscope_el_tint.css({'opacity': opacity});
				}
			});
		 }

		// Floating Elements
		var $floating_el = $('.nfloating-box-list');
		if ( $floating_el.length ) {
			$floating_el.each(function () {
				if($wScroll > $(this).offset().top - $(window).height()){
					var offset = (Math.min(0, $wScroll - $(this).offset().top +$(window).height() - 350)).toFixed();
					$(this).find(".nbox:nth-child(1)").css({'transform': 'translate('+ offset +'px, '+ Math.abs(offset * 0.2) +'px)'});
					$(this).find(".nbox:nth-child(3)").css({'transform': 'translate('+ Math.abs(offset) +'px, '+ Math.abs(offset * 0.2) +'px)'});
				}
			});
		}

		// Landing Elements
		var $landing_el = $('.nlanding-box-list');
		if ( $landing_el.length ) {
			$landing_el.each(function () {
				var $this = $(this);
				if($wScroll > $this.offset().top - ($(window).height() / 1.2)) {
					$this.find(">.nbox").each(function(i){
						setTimeout(function(){
							$this.find(">.nbox").eq(i).addClass('is-showing');
						}, (700 * (Math.exp(i * 0.14))) - 700);
					});
				}
			});
		}

	});

}); 
