﻿
function ScrollBar() {
	if (($("#text").height() - $("#textbox").height()) > 0)
	{
		$("#textbox").css("overflow", "hidden");
        $("#sliderbox").css("display", "block");
        
        // 20 sliderbox width + margin-left
		$("#textbox").css("width", ($("#textbox").width() - 20) + "px");
		$("#textbox").css("float", "left");
	
		var sliderHeight = ($("#textbox").height() * $("#sliderbox").height()) / $("#text").height();
		$("#slider").height(sliderHeight);
	
    	$("#slider").draggable({
			containment: "parent",
			drag: function(e, ui){
            	var textTop = (($("#text").height() - $("#textbox").height()) * ui.position.top) / ($("#sliderbox").height() - sliderHeight );
                $("#text").css("top", textTop * -1 + "px");
          	}
		});
	}
}
