
sofScroller = {
	itemW: 134,
	itemNr: 5,
	count: 0,
	current: -1,
	moveDuration: 300,
	movePause: 3500,
	timer: null,


	init: function() {
		var self = this;
		$('.specOfferItem').each( function() {
			$(this).attr('id', 'sof_scroll_item_'+self.count)
					 .css('position', 'absolute')
					 .css('left', self.count*self.itemW);
			self.count++;
		});
		$('.scrollWrapper').width(this.itemW*this.itemNr-1); // cut off right border
		if (self.count > self.itemNr)
			self.scroll();
	},

	scroll: function() {
		var self=this;
		// move current to the end of the list
		if (this.current != -1)
			$('#sof_scroll_item_'+this.current).css('left', (this.count-1)*this.itemW);
		$('.specOfferItem').each( function() {
			$(this).animate(
				{ left: '-='+self.itemW },
				self.moveDuration,
				function() {
					if ($(this).attr('id') == 'sof_scroll_item_0') {
						if (++self.current >= self.count)
							self.current = 0;
						self.timer = setTimeout('sofScroller.scroll()', self.movePause);
					}
				}
			)
		});
	}

};

$(document).ready(function() { sofScroller.init(); });
