var scrollbarClass = new Class({

		Implements: [Options],

		options: {
			maxThumbSize: 54,
			wheel: 27
		},

		initialize: function(content, options){
			this.setOptions(options);
			
			this.content = $(content);
			var oParent = $(content).getParent();
			this.oScrollbar = oParent.getElement('.scrollbar');
			this.oTrack = this.oScrollbar.getElement('.track');
			this.oThumb = this.oTrack.getElement('.thumb');
			
			this.oBound = {
				'start': this.start.bind(this),				
				'end': this.end.bind(this),
				'drag': this.drag.bind(this),				
				'wheel': this.wheel.bind(this),
				'page': this.page.bind(this)		
			};

			this.vPosition = {};		
			this.vMouse = {};			
			this.update();
			this.attach();
		},

		update: function(){
			
			//Get the size of the content and the of the scroll space and calulate how many times the content goes in to the content scrollsize
			this.vContentSize = this.content.offsetHeight;
			this.vContentScrollSize = this.content.scrollHeight;
			this.vContentRatio = this.vContentSize / this.vContentScrollSize;

			//When the scroll size is smaller or equal to the content dont display scrollbar.
			this.oTrack.setStyle('height', this.vContentSize);
			if ( this.vContentScrollSize <= this.vContentSize ) {
				this.oScrollbar.setStyle('display', 'none');
			} else {
				this.oScrollbar.setStyle('display', 'block');			
			}
			
			//Get track height
			this.oTrackSize = this.oTrack.offsetHeight - 19;	

			//Calculate the thumbsize by multiplying the track height with the content ratio and limiting it by the minmum thumb size and the tracksize.
			this.oThumbSize = (this.oTrackSize * this.vContentRatio).limit(this.options.maxThumbSize, this.oTrackSize);
			this.oThumb.setStyle('height', this.oThumbSize);
			
			this.vScrollRatio = this.vContentScrollSize / this.oTrackSize;
			
			this.UpdateContentFromThumbPosition();
			this.UpdateThumbFromContentScroll();

		},

		UpdateContentFromThumbPosition: function(){
			//update the place of content = the place of the thumb 
			this.content.scrollTop = this.vPosition.now * this.vScrollRatio;
		},	

		UpdateThumbFromContentScroll: function(){
			//position the content is from the top divided trew the scrollratio limited by zero and the space that is left.
			this.vPosition.now = (this.content.scrollTop / this.vScrollRatio).limit(0, (this.oTrackSize - this.oThumbSize));
			// set the position of the thumb
			this.oThumb.setStyle('top', this.vPosition.now);
		},
			
		attach: function(){
			//When the user clicks the left mouse or scrolls go to functions.
			this.oThumb.addEvent('mousedown', this.oBound.start);
			if (this.options.wheel) this.content.addEvent('mousewheel', this.oBound.wheel);
			this.oTrack.addEvent('mouseup', this.oBound.page);		
		},
		
		wheel: function(oEvent){
			oEvent.stop();
			
			//the distance from the top edge of content = the distance from the top edge of content - (wheel direction * wheel pixels on move )
			this.content.scrollTop -= oEvent.wheel * this.options.wheel;
			this.UpdateThumbFromContentScroll();
		},

		page: function(oEvent){
			
			if (oEvent.page.y > this.oThumb.getPosition().y) this.content.scrollTop += this.content.offsetHeight;
			else this.content.scrollTop -= this.content.offsetHeight;
			this.UpdateThumbFromContentScroll();
		},

		start: function(oEvent){
			oEvent.stop();
			
			this.vMouse.start = oEvent.page.y;
			
			//were is the thumb in relation to the track
			this.vPosition.start = this.oThumb.getStyle('top').toInt();
			
			document.addEvent('mousemove', this.oBound.drag);
			document.addEvent('mouseup', this.oBound.end);
			this.oThumb.addEvent('mouseup', this.oBound.end);
		},	

		end: function(oEvent){
			oEvent.stop();
			
			//when mouse button is lifted remove the drag function from the knop.
			document.removeEvent('mousemove', this.oBound.drag);			
			document.removeEvent('mouseup', this.oBound.end);
			this.oThumb.removeEvent('mouseup', this.oBound.end);	
		},

		drag: function(oEvent){
			oEvent.stop();
			
			this.vMouse.now = oEvent.page.y;
			this.vPosition.now = (this.vPosition.start + (this.vMouse.now - this.vMouse.start)).limit(0, (this.oTrackSize - this.oThumbSize));
			this.UpdateContentFromThumbPosition();
			this.UpdateThumbFromContentScroll();
		}
	});