<?php
/*
Plugin Name: Twenty Fifteen Scroll
*/

function tf_script() {
	?>
	<script type="text/javascript">
	jQuery( document ).ready( function ( $ ) {
		$( '#sidebar' ).css( 'overflow', 'hidden' );
		
		var sidebar_scrollheight = $( '#sidebar' )[0].scrollHeight;
		var content_scrollheight = $( '#content' )[0].scrollHeight;
		var ratio = sidebar_scrollheight / content_scrollheight;
		var window_height = $( window ).height();
		var offset = content_scrollheight - window_height;
		var multiplier = content_scrollheight / offset;
		
		$( window ).scroll( function() {
			var content_position = $( window ).scrollTop();
			var sidebar_position = Math.round( content_position * ratio * multiplier );
			$( '#sidebar' ).scrollTop( Math.abs( sidebar_position ) );
		} );
	} );
	</script>
	<?php
}
add_action( 'wp_head', 'tf_script' );


function tf_add_jquery() {
	wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'tf_add_jquery' );
