Module.Media = Class.create ({
	current: 0,
	width: 0,
	animating: false,
	initialize : function ()
	{
	},
	parse: function()
	{
		if (this.container = $$('.mediaDefault').shift ())
		{
			if (this.container.select ('.listContainer .list').length > 0)
			{
				this.width = this.container.select ('.listContainer .list').shift ().getWidth ();
				this.transition	= Effect.Transitions.linear;
				if (this.scroller = this.container.select ('.listContainer .list').shift ())
				{
					this.container.select('.left').shift ().observe ('click', this.left.bind (this));
					this.container.select('.right').shift ().observe ('click', this.right.bind (this));
				}
			}
		}
	},
	left: function()
	{
		if (!this.animating && this.current < 0)
		{
			this.current += (135 * 4);

			new Effect.Morph (this.scroller, { queue: 'end', transition: this.transition, duration: 0.5, style: "left: "+this.current+'px;', afterFinish: this.stopAnimate.bind (this) });
		}
	},
	right: function()
	{
		if (!this.animating && this.current > -this.width + (135 * 5))
		{
			this.current -= (135 * 4);

			new Effect.Morph (this.scroller, { queue: 'end', transition: this.transition, duration: 0.5, style: "left: "+this.current+'px;', afterFinish: this.stopAnimate.bind (this) });
		}
	},
	stopAnimate: function()
	{
		this.animating = false;
	}
});

var mediaModule = new Module.Media ();
document.observe ('dom:loaded', function (event) { mediaModule.parse (); });
