var MiniShowCase = new Class(
{
    Implements: Options,
    options: {
        mode: 'right',
		containerHeight: null
    },
	container: null,
	elements: [],
	actual: 0,
	anterior: null,
	width: 0,
	interval: 0,
	initialize: function(container, elements, options)
	{
		this.setOptions(options);
		this.container = container;
		this.elements = this._preProcessElements(elements);
		this.width = container.getStyle('width');
		this.actual = 0;
		
		this.container.setStyles({'position':'relative', 'overflow':'hidden'});
		
		if(this.options.containerHeight != null) {
			this.container.setStyle('height', this.options.containerHeight);
		}
	},
	play: function(time, direction)
	{
		this.interval = this[direction].periodical(time, this);
	},
	stop: function()
	{
		$clear(this.interval);
	},
	reset: function()
	{
		this.actual = 0;
		this.anterior = null;
	},
	change: function(index)
	{
		this.anterior = this.actual;
		
		if(index > this.elements.length - 1) {
			this.actual = 0;
		}else if(index < 0) {
			this.actual = this.elements.length - 1;
		}else{
			this.actual = index;
		}

		this._setInPosition();
		this._animate();
	},
	next: function()
	{
		this.change(this.actual + 1);
	},
	previous: function()
	{
		this.change(this.actual - 1);
	},
	_animate: function()
	{
		this.elements[this.actual].tween('left', '0px');
		
		if(this.options.mode == 'right') {
			this.elements[this.anterior].tween('left', (-this.width.toInt()) + 'px');
		}else{
			this.elements[this.anterior].tween('left', this.width);
		}
	},
	_setInPosition: function()
	{
		var next = this.elements[this.actual];
		
		if(this.options.mode == 'right') {
			this._setPosition(next, this.width);
			next.inject(this.container, 'bottom');
		}else{
			this._setPosition(next, -(this.width.toInt()));
			next.inject(this.container, 'top');
		}
	},
	_setPosition: function(element, x)
	{
		element.setStyle('position', 'absolute');
		element.setStyle('left', x);
		element.setStyle('top', 0);
	},
	_preProcessElements: function(elements)
	{
		var theElements = [];
		
		elements.each(function(el, c)
		{
			if(c == 0) {
				theElements.push(el);
				this._setPosition(el, this.width);
			}else{
				theElements.push(el.dispose());
			}
		}.bind(this));
		
		return theElements;
	}
});
