﻿if (typeof(ARL) == "undefined"){ ARL={}; }

ARL.VerticalScroller={
	scrollArea:"scrollarea",
	scrollbarTrack:"scrollbartrack",
	scrollbarHandle:"scrollbarhandle",
	verticalSlider:null,

	init:function(setupArgs) {
		if ($(this.scrollArea) == null) {
			return;
		}

		if(typeof(setupArgs.scrollArea) != 'undefined') this.scrollArea = setupArgs.scrollArea;
		if(typeof(setupArgs.scrollbarTrack) != 'undefined') this.scrollbarTrack = setupArgs.scrollbarTrack;
		if(typeof(setupArgs.scrollbarHandle) != 'undefined') this.scrollbarHandle = setupArgs.scrollbarHandle;

		this.verticalSlider = new Control.Slider(this.scrollbarHandle, this.scrollbarTrack, {
			axis: 'vertical'
		});
		
		$(this.scrollArea).setStyle({
			width: "280px",
			paddingRight: "0px",
			overflow: "hidden"
		});

		// Disable vertical scrolling if text doesn't overflow the div
		if ($(this.scrollArea).scrollHeight <= $(this.scrollArea).offsetHeight) {
			this.verticalSlider.setDisabled();
			$(this.scrollbarTrack).hide();
		} else {
			$(this.scrollbarTrack).style.visibility = "visible";
		}

		this.verticalSlider.options.onChange = function(value) {
			ARL.VerticalScroller.scrollVertical(value);
		};

		this.verticalSlider.options.onSlide = function(value) {
			ARL.VerticalScroller.scrollVertical(value);
		};
	},

	scrollVertical:function(toY) {
		element = $(this.scrollArea);

		element.scrollTop = Math.round(toY/ARL.VerticalScroller.verticalSlider.maximum*(element.scrollHeight-element.offsetHeight));
	}
};