var bandeau = function(src, width, target, start_pos, auto)
{
	this.load = function(src)
	{
		this.src = src;
		$(this.target).empty();
		var max = (src.length < this.size) ? src.length : this.size + 2; // nbr d'elements a rajouter
		var buttons = !(this.width == 100 && src.length < 8); // affichage navigation
		for (i=0; i<max; i++)
			$(src[(this.pos + i + src.length) % src.length]).appendTo(this.target);
		// on cache les boutons et on remet le bandeau à 0px
		document.getElementById('prev').style.display = (buttons) ? 'block' : 'none';
		document.getElementById('next').style.display = (buttons) ? 'block' : 'none';
		this.target.css({'left': (buttons ? '-'+this.width : '0')+'px'});
		this.automove(-1);
	}

	this.move = function(direction)
	{
		if (!direction || $('#'+self.target.attr('id')+':animated').length)
			return;

		self.target.animate(
			{'left': (parseInt(self.target.css('left')) + direction * self.width) + 'px'},
			1000,
			'',
			function()
			{
				$('div:' + (direction < 0 ? 'first' : 'last'), self.target).remove();
				self.pos = (self.pos + self.src.length - direction) % self.src.length;
				if (direction > 0)
					$(self.src[self.pos]).prependTo(self.target);
				else
					$(self.src[(self.pos + self.size + 1 + self.src.length) % self.src.length]).appendTo(self.target);
				self.target.css({'left': (parseInt(self.target.css('left')) - direction * self.width) + 'px'});
			}
		);
		return false;
	}

	this.automove = function(direction)
	{
		if (this.auto)
			setTimeout(function() { self.move(direction); self.automove(direction); }, 3000); 
	}
	
	this.auto = auto;
	this.target = target;
	this.pos = start_pos;
	this.width = width;
	this.size = parseInt(parseInt(target.parent().css('width')) / width);

	target.css({'width': (this.size + 2) * this.width + 'px'});
	var self = this;
	if (src) this.load(src);
};
