var animating = false;
jQuery.fn.scrollBlock = function(settings) {
	settings = jQuery.extend({
		blockWidth: 500,
		blockVisibleWidth: 200,
		scrollSpeed: "normal",
		scrollStep: 150
	}, settings);
	return this.each(function(i){
		//$(".news_items",this).css("Width",settings.blockWidth+"px");
		$(".news_items", this).css("overflow","hidden");
		$(".news_items", this).css("position","relative");
		$(".container", this).css("left","0px");
		$(".container", this).css("top","0px");
		$(".container", this).css("position","relative");
		$(".container").css('width', settings.blockWidth+'px');

		$("a.next",this).click(function() {
			if (animating == false) {
				thisParent = $(this).parent().parent().parent();

				// On vérifie si l'on est pas en bas
				if ((settings.blockWidth + parseInt($(".container",thisParent).css("left")) - settings.blockVisibleWidth) == 0)
					return false;

				animating = true;
				// On calcul la position du scroll
				animate = parseInt($(".container",thisParent).css("left")) - settings.scrollStep;
				if (-animate > settings.blockWidth - settings.blockVisibleWidth)
					animate = -(settings.blockWidth - settings.blockVisibleWidth);

				jQuery(".container",thisParent).animate({left: animate}, "normal", function() {
					jQuery(this).css("left",animate);
					animating = false;
				});
			}
			return false;
		});

		$("a.prev",this).click(function() {
			if (animating == false) {
				thisParent = $(this).parent().parent().parent();
				
				// On vérifie si l'on est pas en haut
				if (parseInt($(".container",thisParent).css("left")) == 0)
					return false;

				animating = true;
				// On calcul la position du scroll
				animate = parseInt($(".container",thisParent).css("left")) + settings.scrollStep;
				if (animate > 0)
					animate = 0;

				jQuery(".container",thisParent).animate({left: animate}, "normal", function() {
					jQuery(this).css("left",animate);
					animating = false;
				});
			}
			return false;
		});
	});
};