var EdelNewsTeaser = new Class({
	Implements: [Options, Events],
	options: {
		itemsVisible:		5,
		currentElement:		0,
		showControls:		1,
		transition:			Fx.Transitions.sine,
		transitionDuration:	500,
		overallContainer:	'newsTeaserBox',
		elementScrolled:	'newsTeaserContainer',
		teaserContainer:	'newsTeasers'
	},
	initialize: function(options) {
		this.setOptions(options);
		this.elements = $(this.options.teaserContainer).getElements('.newsTeaser');
		this.scrollFx = new Fx.Scroll(this.options.elementScrolled, {transition: this.options.transition, duration: this.options.transitionDuration}); 
		this.forwardButton = this.addController('forwardButton');
		this.backwardButton = this.addController('backwardButton');
		this.assignNewsTeaserEvents();
		this.assignForwardEvent();
		this.assignBackwardEvent();
	},
	slide: function(step) {
		if((this.options.currentElement < this.elements.length-this.options.itemsVisible && step > 0) || (step < 0 && this.options.currentElement !== 0)) {
			this.scrollFx.cancel();
			this.options.currentElement += step;
			this.scrollFx.toElement(this.elements[this.options.currentElement]);
		}
	},
	addController: function(cssClass) {
		element = new Element('div', {
			'class': cssClass,
			styles: {
				'display': this.options.showControls ? '' : 'none'
			}
		}).injectInside($(this.options.overallContainer));
		return element;
	},
	assignForwardEvent: function() {				
		this.forwardButton.addEvent('click', function() {
			this.slide(this.options.itemsVisible);
		}.bind(this));
	},
	assignBackwardEvent: function() {			
		this.backwardButton.addEvent('click', function() {											
			this.slide(this.options.itemsVisible * (-1));			
		}.bind(this));
	},
	assignNewsTeaserEvents: function() {
		this.elements.each(function(element) {
			defaultTeaserImageHeight = element.getStyle('height');
			newsTeaserImage = element.getElement('.newsImage');
			newsTeaserText = element.getElement('.newsText');
			
			var teaserScrollFx = new Fx.Scroll(element, {duration: 500, transition: Fx.Transitions.sine});
			var isScrolling = false;
			
			newsTeaserImage.addEvent('mouseenter', function() {
				teaserScrollFx.cancel();
				teaserScrollFx.toBottom();
			});
			
			element.addEvent('mouseleave', function() {
				teaserScrollFx.cancel();
				teaserScrollFx.toTop();
			});			
		});
	}
});
