var ScrollButton = new Class({
	target:false,
	initialize:function(pTarget, dir, aSpeed, pButton)
	{
		this.isMobileSafari = navigator.userAgent.match(/.*AppleWebKit.+Mobile.*/);
		this.target = pTarget;
		this.targetcontent = this.target.getFirst('div');
		this.direction = dir;
		this.timePer100Px = 100 / aSpeed;
		this.scroller = new Fx.Scroll(this.target, {
			duration: Number.MAX_VALUE,
			fps: 25,
			wait: false,
			transition: 'linear',
			wheelStops: false,
			offset: {
				'x': 0,
				'y': 0
			}
		});
		if(pButton)
		{
			this.button = pButton;
			if(!this.isMobileSafari)
			{
				pButton.addEvent('mousedown', this.pressed.bind(this));
				pButton.addEvent('mouseup', this.released.bind(this));
				pButton.addEvent('mouseout', this.released.bind(this));
			}
			else
			{
				pButton.addEventListener('touchstart', this.pressed.bind(this), false);
				pButton.addEventListener('touchcancel', this.released.bind(this), false);
				pButton.addEventListener('touchend', this.released.bind(this), false);
			}
		}
		
	},
	pressed:function(event)
	{
		var scrollSize = this.target.getScrollSize();
		var scrollPos  = this.target.getScroll();
		var targetSize = this.target.getSize();
		if (this.scroller) this.scroller.cancel();

		
		var scrollDuration;
		var targetX = -1;
		var targetY = -1;
		if (this.direction == 'up')
		{
			scrollDuration = this.timePer100Px * (scrollPos.y * 0.01);
			targetX = scrollPos.x;
			targetY = 0;
		}
		else if(this.direction == 'down')
		{
			scrollDuration = this.timePer100Px * ((scrollSize.y - targetSize.y - scrollPos.y) * 0.01);
			targetX = scrollPos.x;
			targetY = scrollSize.y;
		}
		else if (this.direction == 'left') {
			//Scrolldauer ist definiert für 100 pixel
			scrollDuration = this.timePer100Px * (scrollPos.x * 0.01);
			targetX = 0;
			targetY = scrollPos.y;
		}
		else if (this.direction == 'right')
		{
			scrollDuration = this.timePer100Px * ((scrollSize.x - targetSize.x - scrollPos.x) * 0.01);
			targetX = scrollSize.x;
			targetY = scrollPos.y;

		}
		//Scrolldauer ist definiert für 100 pixel
			 
		this.scroller = new Fx.Scroll(this.target.id,
			{
				duration: scrollDuration,
				fps: 25,
				wait: false,
				transition: 'linear',
				wheelStops: false,
				offset:
				{
					'x': 0,
					'y': 0
				}
			});
		//if(this.isMobileSafari) console.info('pressed: ' + targetX +', '+ targetY);
		this.scroller.start(targetX, targetY);
		event.preventDefault();
	},
	released:function()
	{
		this.scroller.cancel();
		//if(this.isMobileSafari) console.info('released');
		event.preventDefault();
	}

});


