Control.Scroller = Class.create();
Control.Scroller.prototype = {
	initialize: function(list, handle, track, options) {
		var scroller = this;
		//this.id = "scroller"
		this.list = $(list);
		this.options = options;
		this.handle = $(handle);
		this.track = $(track);
		i=1;
		this.count = Math.floor(this.list.getHeight() / 20);
		this.cuValue = 0;
		this.list.childElements().each(function(n){
			if ($(n).hasClassName('current')) {
				scroller.cuValue = i;
			}
			i++;
		});
		if (this.cuValue!=0) {
			max = scroller.count - scroller.options.visibleCount;
			pol = Math.floor(scroller.options.visibleCount / 2) - 1;
			this.cuValue -= pol;
			if (this.cuValue<0) this.cuValue=0;
			if (this.cuValue>max) this.cuValue=max;
		}
		
		//document.title+=parseInt(this.list.getHeight()) / 20 + ';';

		
		
		if (this.count - this.options.visibleCount <= 0) {
			
			this.handle.hide();
			this.track.hide();
		} else {
			this.slider = new Control.Slider(this.handle, this.track, {
				axis: 'vertical',
				values: $R(0,this.count - this.options.visibleCount),
				range: $R(0,this.count - this.options.visibleCount),
				onSlide: function(value) {
					hH=parseInt(scroller.list.getStyle('marginTop'));
					/*scroller.list.childElements().each(function(n,i){
						if (i<value) hH+=parseInt($(n).getHeight());
					});*/
					
					//alert(scroller.list);
					scroller.list.setStyle({
						marginTop:(-20*value)+'px'
					});
					
					
				}
			});
			scroller.changeTrueValue(this.cuValue);
		}
	},
	
	changeValue: function(delta) {
		//alert(this.slider.value - delta);
		if (this.slider) {
			newW = this.slider.value - delta;
			this.slider.setValue(newW);
			this.list.setStyle({
				marginTop:(-20*this.slider.value)+'px'
			});
		}
	},
	
	changeTrueValue: function(delta) {
		//alert(this.slider.value - delta);
		if (this.slider) {
			newW = delta;
			this.slider.setValue(newW);
			this.list.setStyle({
				marginTop:(-20*this.slider.value)+'px'
			});
		}
	},

	scroll: function() {


	},
	updateView: function(value) {

	}
}
