var VScroll = new Class({	
	Implements: [Events, Options],	
	options: {	
		scrollClass: 'moo-scroll',
		wheelStep: 10,
		scrollTop: 0,
		autoHide: true,
		hideOpacity: 0.4		
	},
	
	initialize: function(selector, options){
		this.setOptions(options);
		this.selector = $(selector);
		if(!this.selector) return;
		if($$('.listFaq').length){
			this.options.scrollTop = Math.round(faqScrollTop / this.options.wheelStep);
		}
		this.setup();		
	},
	
	setup: function(){		
		this.selector.setStyle('overflow', 'hidden');
		var container = new Element('div', {
			'class': this.options.scrollClass			
		}).inject(this.selector, 'after');				
		var scrollUp = new Element('div', {
			'class': 'up'
		}).inject(container);
		var scrollBar = new Element('div', {
			'class': 'bar'					
		}).inject(container);
		var scrollKnob = new Element('div', {
			'class': 'knob'			
		}).inject(scrollBar);
		var scrollDown = new Element('div', {
			'class': 'down'
		}).inject(container);		
		var selectorSize = this.selector.getSize();
		var selectorScrollSize = this.selector.getScrollSize();
		var selectorHeight = this.selector.getCoordinates().height;		
		if(selectorHeight <= 0) return;
		var scrollBarHeight = selectorHeight;
		container.set('styles', {
			'height': selectorHeight + 10
		});		
		scrollBar.set('styles', {
			'height': scrollBarHeight - 10
		});
		var scale = scrollBarHeight / selectorScrollSize.y;				
		var scrollTop = selectorScrollSize.y - selectorSize.y;
		var steps = Math.round(scrollTop / this.options.wheelStep);
		var hasScroll = (selectorScrollSize.y - this.selector.getCoordinates().height) > 0;
		scrollKnob.set('styles', {
			'display': (hasScroll) ? 'block' : 'none'			
		});		
		container.set('styles', {
			'opacity': (hasScroll) ? '1' : this.options.autoHide ? '0' : this.options.hideOpacity
		});					
		this.selector.store('slider', new Slider(scrollBar, scrollKnob, {
			onChange: function(step){
				this.selector.scrollTo(0, scrollTop * step / steps);
				this.selector.store('step', step);
		    }.bind(this),
			mode: 'vertical',
			range: [0, steps]
		}).set(Math.min(steps, this.options.scrollTop)));		
		[this.selector, container].each(function(item){
			item.removeEvents('mousewheel').addEvent('mousewheel', function(e){
				e.stop();
				this.selector.retrieve('slider').set(this.selector.retrieve('step') - e.wheel);						
			}.bind(this))
		}.bind(this));		
	}
});