$(function() {
	$('.nyroModal').nm();
	
	var bandeau = $('#bandeau');
	if (bandeau.length) {
		var ul = bandeau.find('ul'),
			lis = ul.find('li'),
			nbs = lis.length,
			nbShow = 5,
			cur = 0,
			w = lis.first().outerWidth(true),
			next = bandeau.find('.next').hide(),
			prev = bandeau.find('.prev').hide();
		if (nbs > nbShow) {
			var
				animated = false,
				anim = function(dir) {
					if (!animated) {
						animated = true;
						cur+= dir;
						if (cur < 0)
							cur = 0;
						else if (cur > nbs-nbShow)
							cur = nbs-nbShow;
						if (cur > 0)
							prev.show();
						else
							prev.hide();
						if (cur < nbs-nbShow)
							next.show();
						else
							next.hide();
						ul.animate({
							marginLeft: (-cur*w)+'px'
						}, function() {
							animated = false;
						});
					}
				};
			next.show().click(function(e) {
				e.preventDefault();
				anim(1);
			});
			prev.click(function(e) {
				e.preventDefault();
				anim(-1);
			});
		}
	}
});
