// JavaScript Document
var animMiniature = false;
var nbMiniature = 0;
var slideMinWidth = 0;
var totalMinlWidth = 0;

var animMiniaturePopup = false;
var nbMiniaturePopup = 0;
var slideMinWidthPopup = 0;
var totalMinlWidthPopup = 0;


$(document).ready(function(){
	

	/* ****BLOC MINIATURE*******************************************************/
	nbMiniature 	= $('.thumbs .lien_miniature').length;
	slideMinWidth = parseInt($('.thumbs .lien_miniature').css('width'))+ parseInt($('.thumbs .lien_miniature').css('marginLeft'));
	$('.thumbs .slideInner').css('width',nbMiniature*slideMinWidth+'px');
	//if (typeof console != 'undefined') console.log(nbMiniature+"*"+slideMinWidth);
	totalMinlWidth	= parseInt($('.thumbs .slideInner').css('width'));
	
	//if (typeof console != 'undefined') console.log($('.liste_thumb .thumb_prec'));
	$('.liste_thumb .thumb_prec').live('click', function (){ animThumb('-1'); return false;});
	$('.liste_thumb .thumb_suiv').live('click', function (){ animThumb('1'); return false});
		
	
	$(".slideInner .lien_miniature, .visuel_toolbox .zoom , .visuel_gd , .picto_photo , .picto_schema ").bind('click', function(){
	
	
	
	var ref_photo = $(this).attr('ref_photo');
	var ref_schema = $(this).attr('ref_schema');	
		var is_log = 0;

		$.ajax({
			type:"get",
			async:false,
			url: URL_SITE_HTTP+"ajax/is_log.xhr.php",
			success: function(data){
				is_log = data;
			}
		});
		
		var localTitre = $('h2.fn').text();
		if (localTitre.length>55){
			localTitre = localTitre.substr(0,55)+' ...';
		}
		$.messageService({
			title: 			'<strong style="font-size:14px;">'+localTitre+'</strong> <span></span>',
			print:			'visuel_produit.print.php?idsp='+$('#idsp').val(),
			download:		((is_log==0)?null:'#'),
			type:			'url',
			source:			'popup_ajax/visuel_produit.popup.php?ref_schema='+ ref_schema +'&ref_photo='+ ref_photo +'&idsp='+$('#idsp').val(),
			width:			850,
			onLoad:			function(){ },
			onLoadComplete:	function(){ 
				$('.messageService_conteneur_entete_print').removeClass('blank');
				$('.messageService_conteneur_entete_download').removeClass('blank');
				

				$('.messageService_conteneur_entete_print').click(function (){
					var urlImg = $('.jqzoom img').attr('jqimg');
					
					var mareg=new RegExp("/photos-produits/900px/", "g");
					urlImg= urlImg.replace(mareg,'');
					
					var mareg=new RegExp("/schemas-produits/900px/", "g");
					urlImg= urlImg.replace(mareg,'');
					
					$('this').attr('href', 'visuel_produit.print.php?idsp='+$('#idsp').val()+'&img='+urlImg) ;
					//$('.jqzoom img').attr('jqimg').printElement({printMode:'popup'});
					window.open(URL_SITE_HTTP+'visuel_produit.print.php?idsp='+$('#idsp').val()+'&img='+urlImg);
					return false;
				});

				$('.messageService_conteneur_entete_download').click(function (){
					var urlImg = $('.jqzoom img').attr('jqimg');
					var mareg=new RegExp("/photos-produits/900px/", "g");
					urlImg= urlImg.replace(mareg,'');

					location.href = URL_SITE_HTTP+'download.php?f='+urlImg;
					return false;
				});

				$(".jqzoom").jqueryzoom({
					xzoom: 350,		//zooming div default width(default width value is 200)
					yzoom: 350,		//zooming div default width(default height value is 200)
					offset: 0,		//zooming div default offset(default offset value is 10)
					position: "right",  //zooming div position(default position value is "right")
					preload: 1    , // preload of images :1 by default
					lens:1  ,// lens over the image   1 by default
					alwaysOn:true
				});
				//messageService_conteneur_entete_print
				//messageService_conteneur_entete_download
				
				
				$(".liste_visuels .lien_miniature").click(function() {
					
					
					//Update code article title
					$(".messageService_conteneur_entete_titre span").html(' - CODE ARTICLE '+$(this).find('img').attr('title'));
					
					// Récupération de la photo moyenne
				    var photomed = $(this).find('img').attr('rel');			
												
					//	Récupération de la photo de grande taille
					var photoGD = $(this).attr('rel');	
					
					// Unbind the zoom:
    				$(".jqzoom").unbind(".jqzoom");
					$(".jqPreload0").remove();
					
					//$(".jqzoom").fadeOut('slow');
					
					//Ajout de la grande photo
					$(".jqzoom img").attr('src', photomed);
					$(".jqzoom img").attr('jqimg', photoGD);
					
					var theImage = new Image();
					
					$(".jqzoom img").load(function() {
						theImage.src = photomed;
						
						$(".jqzoom").width(theImage.width);
						$(".jqzoom").height(theImage.height);
					});
					
					
					
					
					//$(".jqzoom img").width(theImage.width);
					//$(".jqzoom img").height(theImage.height);
					
					
					
					//$(".jqzoom img").css('width', $(".jqzoom img").width());
					//$(".jqzoom img").css('height', $(".jqzoom img").height());
					
					//console.log("Taille de l'image: "+$(".jqzoom img").width());
					//$(".jqzoom").fadeIn('slow');
					
					$(".jqzoom").jqueryzoom({
											xzoom: 350,		
											yzoom: 350,		
											offset: 0,		
											position: "right",
											preload: 1    ,
											lens:1  ,
											alwaysOn:true
										});
					
					
					return false;
				});
				
				slideMinHeightPopup = parseInt($('.liste_visuels .lien_miniature').css('height'))+2+parseInt($('.liste_visuels .lien_miniature').css('marginTop'));
				$('.liste_visuels .slideContenu').css('height',nbMiniature*slideMinHeightPopup+'px');
				totalMinHeigtPopup	= parseInt($('.liste_visuels .slideContenu').css('height'));

				$('.liste_visuels .lien_prec').live('click', function (){ animThumbPopup('-1'); return false;});

				$('.liste_visuels .lien_suiv').live('click', function (){ animThumbPopup('1'); return false;});
				
			},
			onClose:		function(){ },
			onCloseComplete:function(){ }
		});
		
		
		return false;								   
	});
	
	//Bloc ma selection
	$(".add_selection").live('click', function (){
		
		$.ajax({
			type:"get",
			url: URL_SITE_HTTP+"ajax/update_maselection.xhr.php",
			data:"action=add&idsp="+$('#idsp').val(),
			success: function(data){
				$('.add_selection').replaceWith('<a href="#" class="del_selection"><span></span>Supprimer de ma sélection</a>');

				$.messageService({
					title: 			'Ma sélection',
					type:			'html',
					width:			500,
					html: 			'<p class="texte">Cet article a bien été ajouté à votre sélection<br/>Vous pouvez maintenant le retrouver rapidement dans la rubrique <strong>Ma sélection</strong>.</p><a href="#" class="btn_noir_100 messageService_close" style="margin:0 auto">OK</a>'
					
				});
			}
		});
		return false;									
	});
	
	$(".del_selection").live('click', function (){
		
		$.ajax({
			type:"get",
			url: URL_SITE_HTTP+"ajax/update_maselection.xhr.php",
			data:"action=del&idsp="+$('#idsp').val(),
			success: function(data){
				$('.del_selection').replaceWith('<a href="#" class="add_selection"><span></span>Ajouter à ma sélection</a>');

				$.messageService({
					title: 			'Ma sélection',
					type:			'html',
					width:			400,
					html: 			'<p class="texte" style="text-align:center">Cet article a bien été supprimé de votre sélection.</p><a href="#" class="btn_noir_100 messageService_close" style="margin:0 auto">OK</a>'
					
				});
			}
		});
		return false;									
	});
	
	

	$(".help_choice").live('click', function (){
		$.messageService({
			title: 			'Caractéristique techniques',
			type:			'html',
			source:			'popup_ajax/visuel_produit.popup.php?idsp='+$('#idsp').val(),
			width:			650,
			html: 			$('.data_help_choice').html(),
			onLoadComplete: function(){
								$(".liste_carac_tech tr:even").css("background-color", "#e7e6e6");
								$(".liste_carac_tech tr:odd").css("background-color", "#FFF");
							}
		});
		return false;
	});

	
	
	
	//$(".tabs").tabs();
	
	
	//gestion des onglets
	//$(".tabs .contenu_onglet").css("display", "none");
	//$(".tabs .contenu_onglet:first").css("display", "block");
	
	
	$(".tabs ul li a").click(function (){
		var id = $(this).attr('href');
		id = id.substring(1);
		$(".tabs .contenu_onglet").css("display", "none");
		$('#'+id).css("display", "block");
		$(".tabs ul li").removeClass("selected");
		$(this).parent(	).addClass("selected");
		
		return false;
	});
	
	
	$(".produit_equivalent").parent().css("display", "none");
	$(".lien_produit_equivalent").click(function (){
		var id = $(this).attr('href');
		id = id.substring(1);
		
		if ($('#'+id).css("display")=='' || $('#'+id).css("display")=='table-row'){
			$('#'+id).hide();
			$(this).find('span').css('background-position','-455px -573px');
		}else{
			$('#'+id).show();
			$(this).find('span').css('background-position','-455px -583px');
		}
		return false;
	});
	
	$(".lien_produit_complementaire").click(function (){
		var id = $(this).attr('href');
		id = id.substring(1);
		
		if ($('#'+id).css("display")=='' || $('#'+id).css("display")=='table-row'){
			$('#'+id).hide();
			$(this).html('<span></span>voir<br/>articles<br/>compl.');
			$(this).find('span').css('background-position','-445px -573px');
		}else{
			$('#'+id).show();
			$(this).html('<span></span><br/>Fermer<br/>');
			$(this).find('span').css('background-position','-445px -583px');
		}
		return false;
	});
	
	
	
	$(".produit_complementaire").parent().css("display", "none");
	
	
	$(".listing_article tr:visible").filter(":even").css("background-color", "#e7e6e6");
	$(".listing_article tr:visible").filter(":odd").css("background-color", "#FFF");
	
	
	$(".liste_produit_equivalent tr:odd").css("background-color", "#ffeab6");
	$(".liste_produit_equivalent tr:even").css("background-color", "#FFF");
	
	$(".produit_complementaire tr:even").css("background-color", "#999999");
	$(".produit_complementaire tr:odd").css("background-color", "#cccccc");

	
	$(".listing_article tr.coul_recherche").css("background-color", "#e7e600");
	
	/* ****BLOC VARIANTES*******************************************************/
	//Bloc produit variante et sa pagination
	$("#variantes .variante_produit:nth-child(6)").nextAll().css("display", "none");
	$("#variantes .variante_produit:nth-child(3n)").css('border-right', '0');

	//On remet la pagination effaçé par la ligne précédente
	$("#variantes .pagination").css('display', 'block');
	
	
	//Les pages
	$("#variantes .pagination").delegate(".other_page", "click", function(){
		
		$("#variantes .sep_dotted").remove();
		
		//Récupération de la page a afficher
		var nextPage = parseInt($(this).html());
		var curPage = parseInt($(".pagination span.current").html());

		//On masque tout
		$("#variantes .variante_produit").css("display", "none");
		
		for(var i=((nextPage-1)*6+1); i<=(6*nextPage);i++){
			$("#variantes .variante_produit:nth-child("+i+")").css("display", "block");
		}
		$("#variantes .variante_produit:nth-child("+6*nextPage+")").nextAll().css("display", "none");
		//On remet la pagination effaçé par la ligne précédente
		$("#variantes .pagination").css('display', 'block');
		
		$(".pagination span.current").each(function(){
			$(this).replaceWith("<a href='#' class=\"other_page\">"+$(this).text()+"</a>");
		});

		$(this).replaceWith("<span class=\"current\">"+$(this).text()+"</span>");
		
		creerSep("variantes", "variante_produit");
		updateBtnSuivPrec(curPage, nextPage, "variantes");
		updateposFond();
		
		return false;
	});
	
	//Btn suivants
	$("#variantes .pagination").delegate(".btn_suivant", "click", function(){
		
		$("#variantes .sep_dotted").remove();
		
		var curPage = parseInt($("#variantes span.current").html());
		var nextPage = parseInt(curPage)+1;
		
		var last_span = parseInt($("#variantes .pagination span.current:last").html());
		var last_a = parseInt($("#variantes .pagination a.other_page:last").html());
		
		
		if((last_span<=last_a &&  nextPage>=last_span)||(last_span<last_a &&  nextPage<=last_a)){
			//On masque tout
			$("#variantes .variante_produit").css("display", "none");
			
			
			for(var i=((nextPage-1)*6+1); i<=(6*nextPage);i++){
				$("#variantes .variante_produit:nth-child("+i+")").css("display", "block");
			}
			$("#variantes .variante_produit:nth-child("+6*nextPage+")").nextAll().css("display", "none");
			//On remet la pagination effaçé par la ligne précédente
			$("#variantes .pagination").css('display', 'block');
			
			$("#variantes .pagination span.current").each(function(){
				$(this).replaceWith("<a href='#' class=\"other_page\">"+$(this).text()+"</a>");
			});
			
	
			$("#variantes .pagination .other_page").eq(nextPage-1).each(function(){
				$(this).replaceWith("<span class=\"current\">"+$(this).text()+"</span>");
			});
			
			creerSep("variantes", "variante_produit");
			updateBtnSuivPrec(curPage, nextPage, "variantes");
			updateposFond();
		}
		return false;
	});

	
	//Btn precedent
	$("#variantes .pagination").delegate(".btn_precedent", "click", function(){

		$("#variantes .sep_dotted").remove();
		
		var curPage = parseInt($("#variantes span.current").html());
		if(curPage>1){
			var nextPage = parseInt(curPage)-1;
			//On masque tout
			$("#variantes .variante_produit").css("display", "none");
			
			
			for(var i=((nextPage-1)*6+1); i<=(6*nextPage);i++){
				$("#variantes .variante_produit:nth-child("+i+")").css("display", "block");
			}
			$("#variantes .variante_produit:nth-child("+6*nextPage+")").nextAll().css("display", "none");
			//On remet la pagination effaçé par la ligne précédente
			$("#variantes .pagination").css('display', 'block');
			
			$("#variantes .pagination span.current").each(function(){
				$(this).replaceWith("<a href='#' class=\"other_page\">"+$(this).text()+"</a>");
			});
			
	
			$("#variantes .pagination .other_page").eq(nextPage-1).each(function(){
				$(this).replaceWith("<span class=\"current\">"+$(this).text()+"</span>");
			});
			
			creerSep("variantes", "variante_produit");
			updateBtnSuivPrec(curPage, nextPage, "variantes");
			updateposFond();
		}
		return false;
	});
	
	
	
	//A cause de la methos nextAll, les ligne de démarquations disparaisse en même temps que les variante, 
	//On les créé donc à la volée
	creerSep("variantes", "variante_produit");
	
	
	
	
	
	
	/* ****BLOC VARIANTES*******************************************************/
	//Bloc produit variante et sa pagination
	$("#toute_la_gamme .gamme_produit:nth-child(6)").nextAll().css("display", "none");
	$("#toute_la_gamme .gamme_produit:nth-child(3n)").css('border-right', '0');
	//On remet la pagination effaçé par la ligne précédente
	$("#toute_la_gamme .pagination").css('display', 'block');
	
	
	
	//Les pages
	$("#toute_la_gamme .pagination").delegate(".other_page", "click", function(){
		
		$("#toute_la_gamme .sep_dotted").remove();
		
		//Récupération de la page a afficher
		var nextPage = parseInt($(this).html());
		var curPage = parseInt($(".pagination span.current").html());

		//On masque tout
		$("#toute_la_gamme .gamme_produit").css("display", "none");
		
		for(var i=((nextPage-1)*6+1); i<=(6*nextPage);i++){
			$("#toute_la_gamme .gamme_produit:nth-child("+i+")").css("display", "block");
		}
		$("#toute_la_gamme .gamme_produit:nth-child("+6*nextPage+")").nextAll().css("display", "none");
		//On remet la pagination effaçé par la ligne précédente
		$("#toute_la_gamme .pagination").css('display', 'block');
		
		$(".pagination span.current").each(function(){
			$(this).replaceWith("<a href='#' class=\"other_page\">"+$(this).text()+"</a>");
		});

		$(this).replaceWith("<span class=\"current\">"+$(this).text()+"</span>");
		
		creerSep("toute_la_gamme", "gamme_produit");
		updateBtnSuivPrec(curPage, nextPage, "toute_la_gamme");
		updateposFond();
		
		return false;
	});
	
	//Btn suivants
	$("#toute_la_gamme .pagination").delegate(".btn_suivant", "click", function(){
		
		$("#toute_la_gamme .sep_dotted").remove();
		
		var curPage = parseInt($("#toute_la_gamme span.current").html());
		var nextPage = parseInt(curPage)+1;
		
		var last_span = parseInt($("#toute_la_gamme .pagination span.current:last").html());
		var last_a = parseInt($("#toute_la_gamme .pagination a.other_page:last").html());
		
		
		if((last_span<=last_a &&  nextPage>=last_span)||(last_span<last_a &&  nextPage<=last_a)){
			//On masque tout
			$("#toute_la_gamme .gamme_produit").css("display", "none");
			
			
			for(var i=((nextPage-1)*6+1); i<=(6*nextPage);i++){
				$("#toute_la_gamme .gamme_produit:nth-child("+i+")").css("display", "block");
			}
			$("#toute_la_gamme .gamme_produit:nth-child("+6*nextPage+")").nextAll().css("display", "none");
			//On remet la pagination effaçé par la ligne précédente
			$("#toute_la_gamme .pagination").css('display', 'block');
			
			$("#toute_la_gamme .pagination span.current").each(function(){
				$(this).replaceWith("<a href='#' class=\"other_page\">"+$(this).text()+"</a>");
			});
			
	
			$("#toute_la_gamme .pagination .other_page").eq(nextPage-1).each(function(){
				$(this).replaceWith("<span class=\"current\">"+$(this).text()+"</span>");
			});
			
			creerSep("toute_la_gamme", "gamme_produit");
			updateBtnSuivPrec(curPage, nextPage, "toute_la_gamme");
			updateposFond();
		}
		return false;
	});

	
	//Btn precedent
	$("#toute_la_gamme .pagination").delegate(".btn_precedent", "click", function(){

		$("#toute_la_gamme .sep_dotted").remove();
		
		var curPage = parseInt($("#toute_la_gamme span.current").html());
		if(curPage>1){
			var nextPage = parseInt(curPage)-1;
			//On masque tout
			$("#toute_la_gamme .gamme_produit").css("display", "none");
			
			
			for(var i=((nextPage-1)*6+1); i<=(6*nextPage);i++){
				$("#toute_la_gamme .gamme_produit:nth-child("+i+")").css("display", "block");
			}
			$("#toute_la_gamme .gamme_produit:nth-child("+6*nextPage+")").nextAll().css("display", "none");
			//On remet la pagination effaçé par la ligne précédente
			$("#toute_la_gamme .pagination").css('display', 'block');
			
			$("#toute_la_gamme .pagination span.current").each(function(){
				$(this).replaceWith("<a href='#' class=\"other_page\">"+$(this).text()+"</a>");
			});
			
	
			$("#toute_la_gamme .pagination .other_page").eq(nextPage-1).each(function(){
				$(this).replaceWith("<span class=\"current\">"+$(this).text()+"</span>");
			});
			
			creerSep("toute_la_gamme", "gamme_produit");
			updateBtnSuivPrec(curPage, nextPage, "toute_la_gamme");
			updateposFond();
		}
		return false;
	});
	
	
	
	//A cause de la methos nextAll, les ligne de démarquations disparaisse en même temps que les variante, 
	//On les créé donc à la volée
	creerSep("toute_la_gamme", "gamme_produit");
	
	
	updateposFond();
	
	
	
	
	
	
	//Vérification commande qte possible
	$('.btn_commander_ref_seul').click(function(){
	
		var tab_art_commandes 	= new Array();
		var tab_quantite 		= new Array();
	
		var REF_FOUSSIER = $(this).parent().find('input[name="ART_REF_FOUSSIER"]').val();
		var QUANTITE = Number($(this).parent().find('input[name="quantite"]').val());

		var article_commandable = quantiteIsCommandable(REF_FOUSSIER, QUANTITE, false, true);
		tab_art_commandes.push(REF_FOUSSIER);
		tab_quantite.push(QUANTITE);
		
		if(!article_commandable.IS_COMMANDABLE){
			popupQuantiteNonCommandable(article_commandable);
		}
		else{
			ajouterAuPanier(tab_art_commandes, tab_quantite);
			updateCartouchePanier();
			popupAjoutPanier(tab_art_commandes, tab_quantite);
		}	
			
		return false;
	});
		
	
	$('#btn_ajout_article').click(function(){
	
		var tab_art_non_commandables 	= new Array();
		var tab_art_commandes 			= new Array();
		var tab_quantite 				= new Array();
		
		$.each($('.listing_article input[name^="ART_REF_FOUSSIER_QTE"]'), function(){
			var QUANTITE = Number($(this).val());
			if(QUANTITE > 0){
				var REF_FOUSSIER = $(this).attr('name').replace('ART_REF_FOUSSIER_QTE[', '').replace(']', '');
				var article_commandable = quantiteIsCommandable(REF_FOUSSIER, QUANTITE, false, false);
				if(!article_commandable.IS_COMMANDABLE) tab_art_non_commandables.push(article_commandable);
				tab_art_commandes.push(REF_FOUSSIER);
				tab_quantite.push(QUANTITE);
			}
		});

		if(tab_art_non_commandables.length > 0){
			popupQuantiteNonCommandableMultiple(tab_art_non_commandables);
		}	
		else{
			ajouterAuPanier(tab_art_commandes, tab_quantite);
			updateCartouchePanier();
			popupAjoutPanier(tab_art_commandes, tab_quantite);
		}	
			
		return false;
	});
	
	
	
	
	
	
	
	
	
	// decompte timer
	var minute = 60;
	var heure = 60*minute;
	var jour = 24*heure;
		
	setInterval(function updateTimer(){
		if($('.timer span.contenu_timer').length){	
		
			$('.timer span.contenu_timer').each(function(){
				
				var contenu = $(this).html();
				if(contenu.length>0 ){
					//Jour
					var nbJour = $(this).find('.jour').html();
					
					//heure
					var nbHeure = $(this).find('.heure').html();
					 
					//Minute
					var nbMinute = $(this).find('.minute').html();
					
					//Seconde
					var nbSeconde = $(this).find('.seconde').html();
					
					//contenu = contenu.replace(/([0-9]*)j/i, "trouvé");
					
					var duree = parseInt(nbMinute*minute,10) + parseInt(nbHeure*heure,10) + parseInt(nbJour*jour,10)+ parseInt(nbSeconde,10)-1;
					
					if(duree>0){
						var nb_jour = Math.floor(duree/jour);
						var nb_heure = Math.floor((duree%jour)/heure);
						var nb_minute = Math.floor((duree%heure)/minute);
						var nb_seconde = Math.floor(duree%minute);
						
							
						if(nb_jour>0){
							$(this).find('.jour').html(nb_jour);
						}else{
							$(this).find('.jour').hide();
							$(this).find('.unitejour').hide();
						}
						
						if(nb_heure>0){
							$(this).find('.heure').html(nb_heure);
						}else{
							if (nb_heure+nb_jour==0){
								$(this).find('.heure').hide();
								$(this).find('.uniteheure').hide();
							}
						}
						
						if(nb_minute>0){
							$(this).find('.minute').html(nb_minute);
						}else{
							if (nb_heure+nb_jour+nb_minute==0){
								$(this).find('.minute').hide();
								$(this).find('.uniteminute').hide();
							}
						}
						
						
						$(this).find('.seconde').html(nb_seconde);
						
						
					}else{
						$(this).parent().html('');
					}
					
				}
			});		
		}
	}, 1000);	
	
	
	
});










