
$(document).ready(function() { 

	var $window = $(window);
	var $firstBG = $('#home');
	var trainers5 = $("#home #logo");
	var trainers6 = $("#home #catch");
	var trainers7 = $("#home #catch2");
	
	var windowHeight = $window.height();
	
	$('#home, #second, #third, #fourth').bind('inview', function (event, visible) {
			if (visible == true) {
			$(this).addClass("inview");
			} else {
			$(this).removeClass("inview");
			}
		});
	
	function RepositionNav(){
		var windowHeight = $window.height(); 
		var navHeight = $('#nav').height() / 2;
		var windowCenter = (windowHeight / 2); 
		var newtop = windowCenter - navHeight;
		$('#nav').css({"top": newtop}); 
	}
	
	function newPos(x, windowHeight, pos, adjuster, inertia){
		return x + "% " + (-((windowHeight + pos) - adjuster) * inertia)  + "px";
	}
	
	function Move(){ 
		var pos = $window.scrollTop(); 

		if($firstBG.hasClass("inview")){
			$firstBG.css({'backgroundPosition': newPos(0, windowHeight, pos, 00, 0.9)}); 
			trainers5.css({'backgroundPosition': newPos(0, windowHeight, pos, 970, 0.6)});
			trainers6.css({'backgroundPosition': newPos(80, windowHeight, pos, 1220, 0.99)});
			trainers7.css({'backgroundPosition': newPos(95, windowHeight, pos, 1780, 0.99)});
		}
		
		
		$('#pixels').html(pos); 
	}
		
	RepositionNav(); 
	
	$window.resize(function(){ 
		Move(); 
		RepositionNav(); 
	});		
	
	$window.bind('scroll', function(){ 
		Move(); 
	});
	
});
