function AidaScrollBar(options)
{
	var $target = I(options.target), self = this;
	
	this.scrollLeftWheel	= options.scrollLeftWheel;
	this.scrolling			= false;
	this.onScrollStart		= options.onScrollStart || Function.empty;
	this.onScrollFinish		= options.onScrollFinish || Function.empty;
	this.onScroll			= options.onScroll || Function.empty;
	this.onPage				= options.onPage || Function.empty;
	this.onPageChange		= options.onPageChange || Function.empty;
	this.onReady			= options.onReady || Function.empty;
	this.paginated			= options.paginated;
	this.elastic			= options.elastic;
	this.elasticRatio		= options.elasticRatio || 0.3;
	this.oneDirection		= options.oneDirection;
	this.pages				= null;
	this.noScrollTop		= options.noScrollTop;
	this.noScrollLeft		= options.noScrollLeft;
	this.pagePrevX			= -1;
	this.pagePrevY			= -1;
	
	if(options.fixedSizesTopHandle || options.fixedSizesHandles)
	{
		this.fixedSizesTopHandle = true;
	}
	
	if(options.fixedSizesLeftHandle || options.fixedSizesHandles)
	{
		this.fixedSizesLeftHandle = true;
	}
	
	if(options.pages)
	{
		this.pages = [];
		
		var pagesRows = options.pages.split(','),
			colsNum = 0;
		
		pagesRows.each(function(row, j)
		{
			var r = [];
			
			for(var i = 0, len = row.length; i < len; i++)
			{
				var p = row[i];
				
				r[i] = !(p == ' ' || p == '0' || p == '_');
			}
			
			self.pages[j] = r;
			
			colsNum = Math.max(colsNum, row.length)
		});
		
		this.pagesRows = this.pages.length;
		this.pagesCols = colsNum;
	}
	
	// Elemento contanitore
	var $container  = N(['div', {
		className: 'aj-scrollbar-container ' + (options.className || ''),
		tabindex: '-1',
		style: {
			position: 'relative',
			width: options.width || '',
			height: options.height || ''
		}
	}]);
	
	this.$container = $container;
	
	
	// Elemento Wrapper
	var $wrapper = N(['div', {
		className: 'aj-scrollbar-wrapper',
		style: {
			width: '100%',
			height: '100%',
			position: 'relative',
			overflow: 'hidden',
			padding: '0px',
			margin: '0px',
			border: 'none'
		}
	}], $container);
	
	this.$wrapper = $wrapper;
	
	
	var $content = N(['div', {
		className: 'aj-scrollbar-content',
		style: {
			position: 'relative',
			padding: '0px',
			margin: '0px',
			border: 'none'
		}
	}], $wrapper);
	
	this.$content = $content;
	
	
	// Muovo i contenuti e appendo gli elementi
	while($target.firstChild)
	{
		var $child = $target.firstChild;
		
		$child.parentNode.removeChild($child);
		
		$content.appendChild($child);
	}
	
	
	$target.ajAppend($container);
	this.$target = $target;
	
	// Creo lo scroller verticale
	if(!this.noScrollTop)
	{
		var $topBar = N(['div', {
			className: 'aj-scrollbar-top',
			style: {
				position: 'absolute'
			}
		}]),
		$topHandle = N(['div', {
			className: 'aj-scrollbar-top-handle',
			style: {
				position: 'absolute',
				top: '0px'
			}
		}], $topBar);
		
		this.$topBar = $topBar;
		this.$topHandle = $topHandle;
		
		$container.ajAppend($topBar);
		
		this.scrollbarTopDraggable = new AidaDraggable({
			target: $topHandle,
			onStart: function(event)
			{
				self.scrollStart();
				
				event.stop();
			},
			onMove: function(event, dX, dY)
			{
				var top = parseFloat($topHandle.ajCssGet('top'), 10), ret = [0, 0];
				
				top += dY;
				
				
				var maxTop = self.$topBar.clientHeight - self.scrollbarTopHandleHeight;
				
				if(top < 0)
				{
					ret[1] = top;
					top = 0;
				}
				else if(top > maxTop)
				{
					ret[1] = top - maxTop;
					top = maxTop;
				}
				
				self.scrollTopTo(top / maxTop);
				
				event.stop();
				
				return ret;
			},
			onFinish: function()
			{
				self.scrollFinish();
			}
		});
		
		if(options.scrollButtons || options.scrollTopButtons)
		{
			this.$topMinus = N(['div', {
				className: 'aj-scrollbar-top-minus',
				mousedowntimed: function()
				{
					self.scrollStart();
					
					var to = ($wrapper.scrollTop - 25) / ($wrapper.scrollHeight - $wrapper.clientHeight);
					
					self.scrollTopTo(to);
					
					self.scrollFinish();
				},
				unselectable: true
			}], $container);
			
			this.$topPlus = N(['div', {
				className: 'aj-scrollbar-top-plus',
				mousedowntimed: function()
				{
					self.scrollStart();
					
					var to = ($wrapper.scrollTop + 25) / ($wrapper.scrollHeight - $wrapper.clientHeight);
				
					self.scrollTopTo(to);
					
					self.scrollFinish();
				},
				unselectable: true
			}], $container);
		}
	}
	
	
	// Creo lo scroller orrizzontale	
	if (!this.noScrollLeft) 
	{
		var $leftBar = N(['div', {
			className: 'aj-scrollbar-left',
			style: {
				position: 'absolute'
			}
		}]),
		$leftHandle = N(['div', {
			className: 'aj-scrollbar-left-handle',
			style: {
				position: 'absolute',
				left: '0px'
			}
		}], $leftBar);
		
		this.$leftBar = $leftBar;
		this.$leftHandle = $leftHandle;
		
		$container.ajAppend($leftBar);
		
		this.scrollbarLeftDraggable = new AidaDraggable({
			target: $leftHandle,
			onStart: function(event)
			{
				self.scrollStart();
				
				event.stop();
			},
			onMove: function(event, dX, dY)
			{
				var left = parseFloat($leftHandle.ajCssGet('left'), 10), ret = [0, 0];
				
				left += dX;
				
				
				var maxLeft = self.$leftBar.clientWidth - self.scrollbarLeftHandleWidth;
				
				if (left < 0) 
				{
					ret[0] = left;
					left = 0;
				}
				else if (left > maxLeft) 
				{
					ret[0] = left - maxLeft;
					left = maxLeft;
				}
				
				self.scrollLeftTo(left / maxLeft);
				
				event.stop();
				
				return ret;
			},
			onFinish: function()
			{
				self.scrollFinish();
			}
		});
		
		
		if(options.scrollButtons || options.scrollLeftButtons)
		{
			this.$leftMinus = N(['div', {
				className: 'aj-scrollbar-left-minus',
				mousedowntimed: function()
				{
					self.scrollStart();
					
					var to = ($wrapper.scrollLeft - 25) / ($wrapper.scrollWidth - $wrapper.clientWidth);
					
					self.scrollLeftTo(to);
					
					self.scrollFinish();
				},
				unselectable: true
			}], $container);
			
			this.$leftPlus = N(['div', {
				className: 'aj-scrollbar-left-plus',
				mousedowntimed: function()
				{
					self.scrollStart();
					
					var to = ($wrapper.scrollLeft + 25) / ($wrapper.scrollWidth - $wrapper.clientWidth);
					
					self.scrollLeftTo(to);
					
					self.scrollFinish();
				},
				unselectable: true
			}], $container);
		}
	}
	
	if(options.draggable || AidaAgent.ios || AidaAgent.android)
	{
		var elasticDivX = this.elasticRatio,
			elasticDivY = this.elasticRatio,
			elasticLeft = 0,
			elasticTop = 0,
			direction;
			
		
		var dragMove = function(event, dX, dY, noElastic)
		{
			var left = $wrapper.scrollLeft,
				top = $wrapper.scrollTop,
				ret = [0, 0];
			
			if(self.noScrollLeft)
			{
				dX = 0;
			}
				
			if(self.noScrollTop)
			{
				dY = 0;
			}
			
			left -= dX;
			top -= dY;
			
			var maxLeft = ($wrapper.scrollWidth - $wrapper.clientWidth),
				maxTop = ($wrapper.scrollHeight - $wrapper.clientHeight);
			
			if (left < 0) 
			{
				ret[0] = -left;
				left = 0;
			}
			else if (left > maxLeft) 
			{
				ret[0] = maxLeft - left;
				left = maxLeft;
			}
			
			if(top < 0)
			{
				ret[1] = -top;
				top = 0;
			}
			else if(top > maxTop)
			{
				ret[1] = maxTop - top;
				top = maxTop;
			}
			
			if(self.oneDirection)
			{
				if(!direction)
				{
					direction = (Math.abs(dX) > Math.abs(dY)) ? 'left' : 'top';
				}
			}
			
			var directionLeft = (!direction || direction == 'left'),
				directionTop = (!direction || direction == 'top');
			
			if(elasticLeft || elasticTop)
			{
				var moveX = 0,
					moveY = 0,
					nextElasticLeft = elasticLeft + dX,
					nextElasticTop	= elasticTop + dY;
					
				if(elasticLeft)
				{
					if(elasticLeft < 0 && dX > 0)
					{
						if(nextElasticLeft > 0)
						{
							dX = -elasticLeft;
							elasticLeft = 0;
						}
						else
						{
							elasticLeft = nextElasticLeft;
						}
						
						moveX = dX;
						directionLeft = false;
						elasticDivX = self.elasticRatio;
					}
					else if(elasticLeft > 0 && dX < 0)
					{
						if(nextElasticLeft < 0)
						{
							dX = -elasticLeft;
							elasticLeft = 0;
						}
						else
						{
							elasticLeft = nextElasticLeft;
						}
						
						moveX = dX;
						directionLeft = false;
						elasticDivX = self.elasticRatio;
					}
				}
				
				if(elasticTop)
				{
					if(elasticTop < 0 && dY > 0)
					{
						if(nextElasticTop > 0)
						{
							dY = -elasticTop;
							elasticTop = 0;
						}
						else
						{
							elasticTop = nextElasticTop;
						}
						
						moveY = dY;
						directionTop = false;
						elasticDivY = self.elasticRatio;
					}
					else if(elasticTop > 0 && dY < 0)
					{
						if(nextElasticTop < 0)
						{
							dY = -elasticTop;
							elasticTop = 0;
						}
						else
						{
							elasticTop = nextElasticTop;
						}
						
						moveY = dY;
						directionTop = false;
						elasticDivY = self.elasticRatio;
					}
				}
				
					
				$container.ajTranslate(moveX, moveY);
			}
			
			if(directionLeft)
			{
				self.scrollLeftTo(left / maxLeft);
			}
			
			if(directionTop)
			{
				self.scrollTopTo(top / maxTop);
			}
			
			if(event)
			{
				event.stop();
				
				self.scrollInertia.change(-left, -top);
			}
			
			
			if(self.elastic && true !== noElastic && (ret[0] || ret[1]))
			{
				var moveX = 0,
					moveY = 0;
				
				if(directionLeft && ret[0] && ($wrapper.scrollWidth > $wrapper.clientWidth))
				{
					moveX = ret[0] / elasticDivX;
					elasticDivX	+= self.elasticRatio;
				}
				
				if(directionTop && ret[1] && ($wrapper.scrollHeight > $wrapper.clientHeight))
				{
					moveY = ret[1] / elasticDivY;
					elasticDivY	+= self.elasticRatio;
				}
				
				elasticLeft	+= moveX;
				elasticTop	+= moveY;
				
				$container.ajTranslate(moveX, moveY);
				
				return;
			}
			
			return ret;
		},
		dragFinish = function(event, fin)
		{
			direction = null;
			
			if(elasticLeft || elasticTop)
			{
				var startLeft = $container.ajCss('left').toFloat(),
					startTop = $container.ajCss('top').toFloat();
				
				self._elasticCin = new AidaCinematic({
					onFrame: function(i, t, r)
					{
						elasticLeft = (1 - r) * startLeft;
						elasticTop = (1 - r) * startTop;
						
						$container.ajCss({
							left: elasticLeft,
							top:  elasticTop
						});
					},
					easing: AidaEasing.outCubic,
					time: 0.5
				});
				
				self._elasticCin.start();
			}
			
			elasticDivX = self.elasticRatio;
			elasticDivY = self.elasticRatio;
			
			self.scrollFinish();
			
			
			if(fin)
			{
				
			}
			else
			{
				self.scrollInertia.end();
			}
		};
		
		this.scrollInertia = new AidaInertia({
			onFrame: function(dX, dY)
			{
				dragMove(null, dX, dY, true);
			},
			onFinish: function()
			{
				dragFinish(null, true);
			}
		});
		
		
		this.scrollDraggable = new AidaDraggable({
			target: $wrapper,
			onStart: function(event)
			{
				if(true !== self.scrollStart(event))
				{
					//event.stop();
				}
				
				self.scrollInertia.start();
			},
			onMove: dragMove,
			onFinish: dragFinish
		});
	
	}
	
	// Imposto le dimensioni degli handle
	//this.refresh();


	this.lastPassEvent;
	
	// Imposto l'evento wheel
	AidaEvent.add($container, 'mousewheel', function(event)
	{
		var passEvent = self.scrollStart(event, self.lastPassEvent);
		
		self.lastPassEvent = passEvent;
		
		var wheel = event.mouseWheel(), to, out;
		
		if (event.mouseWheelAxis() == 'horizontal' || (event.shiftKey() || self.scrollLeftWheel)) 
		{
			if (!self.noScrollLeft) 
			{
				to = ($wrapper.scrollLeft + (wheel * (AidaAgent.trident ? 50 : -50))) / ($wrapper.scrollWidth - $wrapper.clientWidth);
				
				out = self.scrollLeftTo(to);
			}
		}
		else 
		{
			if (!self.noScrollTop) 
			{
				to = ($wrapper.scrollTop + (wheel * -50)) / ($wrapper.scrollHeight - $wrapper.clientHeight);
				
				out = self.scrollTopTo(to);
			}
		}
		
		self.scrollFinish();
		
		if(!out && passEvent !== true)
		{
			return event.stop();
		}
	});
	
	AidaEvent.add($wrapper, 'keydown', function(event)
	{
		var top = null,
			left = null;
		
		switch(event.key())
		{
			case 'CursorDown':
				top = ($wrapper.scrollTop + 50) / ($wrapper.scrollHeight - $wrapper.clientHeight);
			break;
			case 'CursorUp':
				top = ($wrapper.scrollTop - 50) / ($wrapper.scrollHeight - $wrapper.clientHeight);
			break;
			case 'CursorLeft':
				left = ($wrapper.scrollLeft - 50) / ($wrapper.scrollWidth - $wrapper.clientWidth);
			break;
			case 'CursorRight':
				left = ($wrapper.scrollLeft + 50) / ($wrapper.scrollWidth - $wrapper.clientWidth);
			break;
		}
		
		if(top !== null)
		{
			self.scrollTopTo(top);
			
			self.scrollStart();
			self.scrollFinish();
		}
		
		if(left !== null)
		{
			self.scrollLeftTo(left);
			
			self.scrollStart();
			self.scrollFinish();
		}
	});

	
	AidaEvent.add(window, 'resize', function()
	{
		self.refresh();
	});
	
	AidaEvent.onLoad(function()
	{
		//self.scrolling = true;
		self.refresh();
		
		if(options.autoRefresh)
		{
			self.autoRefresh(options.autoRefreshTime);
		}
		
		//self.scrollFinish();
	});
	
	this.onReady();
}

