var HomeScroller = Class.create ({
	
	initialize: function(container)
	{
		this.container = container;
		this.numItems = $$('div.sliderItemHome').size();
		this.scrollerWidth = (980*this.numItems);
		this.currentPos = $$('div.sliderItemHome').size();
		
		this.container.select('div.sliderContentHome')[0].setStyle({width: this.scrollerWidth + "px"});
		
		if (!this.container)
		{
			return false;
		}
		this.addControls();
		
		this.timer = new PeriodicalExecuter(this.timedMove.bind(this), 7)
	},
	
	addControls: function()
	{	
		$$('a').each(function(container)
		{
			if (container.hasClassName('displayNone')) 
			{
				container.removeClassName('displayNone');
				container.addClassName('displayBlock');
			}
		});
		
		$$('div').each(function(container)
		{
			if (container.hasClassName('displayNone')) 
			{
				container.removeClassName('displayNone');
				container.addClassName('displayBlock');
			}
		});
	},
	
	doMove: function(amount)
	{	
		if(((this.currentPos - amount) > 0) && ((this.currentPos - amount) <= this.numItems))
		{
			this.currentPos = this.currentPos - amount;
			new Effect.Move($('sliderContentHome'), { y: (274*amount*-1), x: 0, mode: 'relative', duration: 0.8, queue: 'end' });
		}
	},
	
	restartTimer: function()
	{
		this.timer.stop();
		this.timer = new PeriodicalExecuter(this.timedMove.bind(this), 7)
	},
	
	timedMove: function()
	{
		if((this.currentPos) == 1)
		{
			this.doMove((this.numItems-1)*-1);
		}
		else
		{
			this.doMove(1);
		}
	}
});


document.observe('dom:loaded', function()
{	
	if ($("sliderBoxHome"))
	{
		new HomeScroller($('sliderBoxHome'));
	}
});
