jQuery(document).ready(function() {	
	var containerH = jQuery('.news-index-right');
	var blocsH = containerH.find('.news-index-right-blocs li');
	var currentH = 0;
	var timeH;
	var pause = false;
	
	var slideTo = function (index) {
		var slide = jQuery(blocsH.get(index))
		var p = slide.parent();
		p.queue('slide_fade');
		p.stop().animate({
			'opacity': 0
		}, 500, function () {
			jQuery(this).css('top', '-'+slide.position().top+'px');
			jQuery(this).animate({
				'opacity': 1
			});
		});
		currentH = index;
		p.dequeue('slide_fade');

		auto();
	};
	
	var auto = function() {
		if (!pause) {
			clearTimeout(timeH);
			timeH = setTimeout(function () {
				var index = ((currentH+1) >= blocsH.length ) ? 0 : currentH+1;
				slideTo(index);
			}, 5000);
		}
	};
	
	var start = function () {
		pause = false;
		auto();
	};
	
	var stop = function() {
		pause = true;
		clearTimeout(timeH);
	};

	containerH.hover(stop,start);

	//init mouvement
	start();
});
