$(function() {
	if ($('#blockfocushome').length) {
		
		//shuffle
		//$('div#blockfocushome ul').shuffle();



		/* Si pas de shuffle: ordre en fx du num titre */
		$.fn.orderby = function() {
			var tmp = Array();
			var tmpbg = Array();
			this.children().each(function(){
				var poz = $(this).find('h2').text().split('.');
				$(this).find('h2').text(poz[1]);
				tmp[parseInt(poz[0])] = $(this).html();
				tmpbg[parseInt(poz[0])] = $(this).attr('style');
			});
			$.each(tmp, function(i, val) {
				var ch = ''+val+'';
				if( ch.length>10 ) {
					$('div#blockfocushome ul li:eq('+(i-1)+')').html(ch);
					$('div#blockfocushome ul li:eq('+(i-1)+')').attr('style', tmpbg[i]);
				}
			});
		}

		$('div#blockfocushome ul').orderby();
		/* Fin si pas de shuffle */



		//$.browser.msie && $.browser.version == 7
		var ie6 = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 6.0") != -1);
		var ie7 = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 7.0") != -1);
		if( $.browser.msie && $.browser.version == 6 || $('#blockfocushome ul li').length<2 )
			$('a#focus_prec, a#focus_suiv').css('display', 'none');
		
		if( !($.browser.msie && $.browser.version == 7) ) {
			$('a#focus_prec, a#focus_suiv').hover(function() {
				$(this).stop().animate({opacity: 0.6});
			}, function() {
				$(this).stop().animate({opacity: 1});
			});
		}
		
		$('div#blockfocushome ul li div.focus_texte').css('opacity', 0.8);
		
		var mrg = 0;
		var wli = $("#blockfocushome ul li").css('width').replace('px', '');

		$("#blockfocushome ul").css("width", ($('#blockfocushome ul li').length)*wli);
		var wprog = $("#blockfocushome ul").css("width");
		wprog = parseInt(wprog.replace(/px/, ''));
		var eslid = 1;
		var butee = -1;
		var mlmin = -(wprog-wli*eslid);
		var d = 1000;

		$("a#focus_prec").click(function() {
			clearInterval(loopy);
			mrg += wli*eslid;
			if( butee>0 ) butee=0;
			
			if( mrg>=0 ){ butee--; mrg = 0; }
			
			if( butee>=-1 ){
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d);
			}
			return false;
		});

		$("a#focus_suiv").click(function() {
			clearInterval(loopy);
			mrg -= wli*eslid;
			if( butee<0 ) butee=0;
			if( mrg <= mlmin ){ butee++; mrg = mlmin; }
			if( butee>1 ){
				butee=-1;
				mrg = 0;
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d*($('#blockfocushome ul li').length));
			}
			else {
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d);
			}

			return false;
		});


		/* ça bouge tout seul! */
		function auto_rotation() {
			mrg -= wli*eslid;
			if( butee<0 ) butee=0;
			if( mrg <= mlmin ){ butee++; mrg = mlmin; }
			if( butee>1 ){
				butee=-1;
				mrg = 0;
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d*($('#blockfocushome ul li').length));
			}
			else {
				$("#blockfocushome ul").animate({marginLeft: mrg+"px"}, d);
			}
		}
		loopy = window.setInterval(auto_rotation, 12000);
		/* fin ça bouge tout seul */


	}

});

$