function updateBtnSuivPrec(curPage, nextPage, context){
	
	var last_span = parseInt($("#"+context+" .pagination span.current:last").html());
	var last_a = parseInt($("#"+context+" .pagination a.other_page:last").html());

	if (( last_span>last_a &&  last_span==nextPage)||( last_span<last_a &&  last_a==nextPage)){
		$("#"+context+" .pagination .btn_suivant").each(function(){
			$(this).replaceWith("<span class=\"btn_suivant disabled\">"+$(this).text()+"</span>");
		});
	}
	
	if (( last_span>last_a &&  last_span>nextPage)||( last_span<last_a &&  last_a>nextPage)){
		$("#"+context+" .pagination .btn_suivant").each(function(){
			$(this).replaceWith("<a href=\"#\" class=\"btn_suivant\">"+$(this).text()+"</a>");
		});
	}	

	if (nextPage >1 ){
		$("#"+context+" .pagination .btn_precedent").each(function(){
			$(this).replaceWith("<a href=\"#\" class=\"btn_precedent\">"+$(this).text()+"</a>");
		});
	}
	
	if (nextPage == 1){
		$("#"+context+" .pagination .btn_precedent").each(function(){
			$(this).replaceWith("<span class=\"btn_precedent disabled\">"+$(this).text()+"</span>");
		});
	}
}


