$(document).ready(function()
{
	$(".listederniersajouts").listederniersajouts();
	$(".select").each(function()
	{
		$(this).selects();
	});
});


(function($)
{
	$.fn.listederniersajouts=function(options)
	{
		var settings={currentId:0,playAuto:true,intervalPlay:4000,intervalEffect:700};
		var nbItems;
		var currentId;
		var rotateAuto;
		var isPlaying=false;
		var $this=$(this);
		if(arguments[0])jQuery.extend(settings,options);
		function init()
		{
			if(settings.intervalPlay<settings.intervalEffect)settings.intervalEffect=settings.intervalPlay;
			nbItems=$this.find("li").size();
			currentId=settings.currentId;
			$this.find("li:not(:eq("+currentId+")) div").hide();
			$this.find("li:eq("+currentId+") a.handler").addClass("hover");
			$this.find("li:eq("+currentId+") span.classi").addClass("hover");
			$this.find("li a.handler").each(function(index)
			{
				$(this).bind("mouseover focus",function()
				{
					clearInterval(rotateAuto);switchNews(index);
					return false;
				});
			});
			$this.find(".pause").click(function()
			{
				pause();
			})
		}
		function switchNews(id)
		{
			if(id!==currentId)
			{
				$this.find("li div").stop(false,true);
				$this.find("li:eq("+currentId+") div").fadeOut("slow");
				$this.find("li:eq("+currentId+") a.handler").removeClass("hover");
				$this.find("li:eq("+currentId+") span.classi").removeClass("hover");
				currentId=id;
				$this.find("li:eq("+currentId+") div").fadeIn("slow");
				$this.find("li:eq("+currentId+") a.handler").addClass("hover");
				$this.find("li:eq("+currentId+") span.classi").addClass("hover");
			}
		}
		function rotateNews()
		{
			if(currentId==nbItems-1)switchNews(0);else switchNews(currentId+1);
		}
		function play()
		{
			rotateAuto=setInterval(rotateNews,settings.intervalPlay);
			isPlaying=true;$this.hover(function(){clearInterval(rotateAuto);},function(){if(isPlaying)rotateAuto=setInterval(rotateNews,settings.intervalPlay);});
		}
		function pause()
		{
			clearInterval(rotateAuto);isPlaying=false;
		}
		if(settings.playAuto===true)
		{
			play();
		}
		init();return $(this);
	};
})(jQuery);

