jQuery(document).ready(function(){
     

	$window = jQuery(window);
        
        jQuery('[data-type="move"]').each(function() {
            var $sprite = jQuery(this);
            var offset = $sprite.offset();
            
            $sprite.css({ top: ($window.scrollTop() / $sprite.data('speed')) + offset.top });
            jQuery(window).scroll(function() {
                $sprite.css({ top: ($window.scrollTop() / $sprite.data('speed')) + offset.top });	
            });
        });
        
        jQuery('[data-type="background"]').each(function() {
            var $sprite = jQuery(this);
            
            $sprite.css({backgroundPosition: $window.scrollTop() / $sprite.data('speed')});
        });

	jQuery('*[data-type="background"]').each(function(){
		if($window.width() <= 1024) {
			return;
		}
		var $self = jQuery(this),
			offsetCoords = $self.offset(),
			topOffset = offsetCoords.top;
		
		
		if ( ($window.scrollTop() + $window.height()) > (topOffset) && ( (topOffset + $self.height()) > $window.scrollTop() ) ) {
			var yPos = -($window.scrollTop() / $self.data('speed')); 
			if ($self.data('offsetY')) {
				yPos += $self.data('offsetY');
			}
			var coords = '50% '+ yPos + 'px';
			$self.css({ backgroundPosition: coords });	

			jQuery('[data-type="move"]', $self).each(function() {
				var $sprite = jQuery(this);
				var yPos = ($window.scrollTop() / $sprite.data('speed')) + topOffset.top;
				$sprite.css({ top: yPos });													
	
			});
		}
		
		jQuery(window).scroll(function() {
			if ( ($window.scrollTop() + $window.height()) > (topOffset) && ( (topOffset + $self.height()) > $window.scrollTop() ) ) {
				var yPos = -($window.scrollTop() / $self.data('speed')); 
				if ($self.data('offsetY')) {
					yPos += $self.data('offsetY');
				}
				var coords = '50% '+ yPos + 'px';
				$self.css({ backgroundPosition: coords });	
                                
				jQuery('[data-type="move"]', $self).each(function() {
                                    var $sprite = jQuery(this);
                                    var yPos = ($window.scrollTop() / $sprite.data('speed')) + topOffset.top;
                                    $sprite.css({ top: yPos });													
				});
			}
		});
	});
	
	
	
	
	


});


