var mooGallerieScroll = new Class({

	Implements: [Events, Options],
	options: {
		width: 940,
		duration: 500,
		'debug': false
	},
	container: null,
	Items: null,
	Scroll: null,
	CurrentL: 0,
	CurrentR: 0,
	action: 0,

	/* Initialisierung */
	initialize: function(node, options) {
		this.setOptions(options);
		this.pObj 		= node;
		this.gallerie	= node.getElement('.gallery');
		this.container	= node.getElement('.inner');
		this.Items		= this.container.getElements('a');

		this.options.width=0;

		this.Items.each(function(item, id){
			this.options.width += item.getWidth();
			if(this.CurrentR == 0 && this.options.width >= this.gallerie.getWidth()) this.CurrentR = id+1;
		}, this);

		this.container.setStyle('width', this.options.width);

		if(this.options.width <= this.gallerie.getWidth()) return;
		this.goLeft  = new Element('div.toLeft' ).adopt(new Element('a').addEvent('click', function(event){event.stop(); /*if(this.action==1)return;*/ this.scrollLeft(); }.bind(this)));
		this.goRight = new Element('div.toRight').adopt(new Element('a').addEvent('click', function(event){event.stop(); /*if(this.action==1)return;*/ this.scrollRight(); }.bind(this)));


		this.goLeft.inject(this.pObj, "top");
		this.goRight.inject(this.pObj, "bottom");

		this.Pos = this.container.getPosition();
		this.Scroll = new Fx.Tween(this.container, {link:'cancel', duration: this.options.duration, transition:Fx.Transitions.Sine.easeOut, property: 'left'});

	},

	scrollLeft: function() {
		if(this.CurrentL <= 0) return;
		this.CurrentL -= 1;
		this.CurrentR -= 1;
		this.action = 1;
		this.Scroll.chain(function(){this.action=0;}.bind(this));
		this.Scroll.start(this.container.getStyle('left').toInt() + this.Items[this.CurrentR].getWidth());
	},

	scrollRight: function(event) {
		if(this.CurrentR >= this.Items.length) return;
		this.CurrentL += 1;
		this.CurrentR += 1;
		this.action = 1;
		this.Scroll.chain(function(){this.action=0;}.bind(this));
		this.Scroll.start(this.container.getStyle('left').toInt() - this.Items[this.CurrentR-1].getWidth());
	}
});

