
var avScroll = new Class({

    options: {
		imgWidth: 0,
		scrollRange: 0,
		leftHandle: null,
		rightHandle: null,
		container: null,
		leftClicks: 0,
		rightClicks: 0,
		speed: 200,
		count:0,
		anzahl: 16
	},
	
	initialize: function(options){
	this.setOptions(options)
	
		this.imgWidth = options['imgWidth'];
		this.scrollRange = options['scrollRange'];
		this.leftHandle = options['leftHandle'];
		this.rightHandle = options['rightHandle'];	
		this.anzahl = options['anzahl'];
		this.count = 0;
		this.container = $(options['container']);
		
		if($(options['ff'])){
			this.ff = $(options['ff']);
			$(this.ff).addEvent('click',this.fastForward.bindWithEvent(this));
		}
		if($(options['rw'])){
			this.rw = $(options['rw']);
			$(this.rw).addEvent('click',this.speedReverse.bindWithEvent(this));
		}
		
		this.leftClicks = 0;
		this.rightClicks = 0;
		this.speed = 850;		
		$(this.leftHandle).addEvent('click',this.leftClick.bindWithEvent(this));
		$(this.rightHandle).addEvent('click',this.rightClick.bindWithEvent(this));
	},
	
	
	leftClick: function(){
		
				if(this.leftClicks > 0){
					var start= this.leftClicks * this.imgWidth;
					var end = ( this.leftClicks - 1 ) * this.imgWidth;
					$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut }).start(start,end);
					this.leftClicks--;
				}
				
				
	},
		
	rightClick: function(){
				var start= this.leftClicks * this.imgWidth;
				var end = (this.leftClicks * this.imgWidth) + this.imgWidth;
				$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut}).start(start,end);
				this.leftClicks++;
				
	},
	
	fastForward: function(){
				// scroll 4 images to the right, calculate it on base of the clicks and the image width
				
				
				for(var i = 8 ; i > 0; i--)
				{
					if((this.count + (9 + i)) <= this.anzahl)
					{
						var start= (this.leftClicks) * (this.imgWidth +17.07);			
						var end = (( this.leftClicks + i ) * (this.imgWidth +17.07));
						$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut }).start(start,end);
						this.leftClicks = this.leftClicks + i;
						this.count += i;
						return;
					}
				}
				/*else
				{
					if((this.count + (8 + 7)) <= this.anzahl)
					{
						var start= (this.leftClicks) * (this.imgWidth +18);			
						var end = (( this.leftClicks + 7) * (this.imgWidth +18));
						$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut }).start(start,end);
						this.leftClicks = this.leftClicks + 7;
						this.count += 2;
					}
					else
					{
						if((this.count + (8 + 6)) <= this.anzahl)
						{
							var start= (this.leftClicks) * (this.imgWidth +18);			
							var end = (( this.leftClicks + 6 ) * (this.imgWidth +18));
							$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut }).start(start,end);
							this.leftClicks = this.leftClicks + 6;
							this.count += 6;
						}else 	
							{
								if((this.count + (8 + 5)) <= this.anzahl)
								{
									var start= (this.leftClicks) * (this.imgWidth +18);			
									var end = (( this.leftClicks + 6 ) * (this.imgWidth +18));
									$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut }).start(start,end);
									this.leftClicks = this.leftClicks + 6;
									this.count += 6;
								}
							}
					}
				}*/
				
	},
	
	speedReverse: function(){
		
			for(var i = 8 ; i > 0; i--)
			{
				if(this.count - i >= 0)
				{
					var start= (this.leftClicks *  (this.imgWidth +17.07) );
					var end = ((this.leftClicks  - i ) * (this.imgWidth +17.07));
					$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut }).start(start,end);
					this.leftClicks-= i;
					this.count -=i;
					return;
				}
			}
		
			/*if(this.count - 3 >= 0)
			{
				var start= (this.leftClicks *  (this.imgWidth +18) );
				var end = ((this.leftClicks  - 3 ) * (this.imgWidth +18));
				$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut }).start(start,end);
				this.leftClicks-= 3;
				this.count -=3;
			}
			else
				{
					if((this.count - (8 + 2)) >= 0)
					{
						var start= (this.leftClicks) * (this.imgWidth +18);			
						var end = (( this.leftClicks - 2 ) * (this.imgWidth +18));
						$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut }).start(start,end);
						this.leftClicks = this.leftClicks - 2;
						this.count -= 2;
					}
					else
					{
						if((this.count - (8 + 1)) >=0)
						{
							var start= (this.leftClicks) * (this.imgWidth +18);			
							var end = (( this.leftClicks - 1 ) * (this.imgWidth +18));
							$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Quad.easeOut }).start(start,end);
							this.leftClicks = this.leftClicks - 1;
							this.count -= 1;
						}
					}
				}*/
				
	}
				
});
avScroll.implement(new Options, new Events);