AidaScrollBar.prototype = {
	startPageEase: function(scrollLeft, scrollTop)
	{
		if (this.paginated) 
		{
			this.stopPageEase();
			
			//this.pageEaseTimeout = setTimeout((function()
			//{
				//this.refreshContentSizes();
				
				var $wrapper = this.$wrapper;
				
				if(!Aida.is(scrollLeft))
				{
					scrollLeft = $wrapper.scrollLeft;
				}
				
				if(!Aida.is(scrollTop))
				{
					scrollTop = $wrapper.scrollTop;
				}
				
				scrollLeft	= Math.min($wrapper.scrollWidth - $wrapper.clientWidth, scrollLeft);
				scrollTop	= Math.min($wrapper.scrollHeight - $wrapper.clientHeight, scrollTop);
				
				var	self = this,
					iLeft = Math.round(scrollLeft / $wrapper.clientWidth),
					iTop = Math.round(scrollTop / $wrapper.clientHeight);
					

				if(this.pages)
				{
					if(!this.pages[iTop])
					{
						while(!this.pages[iTop])
						{
							if(!iTop)
							{
								break;
							}
							
							iTop--;
						}
					}
					
					if(!this.pages[iTop][iLeft])
					{
						while(!this.pages[iTop][iLeft])
						{
							if(!iLeft)
							{
								break;
							}
							
							iLeft--;
						}
					}
				}
				
				var startLeft = $wrapper.scrollLeft,
					diffLeft = ($wrapper.clientWidth * iLeft) - startLeft,
					
					startTop = $wrapper.scrollTop,
					diffTop = ($wrapper.clientHeight * iTop) - startTop;
				
				var pageChange = (iLeft != this.pagePrevX || iTop != this.pagePrevY),
					data = {
						pageChange: pageChange,
						pageX: iLeft,
						pageY: iTop,
						pagePrevX: this.pagePrevX,
						pagePrevY: this.pagePrevY
					};
					
				this.pagePrevX = iLeft;
				this.pagePrevY = iTop;
				
				if(diffLeft != 0 || diffTop != 0)
				{
					this._cin = new AidaCinematic({
						onFrame: function(i, t, r)
						{
							var scrollLeft = Math.max(0, Math.min(Math.round(startLeft + (diffLeft * r)), $wrapper.scrollWidth - $wrapper.clientWidth));
							var scrollTop =  Math.max(0, Math.min(Math.round(startTop + (diffTop * r)), $wrapper.scrollHeight - $wrapper.clientHeight));
							
							$wrapper.scrollLeft = scrollLeft;
							$wrapper.scrollTop = scrollTop;
							
							self.refreshScrollbars();
						},
						onFinish: function()
						{
							self.fireScrollFinish();
							self.onPage(data);
							
							if(pageChange)
							{
								self.onPageChange(data);
							}
						},
						easing: AidaEasing.outCubic,
						time: 0.5
					});
					
					this._cin.start();
				}
				else
				{
					this.fireScrollFinish();
					this.onPage(data);
					
					if(pageChange)
					{
						this.onPageChange(data);
					}
				}
				
			//}).bind(this), 200);
		}
		else
		{
			this.fireScrollFinish();
		}
	},
	stopPageEase: function()
	{
		if(this._cin)
		{
			this._cin.stop();
		}
		
		//clearTimeout(this.pageEaseTimeout);
	},
	fireScrollFinish: function()
	{
		this.$container.ajRemoveClass('scrolling');
		this.onScrollFinish();
	},
	
	scrollStart: function(event, lastPassEvent)
	{
		// Scroll Start
		clearTimeout(this.scrollFinishTO);
		
		this.stopPageEase();
		
		if(!this.scrolling)
		{
			this.scrolling = true;
			
			this.$container.ajAddClass('scrolling');
			
			return this.onScrollStart(event);
		}
		
		return lastPassEvent;
	},
	scrollFinish: function()
	{
		// Scroll Finish
		clearTimeout(this.scrollFinishTO);
		
		this.scrollFinishTO = setTimeout((function()
		{
			if(this.scrolling)
			{
				this.scrolling = false;
				this.lastPassEvent = null;
				
				this.startPageEase();
			}
		}).bind(this), 300);
	},
	frame: function()
	{
		
	},
	scrollTopOf: function(of, px)
	{
		var $wrapper = this.$wrapper;
		
		var to = px ? ($wrapper.scrollTop + of) / ($wrapper.scrollHeight - $wrapper.clientHeight) :
			($wrapper.scrollTop / ($wrapper.scrollHeight - $wrapper.clientHeight)) + of;
		
		this.scrollTopTo(to);
	},
	scrollLeftOf: function(of, px)
	{
		var $wrapper = this.$wrapper;
		
		var to = px ? ($wrapper.scrollLeft + of) / ($wrapper.scrollWidth - $wrapper.clientWidth) :
			($wrapper.scrollLeft / ($wrapper.scrollWidth - $wrapper.clientWidth)) + of;
		
		this.scrollLeftTo(to);
	},
	scrollTo: function(left, top, px, morph)
	{
		if(morph)
		{
			if(morph === true)
			{
				morph = {};
			}
			
			var $wrapper = this.$wrapper,
				self = this;
			
			var startLeft = $wrapper.scrollLeft,
				maxLeft = $wrapper.scrollWidth - $wrapper.clientWidth,
				diffLeft = Math.min(left, maxLeft) - startLeft,
				
				startTop = $wrapper.scrollTop,
				maxTop = $wrapper.scrollHeight - $wrapper.clientHeight,
				diffTop = Math.min(top, maxTop) - startTop;
			
			
			this.stopPageEase();
				
			this._cin = new AidaCinematic({
				onFrame: function(i, t, r)
				{
					var scrollLeft = Math.max(0, Math.min(Math.round(startLeft + (diffLeft * r)), maxLeft));
					var scrollTop =  Math.max(0, Math.min(Math.round(startTop + (diffTop * r)), maxTop));
					
					$wrapper.scrollLeft = scrollLeft;
					$wrapper.scrollTop = scrollTop;
					
					self.refreshScrollbars();
				},
				onFinish: function()
				{
					self.fireScrollFinish();
				},
				easing: morph.easing || AidaEasing.outCubic,
				time: morph.time || 0.5
			});
			
			this._cin.start();
			
			
			return;
		}
		
		this.scrollLeftTo(left, px);
		this.scrollTopTo(top, px);
	},
	scrollTopTo: function(to, px, morph)
	{
		var $wrapper = this.$wrapper;
		
		if(px)
		{
			to = to / ($wrapper.scrollHeight - $wrapper.clientHeight);
		}
		
		var out = (to < 0 || to > 1);
		
		to = to.bound(0, 1);
		
		if(this.$topBar)
		{
			var top = (this.$topBar.clientHeight - this.scrollbarTopHandleHeight) * to;
			
			// Imposto la positione della barra
			this.$topHandle.ajCss('top', top);
		}
		
		$wrapper.scrollTop = to * ($wrapper.scrollHeight - $wrapper.clientHeight);
		
		this.fireOnScroll();
		
		return out;
	},
	scrollLeftTo: function(to, px)
	{
		var $wrapper = this.$wrapper;
		
		if(px)
		{
			to = to / ($wrapper.scrollWidth - $wrapper.clientWidth);
		}
		
		var out = (to < 0 || to > 1);
		
		to = to.bound(0, 1);
		
		if(this.$leftBar)
		{
			var left = (this.$leftBar.clientWidth - this.scrollbarLeftHandleWidth) * to;
		
			// Imposto la positione della barra
			this.$leftHandle.ajCss('left', left);
		}
		
		// Imposto il nuovo valore di scroll
		$wrapper.scrollLeft = to * ($wrapper.scrollWidth - $wrapper.clientWidth);
		
		this.fireOnScroll();
		
		return out;
	},
	fireOnScroll: function()
	{
		var	$wrapper = this.$wrapper,
			scrollLeft = $wrapper.scrollLeft,
			scrollTop = $wrapper.scrollTop,
			scrollWidth = $wrapper.scrollWidth,
			scrollHeight = $wrapper.scrollHeight,
			clientWidth = $wrapper.clientWidth,
			clientHeight = $wrapper.clientHeight,
		
			leftRatio = scrollLeft / (scrollWidth - clientWidth),
			topRatio = scrollTop / (scrollHeight - clientHeight)
		
		this.onScroll({
			leftMin: scrollLeft,
			leftMax: scrollLeft + clientWidth,
			viewWidth: clientWidth,
			width: scrollWidth,
			maxLeft: scrollWidth - clientWidth,
			leftRatio: leftRatio,
			
			topMin: scrollTop,
			topMax: scrollTop + clientHeight,
			viewHeight: clientHeight,
			height: scrollHeight,
			maxTop: scrollHeight - clientHeight,
			topRatio: topRatio
		});
	},
	refresh: function()
	{
		if(this.pages)
		{
			this.refreshContentSizes();
		}
		this.refreshScrollbars();
		this.refreshScrollbarsHandles();
		
		// Scroll Finish
		clearTimeout(this.refreshTO);
		
		this.refreshTO = setTimeout((function()
		{
			this.startPageEase();
		}).bind(this), 300);
	},
	autoRefresh: function(time)
	{
		this.autoRefreshTO = (setInterval(function()
		{
			this.refresh();
			 
		}).bind(this), time || 1000);
	},
	getContentSizes: function()
	{
		var $wrapper = this.$wrapper;
		
		if(this.paginated)
		{
			if(this.pages)
			{
				return {
					width: $wrapper.clientWidth * this.pagesCols,
					height: $wrapper.clientHeight * this.pagesRows
				}
			}
			
			return {
				width: Math.ceil(($wrapper.scrollWidth * 0.9) / $wrapper.clientWidth) * $wrapper.clientWidth,
				height: Math.ceil(($wrapper.scrollHeight * 0.9) / $wrapper.clientHeight) * $wrapper.clientHeight
			}
		}
		
		return {
			width: $wrapper.clientWidth,
			height: $wrapper.clientHeight
		};
	},
	refreshContentSizes: function()
	{
		var sizes = this.getContentSizes();
		
		this.$content.ajCss({
			width: sizes.width,
			height: sizes.height
		});
	},
	refreshScrollbars: function()
	{
		var $wrapper = this.$wrapper,
			$leftBar = this.$leftBar,
			$topBar = this.$topBar;
		
		if ($leftBar) 
		{

			if($wrapper.scrollWidth > $wrapper.clientWidth)
			{
				$leftBar.ajShow();
				
				var to = ($wrapper.scrollLeft) / ($wrapper.scrollWidth - $wrapper.clientWidth);
			
				this.scrollLeftTo(to);
				
				if(this.$leftMinus)
				{
					this.$leftMinus.ajShow();
					this.$leftPlus.ajShow();
				}
			}
			else
			{
				$leftBar.ajHide();
				
				if(this.$leftMinus)
				{
					this.$leftMinus.ajHide();
					this.$leftPlus.ajHide();
				}
			}
		}

		if ($topBar) 
		{
			if($wrapper.scrollHeight > $wrapper.clientHeight)
			{
				$topBar.ajShow();
				
				var to = ($wrapper.scrollTop) / ($wrapper.scrollHeight - $wrapper.clientHeight);
			
				this.scrollTopTo(to);
				
				if(this.$topMinus)
				{
					this.$topMinus.ajShow();
					this.$topPlus.ajShow();
				}
			}
			else
			{
				$topBar.ajHide();
				
				if(this.$topMinus)
				{
					this.$topMinus.ajHide();
					this.$topPlus.ajHide();
				}
			}
		}
	},
	refreshScrollbarsHandles: function()
	{
		var $wrapper = this.$wrapper,
			$topHandle = this.$topHandle,
			$leftHandle = this.$leftHandle,
			ratio;
		
		
		if ($topHandle) 
		{
			if (this.fixedSizesTopHandle) 
			{
				this.scrollbarTopHandleHeight = $topHandle.ajSize().height;
			}
			else 
			{
				ratio = $wrapper.clientHeight / $wrapper.scrollHeight;
				
				this.scrollbarTopHandleHeight = Math.round(ratio * this.$topBar.clientHeight);
				
				$topHandle.ajCss({
					height: this.scrollbarTopHandleHeight + 'px'
				});
			}
		}
		
		if ($leftHandle) 
		{
			if (this.fixedSizesLeftHandle) 
			{
				this.scrollbarLeftHandleWidth = $leftHandle.ajSize().width;
			}
			else 
			{
				ratio = $wrapper.clientWidth / $wrapper.scrollWidth;
				
				this.scrollbarLeftHandleWidth = Math.round(ratio * this.$leftBar.clientWidth);
				
				$leftHandle.ajCss({
					width: this.scrollbarLeftHandleWidth + 'px'
				});
			}
		}
	}
};
