Cundo.Flippers = Class.create({
	initialize: function(data)
	{
		this.data = data;
		this.pointer = 3;
		this.picPointer = -1; // which pic are we going to change
		this.container = $('flippers');
		this.elements = this.container.select('li');
		this._start();
	},
	
	_start: function()
	{
		window.setInterval(this._scroll.bind(this), 3000);
	},
	
	_scroll: function()
	{
		this.pointer++;
		this.picPointer++;
		if (this.picPointer > 3)
		{
			this.picPointer = 0;
		}
		var data = this.data[this.pointer];
		if (!data)
		{
			this.pointer = 0;
			data = this.data[this.pointer];
		}

		var li = this.elements[this.picPointer];

		if (li)
		{
			li.down('a').writeAttribute('href', '/aanbod/?id=' + data.link);
			li.down('img').writeAttribute('src', '/images/flippers/' + data.picture);
		}
	},
	
	_eoo: true
});
