$('document').ready(function() {
	var tt = $('#text-scroll-bar').next('div').children().eq(0);
	var tw = $('#text-scroll-bar').parent();
    if (tt.outerHeight() > tw.outerHeight()) {
        var height_diff = tw.outerHeight() / tt.outerHeight() * tw.outerHeight();
        $('#text-scroll-handle').css('height', height_diff+'px');
	}
    $('#text-scroll-handle').draggable({
        axis: 'y',
        containment: 'parent',
        drag: function(event, ui) {
            var top = $(this).position().top;
            var height = $('#text-scroll-bar').outerHeight();
            var window_height = $('#text-scroll-bar').next('div').children().eq(0).outerHeight();
            var offset = top / height * window_height;
            $('#text-scroll-bar').next('div').children().eq(0).css('top', '-'+offset+'px');
        }
    });
});

