
var avScroll = new Class({

    options: {
		imgWidth: 0,
		scrollRange: 0,
		leftHandle: null,
		rightHandle: null,
		container: null,
		leftClicks: 0,
		rightClicks: 0,
		speed: 500,
		effect: 1
	},

	initialize: function(options){
		this.setOptions(options);

		this.imgWidth = options['imgWidth'];
		this.scrollRange = options['scrollRange'];
		this.leftHandle = options['leftHandle'];
		this.rightHandle = options['rightHandle'];
		this.container = $(options['container']);
		this.speed = options['speed'];
		this.effect = options['effect'];

		this.leftClicks = 0;
		this.rightClicks = 0;

		$(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;
			if (this.effect){
				$(this.container).effect('right',{ duration: this.speed, wait:true, transition:Fx.Transitions.Back.easeIn }).start(start,end);
			} else {
				$(this.container).effect('right',{ duration: this.speed, wait:true}).start(start,end);
			}
			$$('.rightControl').setProperty('src', '/themes/main/images/catalog-rarrow.gif');
			$$('.rightControl').setStyle('cursor', 'pointer');
			this.leftClicks--;
			if (this.leftClicks != 0)
			{
				$$('.leftControl').setProperty('src', '/themes/main/images/catalog-larrow.gif');
				$$('.leftControl').setStyle('cursor', 'pointer');
			}
			else
			{
				$$('.leftControl').setProperty('src', '/themes/main/images/spacer.gif');
				$$('.leftControl').setStyle('cursor', 'auto');
			}
		}
	},
	rightClick: function(){
		if(this.leftClicks < this.scrollRange){
			var start = this.leftClicks * this.imgWidth;
			var end = (this.leftClicks * this.imgWidth) + this.imgWidth;
			if (this.effect){
				$(this.container).effect('right',{ duration: this.speed, wait:true, transition: Fx.Transitions.Back.easeIn }).start(start,end);
			} else {
				$(this.container).effect('right',{ duration: this.speed, wait:true}).start(start,end);
			}
			$$('.leftControl').setProperty('src', '/themes/main/images/catalog-larrow.gif');
			$$('.leftControl').setStyle('cursor', 'pointer');
			this.leftClicks++;
			if (this.leftClicks != this.scrollRange)
			{
				$$('.rightControl').setProperty('src', '/themes/main/images/catalog-rarrow.gif');
				$$('.rightControl').setStyle('cursor', 'pointer');
			}
			else
			{
				$$('.rightControl').setProperty('src', '/themes/main/images/spacer.gif');
				$$('.rightControl').setStyle('cursor', 'auto');
			}
		}
	}
});

avScroll.implement(new Options, new Events);