function creerSep(context, bloc){
	//Le nombre d'element pour une demarquation est 3
	var nbMax = 3;
	
	var nbEl = $('#'+context+' .'+bloc).size();
	
	if (nbEl>nbMax){
		$('#'+context+' .'+bloc+':nth-child(3n)').each(function (){
			$(this).after('<div class="sep_dotted"></div>');																
		});
	}
	
	//On masque les démarquations inutil
	$('#'+context+' .sep_dotted').each(function() {
		if ($(this).prev().css('display')=='none' || $(this).next().css('display')=='none' || $(this).next().attr('class')=='pagination'){
			$(this).css('display', 'none');	
		}									
		
	});
}


function updateposFond(){
	var hauteur_fond = 667;
	var debut_y = -1660; 
	$('.contenu_onglet').each(function (){

		
		//if($(this).css('display')=='block' || $(this).css('display')==''){
			var val = debut_y - hauteur_fond + ((parseInt($(this).css('height'))+parseInt($(this).css('padding-top')) ) );
			//var val = debut_y - hauteur_fond ;
		
			$(this).css('background-position','left '+val+'px');
		//}
	});
}


//Anim le slide des visuels miniatures
function animThumb(sens){
	if (animMiniature == false){
		animMiniature = true;
		var pos = Math.abs(parseInt($('.thumbs .slideInner').css('marginLeft')));
		var pas = slideMinWidth*3;
		
		if (sens == '1'){
			if ((pos+slideMinWidth) > (totalMinlWidth-slideMinWidth)){
				pos = 0;
			}
			else{									
				pos = -pos-slideMinWidth;
			}	
		}else{
			if ((pos-slideMinWidth>=0)){
				pos = -pos+slideMinWidth;
			}
			else{									
				pos = -totalMinlWidth+slideMinWidth;
				//if (typeof console != 'undefined') console.log('ligne 317');
			}
		}
		
		$('.thumbs .slideInner').animate({'marginLeft' : pos},500, function(){ 
																			animMiniature = false;
																		});
	}
}



//Anim le slide des visuels miniatures
function animThumbPopup(sens){
	if (animMiniaturePopup == false){
		animMiniaturePopup = true;
		var posPopup = Math.abs(parseInt($('.liste_visuels .slideContenu').css('marginTop')));
		var pasPopup =parseInt($('.liste_visuels .lien_miniature').css('height'),10);
		
		if (sens == '1'){
			if ((posPopup+slideMinHeightPopup) > (totalMinHeigtPopup-slideMinHeightPopup)){
				posPopup = 0;
			}
			else{									
				posPopup = -posPopup-slideMinHeightPopup;
			}	
		}else{
			if ((posPopup-slideMinHeightPopup>=0)){
				posPopup = -posPopup+slideMinHeightPopup;
			}
			else{									
				posPopup = -totalMinHeigtPopup+slideMinHeightPopup;
				//if (typeof console != 'undefined') console.log('ligne 317');
			}
		}
		
		$('.liste_visuels .slideContenu').animate({'marginTop' : posPopup},500, function(){ 
																			animMiniaturePopup = false;
																		});
	}
}
