Scroller = Class.create();
Scroller.prototype = {
	
	/*Costruttore*/
	initialize: function(scrollingContentElement, scrollValue){
		this.scrollingContentElement = scrollingContentElement;
		this.scrollValue = scrollValue;
		this.totalScroll = 0;
		
		this.scrollingContentWidth = $(scrollingContentElement).parentNode.scrollWidth;
		this.scrollingContentHeight = $(scrollingContentElement).parentNode.scrollHeight;
		this.scrollingContainerWidth = $(scrollingContentElement).parentNode.offsetWidth;
		this.scrollingContainerHeight = $(scrollingContentElement).parentNode.offsetHeight;
		
		this.moving = false;
	},
	
	scrollRight: function(moreRightSpace){
		if(this.scrollingContentWidth - this.scrollingContainerWidth - this.totalScroll + moreRightSpace > 0 && !this.moving){
		/*if(this.totalScroll + this.scrollingContainerWidth < this.scrollingContentWidth + 80 && !this.moving){*/
			var currentScroller = this;
			new Effect.Move(this.scrollingContentElement, {
				x: -this.scrollValue,
				y: 0,
				beforeStart: function(){
					currentScroller.moving = true;
				},
				afterFinish: function(){
					currentScroller.totalScroll += currentScroller.scrollValue;
					currentScroller.moving = false;
				}
			});
		}
	},
	
	scrollLeft: function(){
		if(this.totalScroll > 0 && !this.moving){
			var currentScroller = this;
			new Effect.Move(this.scrollingContentElement, {
				x: this.scrollValue,
				y: 0,
				beforeStart: function(){
					currentScroller.moving = true;
				},
				afterFinish: function(){
					currentScroller.totalScroll -= currentScroller.scrollValue;
					currentScroller.moving = false;
				}
			});
		}
	},
	
	scrollBottom: function(){
		if(this.scrollingContentHeight - this.scrollingContainerHeight - this.totalScroll > 0 && !this.moving){
		/*if(this.totalScroll + this.scrollingContainerHeight < this.scrollingContentHeight && !this.moving){*/
			var currentScroller = this;
			new Effect.Move(this.scrollingContentElement, {
				x: 0,
				y: -this.scrollValue,
				beforeStart: function(){
					currentScroller.moving = true;
				},
				afterFinish: function(){
					currentScroller.totalScroll += currentScroller.scrollValue;
					currentScroller.moving = false;
				}
			});
		}
	},
	
	scrollTop: function(){
		if(this.totalScroll > 0 && !this.moving){
			var currentScroller = this;
			new Effect.Move(this.scrollingContentElement, {
				x: 0,
				y: this.scrollValue,
				beforeStart: function(){
					currentScroller.moving = true;
				},
				afterFinish: function(){
					currentScroller.totalScroll -= currentScroller.scrollValue;
					currentScroller.moving = false;
				}
			});
		}
	},
	
	scrollAllTop: function(){
		if(this.totalScroll > 0){
			var currentScroller = this;
			new Effect.Move(this.scrollingContentElement, {
				x: 0,
				y: this.totalScroll,
				beforeStart: function(){
					currentScroller.moving = true;
				},
				afterFinish: function(){
					currentScroller.totalScroll -= currentScroller.scrollValue;
					currentScroller.moving = false;
				}
			});
		}
	}
};