
document.observe("dom:loaded", function() {
	var slider = $('slider');
	if (!slider) return;

	Object.extend(slider, Slider).initialize();
});

var Slider = {

	initialize: function() {
		this.sliding = false;
		this.container = this.down('.slidercontainer');
		return this;
	},

	getBlocks: function() {
		this.container.select('.block');
	},

	display: function(block) {
		if (this.isSliding() || !block || !block.hasClassName('sliderblock')) return false;

		this.sliding = true;
		this.container.insert(block);

		new Effect.Move(this.container, {
			x: -block.getWidth(),
			y: 0,
			mode: 'relative',
			duration: 1.5,
			afterFinish: function() {
				this.container.down('.sliderblock').remove();
				this.container.setStyle({ left: 0 });
				this.sliding = false;
			}.bind(this)
		});

		return true;
	},

	isSliding: function() {
		return this.sliding;
	}

}