	$(document).ready(function(){
		initContenu();
	});
	
	var initContenu = function() {
		$.getJSON(racine+"pages/ajax/nos-realisations.php", { "_id":1 }, 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", "slideCarouselRealisation").appendTo("#contenu-small");
				$("<ul>").attr("id", "ulSlideCarousel").appendTo("#slideCarouselRealisation");
				$.each(data.articles, function(i, item){
					$("<li>").attr("id", "liSlideCarousel_"+item.art_id).appendTo("#ulSlideCarousel");
					$("<div>").attr("id", "divSlideCarousel_"+item.art_id).attr("class", "float").appendTo("#liSlideCarousel_"+item.art_id);
					$("<div>").attr("id", "ImgSlideCarousel_"+item.art_id).attr("style", "padding-top:10px;").appendTo("#divSlideCarousel_"+item.art_id);
					if(item.count_artt_upload != 0) {
						var imageThumb	= item.artt_upload[0].aupt_fichier.replace("-visuel-visuel", "-visuel-vign-370_260");
						$("<img>").attr("src", imageThumb).attr("border", 0).attr("alt", "").attr("id", "imgThumb_"+item.art_id).appendTo("#ImgSlideCarousel_"+item.art_id);
					} else {
						$("<img>").attr("src", racineMedia+"o.gif").attr("border", 0).attr("alt", "").attr("width", 370).attr("height", 260).appendTo("#ImgSlideCarousel_"+item.art_id);
					}
					
					$("<div>").attr("id", "divRealisationDroite_"+item.art_id).attr("class", "realisation-droite").appendTo("#liSlideCarousel_"+item.art_id);
					$("<h3>").attr("id", "h3RealisationDroite_"+item.art_id).appendTo("#divRealisationDroite_"+item.art_id);
					$("<span>").html(item.artt_titre).appendTo("#h3RealisationDroite_"+item.art_id);
					
					$("<div>").attr("id", "divVignette_"+item.art_id).attr("class", "vignette-index").appendTo("#divRealisationDroite_"+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("#divVignette_"+item.art_id);
					} else {
						$("<img>").attr("src", racineMedia+"o.gif").attr("border", 0).attr("alt", "").attr("width", 179).attr("height", 125).appendTo("#divVignette_"+item.art_id);
					}
					
					$("<div>").attr("id", "divContenu_"+item.art_id).attr("class", "vignette-index").appendTo("#divRealisationDroite_"+item.art_id);
					$("<span>").html(item.artt_adresse).appendTo("#divContenu_"+item.art_id); $("<br />").appendTo("#divContenu_"+item.art_id);
					$("<span>").html(item.artt_codepostal+" "+item.artt_ville).appendTo("#divContenu_"+item.art_id); $("<br />").appendTo("#divContenu_"+item.art_id);
					if(item.artt_livraison != "") {
						$("<span>").html("Livraison : "+item.artt_livraison).appendTo("#divContenu_"+item.art_id); $("<br />").appendTo("#divContenu_"+item.art_id);
					}
					if(item.art_nbr_logements != "" && item.art_nbr_logements != "0") {
						$("<span>").html("Nombre de logement(s) : "+item.art_nbr_logements+" logement(s)").appendTo("#divContenu_"+item.art_id); $("<br />").appendTo("#divContenu_"+item.art_id);
					}
					if(item.artt_redirection != "" && item.artt_redirection != "http://") {
						$("<span>").html("Le situer avec&nbsp;").appendTo("#divContenu_"+item.art_id);
						$("<a>").attr("href", item.artt_redirection).attr("target", "_blank").attr("class", "lien-clair").html("Google map").appendTo("#divContenu_"+item.art_id);
					}
					
					$("<div>").attr("class", "spacer").appendTo("#divRealisationDroite_"+item.art_id);
					
					$.each(item.artt_upload, function(j, jtem){
						if(j < 4) {
							var imageThumb	= jtem.aupt_fichier.replace("-visuel-visuel", "-visuel-vign-102_72");
							if(j == 0) {
								var opacity			= "opacity: 1.0";
								var classOpacity	= "";
							} else {
								var opacity			= "opacity:0.5; filter:alpha(opacity=50);";
								var classOpacity	= " vignette_opacity";
							}
							$("<div>").attr("class", "vignette").attr("id", "divThumbVignette_"+jtem.aup_id).appendTo("#divRealisationDroite_"+item.art_id);
							$("<a>").attr("href", "javascript:;").attr("class", "fade_image").attr("rel", i+","+item.art_id+","+jtem.aup_id).attr("id", "aVignette_"+jtem.aup_id).appendTo("#divThumbVignette_"+jtem.aup_id);
							$("<img>").attr("src", imageThumb).attr("border", 0).attr("alt", "").attr("class", "image_vignette_"+item.art_id+""+classOpacity).attr("id", "imgVignette_"+jtem.aup_id).attr("style", opacity).appendTo("#aVignette_"+jtem.aup_id);
						}
					});
					
					$("<div>").attr("class", "spacer").appendTo("#divRealisationDroite_"+item.art_id);
					
					/*$(".vignette_opacity").hover(function() {
						$(this).stop().animate({ opacity: 1.0 }, 500);
					}, function() {
						$(this).stop().animate({ opacity: 0.5 }, 500);
					});*/
				});
				if(data.count_articles > 1) {
					$("<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	= $('#slideCarouselRealisation li').outerWidth(true);
				var widthSlide	= data.count_articles * item_width;
				$("#ulSlideCarousel").css("width", widthSlide);
				
				sIFR.replace(sogerim2, {
					css: [ '.sIFR-root { background-color:transparent; color: #e8630a; font-size:34px; }' ],
					fitExactly      : true,
					forceClear      : true,
					forceSingleLine : true,
					selector        : 'h3',
					transparent     : true
				});
				
				$(".fade_image").click(function(){
					var element		= $(this).attr("rel").split(",");
					var boucle		= element[0];
					var idCarousel	= element[1];
					var id			= element[2];
					var dataUpload	= data.articles[boucle].artt_upload;
					var imageThumb	= "";
					
					if($("#imgVignette_"+id).css("opacity") == 0.5) {
						$.each(dataUpload, function(i, item){
							if(item.aup_id == id) {
								imageThumb	= item.aupt_fichier.replace("-visuel-visuel", "-visuel-vign-370_260");
							}
						});
						$("#ImgSlideCarousel_"+idCarousel).fadeOut("normal", function() {
							$(".image_vignette_"+idCarousel).removeClass("vignette_opacity").addClass("vignette_opacity").animate({ opacity: 0.5 }, 500);
							$("#imgVignette_"+id).removeClass("vignette_opacity").animate({ opacity: 1.0 }, 500);
							$("#imgThumb_"+idCarousel).attr("src", imageThumb);
							$("#ImgSlideCarousel_"+idCarousel).fadeIn();
						});
					}
				});
				
				$("#slide_gauche").click(function(){
					var item_width		= $('#slideCarouselRealisation li').outerWidth(true);   
					var left_value		= item_width * (-1);
					var left_indent		= parseInt($('#slideCarouselRealisation ul').css('left')) + item_width;
					var widthSlide		= data.count_articles * item_width;
					var position_left	= Math.abs(left_indent - (1 * item_width));
				
					$('#slideCarouselRealisation ul').animate({'left' : left_indent}, 200, function () {
						$('#slideCarouselRealisation 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		= $('#slideCarouselRealisation li').outerWidth(true);   
					var left_value		= item_width * (-1);
					var left_indent		= parseInt($('#slideCarouselRealisation ul').css('left')) - item_width;
					var widthSlide		= data.count_articles * item_width;
					var position_left	= Math.abs(left_indent - (1 * item_width));
					
					$('#slideCarouselRealisation ul').animate({'left' : left_indent}, 200, function () {
						$('#slideCarouselRealisation 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();
			}
		});

		/*
		$("#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);
					$("<a>").attr("href", racine+"nos-programmes/"+rubrique+"/"+item.artt_titre_url+".html").attr("class", "lien-uppercase").html(item.artt_titre).appendTo("#p2-index-bloc-"+item.art_id);
					$("<span>").html(item.artt_adresse).appendTo("#liSlideCarousel_"+item.art_id); $("<br />").appendTo("#liSlideCarousel_"+item.art_id);
					$("<span>").html(item.artt_codepostal+" "+item.artt_ville).appendTo("#liSlideCarousel_"+item.art_id); $("<br />").appendTo("#liSlideCarousel_"+item.art_id);
					$("<span>").html("Livraison : "+item.artt_livraison).appendTo("#liSlideCarousel_"+item.art_id); $("<br />").appendTo("#liSlideCarousel_"+item.art_id);
					$("<span>").html("Offre : "+item.artt_offre).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();
			}

		});*/
	}

