	$(document).ready(function(){
		initContenu();
		
		$("#select_regions").change(function() {
			var selectRegion	= $("#select_regions").val();
			$.getJSON(racine+"pages/ajax/nos-partenaires.php", { "_region":selectRegion }, function(data){ conteneurContenuCarousel(data); });
		});
	});
	
	var initContenu = function() {
		$.getJSON(racine+"pages/ajax/nos-partenaires.php", { "_region":id }, function(data){ conteneurContenuCarousel(data); });
	}
	
	var conteneurContenuCarousel = function(data) {
		$("#contenu-small").fadeOut("normal", function() {
			$("#contenu-small").empty();
			if(data.count_articles != 0) {
				$("<div>").attr("style", "width:15px; height:1px; float:left;").attr("id", "div_fleche_gauche").appendTo("#contenu-small");
				$("<div>").attr("class", "fleche_cpe2").attr("id", "fleche_gauche").appendTo("#div_fleche_gauche").hide();
				$("<a>").attr("href", "javascript:;").attr("id", "slide_gauche").appendTo("#fleche_gauche");
				$("<img>").attr("src", racineMedia+"fleche-gauche.png").attr("border", 0).attr("alt", "Gauche").appendTo("#slide_gauche");

				$("<div>").attr("id", "slideCarouselIndex").appendTo("#contenu-small");
				$("<ul>").attr("id", "ulSlideCarousel").appendTo("#slideCarouselIndex");
				$.each(data.articles, function(i, item){
					$("<li>").attr("id", "liSlideCarousel_"+item.art_id).appendTo("#ulSlideCarousel");
					$("<p>").attr("id", "p1-index-bloc-"+item.art_id).appendTo("#liSlideCarousel_"+item.art_id);
					if(item.artt_visuel != "") {
						var imageThumb	= item.artt_visuel.replace("-visuel", "-vign-179_125");
						$("<img>").attr("src", imageThumb).attr("border", 0).attr("alt", item.artt_visuel_alt).appendTo("#p1-index-bloc-"+item.art_id);
					} else {
						$("<img>").attr("src", racineMedia+"o.gif").attr("border", 0).attr("alt", "").attr("width", 179).attr("height", 125).appendTo("#p1-index-bloc-"+item.art_id);
					}
					$("<p>").attr("id", "p2-index-bloc-"+item.art_id).appendTo("#liSlideCarousel_"+item.art_id);
					if(item.artt_redirection != "" && item.artt_redirection != "http://") {
						$("<a>").attr("href", "http://"+item.artt_redirection.replace("http://", "")).attr("class", "lien-uppercase").attr("target", "_blank").html(item.artt_titre).appendTo("#p2-index-bloc-"+item.art_id);
					} else {
						$("<span>").attr("style", "color: #e8630a; text-decoration: none; font-weight:bold; text-transform:uppercase;").html(item.artt_titre).appendTo("#p2-index-bloc-"+item.art_id);
					}
					$("<span>").html(item.artt_texte).appendTo("#liSlideCarousel_"+item.art_id); $("<br />").appendTo("#liSlideCarousel_"+item.art_id);
				});
				
				if(data.count_articles > 4) {
					$("<div>").attr("style", "width:15px; height:1px; float:left;").attr("id", "div_fleche_droite").appendTo("#contenu-small");
					$("<div>").attr("class", "fleche_cpe2").attr("id", "fleche_droite").appendTo("#div_fleche_droite");
					$("<a>").attr("href", "javascript:;").attr("id", "slide_droite").appendTo("#fleche_droite");
					$("<img>").attr("src", racineMedia+"fleche-droite.png").attr("border", 0).attr("alt", "Gauche").appendTo("#slide_droite");		
				}

				$("#contenu-small").fadeIn();
				
				var item_width	= $('#slideCarouselIndex li').outerWidth(true);
				var widthSlide	= data.count_articles * item_width;
				$("#ulSlideCarousel").css("width", widthSlide);
				
				$("#slide_gauche").click(function(){
					var item_width		= $('#slideCarouselIndex li').outerWidth(true);   
					var left_value		= item_width * (-1);
					var left_indent		= parseInt($('#slideCarouselIndex ul').css('left')) + item_width;
					var widthSlide		= data.count_articles * item_width;
					var position_left	= Math.abs(left_indent - (4 * item_width));
				
					$('#slideCarouselIndex ul').animate({'left' : left_indent}, 200, function () {
						$('#slideCarouselIndex ul').css({'left' : left_indent});
						if(left_indent == 0) { $("#fleche_gauche").fadeOut(); }
						if(position_left < widthSlide && $("#fleche_droite").not(":visible")) $("#fleche_droite").fadeIn();
					});
				});
				
				$("#slide_droite").click(function(){
					var item_width		= $('#slideCarouselIndex li').outerWidth(true);   
					var left_value		= item_width * (-1);
					var left_indent		= parseInt($('#slideCarouselIndex ul').css('left')) - item_width;
					var widthSlide		= data.count_articles * item_width;
					var position_left	= Math.abs(left_indent - (4 * item_width));
					
					$('#slideCarouselIndex ul').animate({'left' : left_indent}, 200, function () {
						$('#slideCarouselIndex ul').css({'left' : left_indent});
						if($("#fleche_gauche").not(":visible")) $("#fleche_gauche").fadeIn();
						if(position_left >= widthSlide && $("#fleche_droite").is(":visible")) $("#fleche_droite").fadeOut();
					});
				});
			} else {
				$("#contenu-small").fadeIn();
			}

		});
	}

