$(document).ready(
	function () {
		$("iframe").css("z-index","0");
		
		$("#caout").click(function() {
			$("#top").prepend('<div style="position: absolute; z-index: 9; left: 500px; width: 300px; height: 200px; background: red">fsfsd</div>');
		});
		
		i=0;
		$("object").each(function() {
			$(this).wrap('<div class="myobject'+i+'"></div>');
			
			$(".myobject"+i+" > object > embed").attr("wmode","opaque");
			$(".myobject"+i+" > object > embed").before('<param name="wmode" value="opaque">');
			
			var flash = $(this).parent().html().replace(/wmode="([^"]+)"/gi, 'wmode="opaque"');
			flash = flash.replace(/<param name="wmode" value="([^"]+)">/gi, '<param name="wmode" value="opaque">');
			
			$(this).parent().empty();
			//alert(flash);
			$(".myobject"+i).append(flash);
			
			i++;
		});
		
		menu_plus();
		
		$("#plus").click(function() {
			if ($("#menu_plus").css("display") == "none") {
				$("#menu_plus, #menu_plus_ul").css({top: "-"+$("#menu_plus").height()+"px"}).show();
				$("#menu_plus, #menu_plus_ul").animate({top: "300px"}, 500);
				$("#menu_plus, #menu_plus_ul").animate({top: "227px"}, 200);
				$("#plus").text("Plus ▲");
			}
			else {
				$("#menu_plus, #menu_plus_ul").animate({top: "180px"}, 200);
				$("#menu_plus, #menu_plus_ul").animate({top: ($(window).height() + $(window).scrollTop())+"px"}, 500);
				$("#menu_plus, #menu_plus_ul").hide(500);
				$("#plus").text("Plus ▼");
			}
			
			return false;
		});
		
		if (document.getElementById("selector"))
			selector_more();
		
		if (document.getElementById("accueil") && document.getElementById("nouveau")) {
			var c_c = '<div class="intro" style="position: absolute; display: none; z-index: 10; background: #FFEDED; border: 1px solid #8E2827">'
						+ '<a style="float: right" href="#" onclick="$(\'.intro\').slideToggle(1000); return false;"><img src="/images/close.png" /></a>'
						+ '<img src="/images/nouveau.gif" />'
						+ '<div style="margin: 20px 0 0 100px; color: #8E2827; font-weight: bold">'
							+ 'Vous pouvez dorénavant créer un compte membre pour :'
							+ '<ul style="margin: 10px 0 0 40px">'
								+ '<li>1 - Définir les filtres à appliquer par défaut selon vos critères.</li>'
								+ '<li>2 - Enregistrer vos recherches favorites.</li>'
								+ '<li>3 - Créer des alertes par mail.</li>'
							+ '</ul>'
						+ '</div>'
						+ '<br />'
						+ '<div align="center"><a href="/creation-compte"><img src="/images/creercompte.gif" /></a></div>'
					+ '</div>';
			
			$("#intro").before(c_c);
			$(".intro").css({width: $("#intro").width()+'px', height: $("#intro").height()+'px'});
			$(".intro").slideToggle(1000);
		}
		
		/*
		var newlinks = '<a class="1essai" style="display: none; margin: -3px 0 0 0; padding: 0 5px; font-size: 11px; color: white; background: #AF0000" href="#">Réserver un essai</a>'
					  +'<a target="_blank" style="display: none; margin: -3px 0 0 2px; padding: 0 5px; font-size: 11px; color: white; background: #005FAF" href="http://clk.tradedoubler.com/click?p=23770&a=1455591&g=16115608&url=http://www.mediatis.fr/projets/vehicule/voiture-neuve/">Financer ce modèle</a>'
					  +'<a style="display: none; margin: -3px 0 0 2px; padding: 0 5px; font-size: 11px; color: white; background: #DC7F00" href="http://tracking.publicidees.com/clic.php?promoid=4918&progid=195&partid=9887" target="_blank">Assurer cette voiture</a><img src="http://tracking.publicidees.com/link.php?promoid=4918&progid=195&partid=9887" height="1" width="1">';
					  //+'<a style="display: none; margin: -3px 0 0 2px; padding: 0 5px; font-size: 11px; color: white; background: #52AF00" href="http://clic.reussissonsensemble.fr/click.asp?ref=400367&site=6879&type=b4&bnb=4" target="_blank">Réviser sa voiture</a>';
		$(".bloc_plus").append(newlinks);
		*/
		
		var darwin   = (window.location.href.match(new RegExp("voiture-neuve","g"))) ? 'http://clk.tradedoubler.com/click?p=55606&a=1863929&g=19073108' : 'http://clk.tradedoubler.com/click?p=55606&a=1863929&g=19079096';
		var newlinks = '<div class="bloc_plus">'
					 + '<a target="_blank" style="color: white" href="http://ad.zanox.com/ppc/?18296638C1549550695T">Financer</a>'
					 + '</div>'
					 
					 + '<div class="bloc_plus2">'
					 + '<a target="_blank" style="color: white" href="http://clk.tradedoubler.com/click?p=189101&a=1806760&g=18651542">Assurer</a>'
					 + '</div>'
					 
					 + '<div class="bloc_plus3">'
					 + '<a class="1essai" style="color: white" href="#">Essayer</a>'
					 + '</div>';
		
		$(".c_bloc").each(function() {
			$(this).find(".c_infos").append(newlinks);
			//$(this).prepend('<iframe src="http://www.facebook.com/plugins/like.php?href='+window.location.href+'#'+$(this).attr("id")+'&layout=standard&show_faces=false&width=450&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:25px"></iframe>');
		});
		
		$(".bloc, .c_bloc").each(function() {
			$(this).mouseover(function() {
				$(this).find(".c_detail > a > img").attr({src: "/images/details_hover.gif"});
				//1essai
				$(this).find(".bloc_plus, .bloc_plus2, .bloc_plus3").show();
				//1essai
			});
			$(this).mouseout(function() {
				$(this).find(".c_detail > a > img").attr({src: "/images/details.gif"});
				//1essai
				$(this).find(".bloc_plus, .bloc_plus2, .bloc_plus3").hide();
				//1essai
			});
		});
		
		//1essai
		$(".1essai").click(function() {
			var unessai = '<div id="bgframe"></div><div id="1essaiframe" style="position: absolute; display: none; margin: 10px 0 0 0; width: 645px;"><a style="position: absolute; margin: -34px 0 0 632px" href="#" onclick="return false;"><img src="/images/close_web2.png" /></a><iframe id="ifr_1essai" src="http://tracking.publicidees.com/clic.php?promoid=39642&progid=1257&partid=21255" width="630" height="550" noresize="noresize" frameborder="0" marginwidth="0" marginheight="0" style="overflow-x: hidden; padding: 0 0 0 15px; background: #fff; text-align: center"></iframe><!--<div align="center" style="padding: 5px 0 0 0"><a href="#" onclick="return false;"><img src="/images/fleches_bas.png" /></a></div>--></div>';
			
			$(this).after('<img class="loading" style="position: absolute; margin: 0 0 0 5px" src="/images/loading.gif" />');
			$("body").append(unessai);
			
			$("#ifr_1essai").load(function() {
				$(".loading").remove();
				$("#bgframe").css({width: $("#1essaiframe").width()+'px', height: $("#1essaiframe").height()+'px', left: (($(window).width() - $("#1essaiframe").width()) / 2 - 10)+'px', opacity: '0.5'});
				$("#1essaiframe").css({left: (($(window).width() - $("#1essaiframe").width()) / 2)+'px'});
				
				$("#bgframe, #1essaiframe").css({top: ($(document).scrollTop() - $("#bgframe").height() - 20)+"px"}).show();
				$("#bgframe, #1essaiframe").animate({top: (100 + $(window).scrollTop())+"px"}, 500);
				$("#bgframe, #1essaiframe").animate({top: (60 + $(window).scrollTop())+"px"}, 200);
			});
			
			$("body").click(function() {
				$("#bgframe, #1essaiframe").animate({top: (20 + $(window).scrollTop())+"px"}, 200);
				$("#bgframe, #1essaiframe").animate({top: ($(window).height() + $(window).scrollTop())+"px"}, 500);
				
				$("#bgframe, #1essaiframe").hide(500, function() {
					$("#bgframe, #1essaiframe").remove();
				});
			});
			
			return false;
		});
		//1essai
		
		if (document.getElementById("pub_catalogue_left") || document.getElementById("fever")) {
			scrollpub($("#fever").offset().top, $("#tri").offset().top);
		}
		
		
		/*--- hover ---*/
		$(".tri_bloc:eq(0) > ul > li, .tri_bloc:eq(1) > ul > li, .tri_bloc:eq(3) > ul > li, .tri_bloc:eq(4) > ul > li, #liste_finitions > li").mouseover(function() {
			$(this).css("cursor","pointer");
		});
		$(".tri_bloc:eq(0) > ul > li > a, .tri_bloc:eq(1) > ul > li > a, .tri_bloc:eq(3) > ul > li > a, .tri_bloc:eq(4) > ul > li > a, , #liste_finitions > li > a").click(function() {
			$(this).parent().click();
			return false;
		});
		/*--- hover ---*/
		//carburant
		/*
		$(".tri_bloc:eq(0) > ul > li").each(function() {
			$(this).click(function() {
				if ($(this).text().replace(/ /g, "") == "Tous") {
					if ($(this).attr("class") == "unchecked")
						$(".tri_bloc:eq(0) > ul > li").attr("class","");
					else
						$(".tri_bloc:eq(0) > ul > li").attr("class","unchecked");
				}
				else {
					if ($(this).attr("class") == "unchecked")
						$(this).attr("class","");
					else
						$(this).attr("class","unchecked");
				}
			});
		});
		*/
		
		$(".tri_bloc:eq(0) > ul > li").each(function() {
			if ($(this).text().replace(/ /g, "") != "Tous") {
				var checker = ($(this).attr("class") == "unchecked") ? "checked" : "unchecked";
				$(this).prepend('<div class="checker" style="position: absolute; display: none; margin: -3px 0 0 0; padding: 2px 5px; border: 1px solid #c0c0c0"><img style="float: left" src="/images/'+checker+'.png" /><img style="float: left; margin: 0 0 0 10px" src="/images/only_check.png" /></div>');
				
				$(this).mouseover(function() {
					var checker = ($(this).attr("class") == "unchecked") ? "checked" : "unchecked";
					$(this).find(".checker").find("img:eq(0)").attr("src","/images/"+checker+".png");
					$(this).find(".checker").show();
				});
				$(this).mouseout(function() {
					$(this).find(".checker").hide();
				});
			}
			else {
				$(this).click(function() {
					if ($(this).attr("class") == "unchecked")
						$(".tri_bloc:eq(0) > ul > li").attr("class","");
					else
						$(".tri_bloc:eq(0) > ul > li").attr("class","unchecked");
				});
			}
		});
		//tri
		$(".tri_bloc:eq(1) > ul > li").each(function() {
			$(this).click(function() {
				$(".tri_bloc:eq(1) > ul > li").attr("class","unchecked");
				$(this).attr("class","");
			});
		});
		//version
		$("input[name='version']").keypress(function(e) {
			if (e.which == 13)
				$(".tri_submit > button").click();
		});
		
		$("#liste_finitions > li").each(function() {
			if ($(this).text().replace(/ /g, "") != "Toutes") {
				var checker = ($(this).attr("class") == "unchecked") ? "checked" : "unchecked";
				$(this).prepend('<div class="checker" style="position: absolute; display: none; margin: -3px 0 0 0; padding: 2px 5px; border: 1px solid #c0c0c0"><img style="float: left" src="/images/'+checker+'.png" /><img style="float: left; margin: 0 0 0 10px" src="/images/only_check.png" /></div>');
				
				$(this).mouseover(function() {
					var checker = ($(this).attr("class") == "unchecked") ? "checked" : "unchecked";
					$(this).find(".checker").find("img:eq(0)").attr("src","/images/"+checker+".png");
					$(this).find(".checker").show();
				});
				$(this).mouseout(function() {
					$(this).find(".checker").hide();
				});
			}
			else {
				$(this).click(function() {
					if ($(this).attr("class") == "unchecked")
						$("#liste_finitions > li").attr("class","");
					else
						$("#liste_finitions > li").attr("class","unchecked");
				});
			}
		});
		//portes
		/*
		$(".tri_bloc:eq(3) > ul > li").each(function() {
			$(this).click(function() {
				if ($(this).text().replace(/ /g, "") == "Tous") {
					if ($(this).attr("class") == "unchecked")
						$(".tri_bloc:eq(3) > ul > li").attr("class","");
					else
						$(".tri_bloc:eq(3) > ul > li").attr("class","unchecked");
				}
				else {
					if ($(this).attr("class") == "unchecked")
						$(this).attr("class","");
					else
						$(this).attr("class","unchecked");
				}
			});
		});
		*/
		
		$(".tri_bloc:eq(3) > ul > li").each(function() {
			if ($(this).text().replace(/ /g, "") != "Tous") {
				var checker = ($(this).attr("class") == "unchecked") ? "checked" : "unchecked";
				$(this).prepend('<div class="checker" style="position: absolute; display: none; margin: -3px 0 0 0; padding: 2px 5px; border: 1px solid #c0c0c0"><img style="float: left" src="/images/'+checker+'.png" /><img style="float: left; margin: 0 0 0 10px" src="/images/only_check.png" /></div>');
				
				$(this).mouseover(function() {
					var checker = ($(this).attr("class") == "unchecked") ? "checked" : "unchecked";
					$(this).find(".checker").find("img:eq(0)").attr("src","/images/"+checker+".png");
					$(this).find(".checker").show();
				});
				$(this).mouseout(function() {
					$(this).find(".checker").hide();
				});
			}
			else {
				$(this).click(function() {
					if ($(this).attr("class") == "unchecked")
						$(".tri_bloc:eq(3) > ul > li").attr("class","");
					else
						$(".tri_bloc:eq(3) > ul > li").attr("class","unchecked");
				});
			}
		});
		//carrosserie
		/*
		$(".tri_bloc:eq(4) > ul > li").each(function() {
			$(this).click(function() {
				if ($(this).text().replace(/ /g, "") == "Toutes") {
					if ($(this).attr("class") == "unchecked")
						$(".tri_bloc:eq(4) > ul > li").attr("class","");
					else
						$(".tri_bloc:eq(4) > ul > li").attr("class","unchecked");
				}
				else {
					if ($(this).attr("class") == "unchecked")
						$(this).attr("class","");
					else
						$(this).attr("class","unchecked");
				}
			});
		});
		*/
		
		$(".tri_bloc:eq(4) > ul > li").each(function() {
			if ($(this).text().replace(/ /g, "") != "Toutes") {
				var checker = ($(this).attr("class") == "unchecked") ? "checked" : "unchecked";
				$(this).prepend('<div class="checker" style="position: absolute; display: none; margin: -3px 0 0 0; padding: 2px 5px; border: 1px solid #c0c0c0"><img style="float: left" src="/images/'+checker+'.png" /><img style="float: left; margin: 0 0 0 10px" src="/images/only_check.png" /></div>');
				
				$(this).mouseover(function() {
					var checker = ($(this).attr("class") == "unchecked") ? "checked" : "unchecked";
					$(this).find(".checker").find("img:eq(0)").attr("src","/images/"+checker+".png");
					$(this).find(".checker").show();
				});
				$(this).mouseout(function() {
					$(this).find(".checker").hide();
				});
			}
			else {
				$(this).click(function() {
					if ($(this).attr("class") == "unchecked")
						$(".tri_bloc:eq(4) > ul > li").attr("class","");
					else
						$(".tri_bloc:eq(4) > ul > li").attr("class","unchecked");
				});
			}
		});
		$(".checker").each(function() {
			$(this).find("img:eq(0)").click(function() {
				var checker = ($(this).parent().parent().attr("class") == "unchecked") ? "" : "unchecked";
				$(this).parent().parent().attr("class",checker);
				
				checker = ($(this).parent().parent().attr("class") == "unchecked") ? "checked" : "unchecked";
				$(this).attr("src","/images/"+checker+".png");
			});
			$(this).find("img:eq(1)").click(function() {
				$(this).parent().parent().parent().find("li").attr("class","unchecked");
				$(this).parent().parent().attr("class","");
				
				var checker = ($(this).parent().parent().attr("class") == "unchecked") ? "checked" : "unchecked";
				$(this).parent().find("img:eq(0)").attr("src","/images/"+checker+".png");
			});
		});
		//budget
		$("input[name='budget1'], input[name='budget2']").keypress(function(e) {
			if (e.which == 13)
				$(".tri_submit > button").click();
		});
		
		$(".tri_submit > button").click(function() {
			var carburant = "";
			var carb_tous = "oui";
			$(".tri_bloc:eq(0) > ul > li").each(function() {
				if ($(this).text().replace(/ /g, "") != "Tous") {
					if ($(this).attr("class") != "unchecked")
						carburant+= "_"+$(this).find("a").text();
					else
						carb_tous = "non";
				}
			});
			if (carb_tous == "non")
				carburant = carburant.substr(1, (carburant.length - 1));
			else
				carburant = "tous";
			
			
			var tri = $(".tri_bloc:eq(1) > ul > li[class!='unchecked']").text().replace(/ /g, "");
			
			
			var finitions = "";
			var f_toutes  = "oui";
			$("#liste_finitions > li").each(function() {
				if ($(this).text().replace(/ /g, "") != "Toutes") {
					if ($(this).attr("class") != "unchecked")
						finitions+= "_"+$(this).find("a").text().replace("+", "-+-");
					else
						f_toutes = "non";
				}
			});
			if (f_toutes == "non")
				finitions = finitions.substr(1, (finitions.length - 1));
			else
				finitions = "toutes";
			
			
			var portes = "";
			var p_tous  = "oui";
			$(".tri_bloc:eq(3) > ul > li").each(function() {
				if ($(this).text().replace(/ /g, "") != "Tous") {
					if ($(this).attr("class") != "unchecked")
						portes+= "_"+$(this).find("a").text();
					else
						p_tous = "non";
				}
			});
			if (p_tous == "non")
				portes = portes.substr(1, (portes.length - 1));
			else
				portes = "tous";
			
			
			var carrosserie = "";
			var c_toutes  = "oui";
			$(".tri_bloc:eq(4) > ul > li").each(function() {
				if ($(this).text().replace(/ /g, "") != "Toutes") {
					if ($(this).attr("class") != "unchecked")
						carrosserie+= "_"+$(this).find("a").text();
					else
						c_toutes = "non";
				}
			});
			if (c_toutes == "non")
				carrosserie = carrosserie.substr(1, (carrosserie.length - 1));
			else
				carrosserie = "toutes";
			
			
			if ($("input[name='add_search_mode']").val() == 1)
				add_search3(carburant, tri, portes, carrosserie);
			else if (!document.getElementById('menu_moncompte'))
				window.location.replace($("input[name='uri']").val()+'::version='+$("input[name='version']").val()+'&finitions='+finitions+'&carburant='+carburant+'&tri='+tri+'&portes='+portes+'&carrosserie='+carrosserie+'&budget1='+$("input[name='budget1']").val()+'&budget2='+$("input[name='budget2']").val());
		});
		
		/*----- Fiche Ajax -----*/
		$(".c_bloc").each(function() {
			$(this).append('<img class="slide_fiche" style="margin: 20px 0 0 0" src="/images/fiche.jpg" />');
		});
		
		$(".slide_fiche").each(function() {
			$(this).mouseover(function() {
				$(this).css({cursor: 'pointer'});
			});
			$(this).click(function() {
				var ref = $(this).parent().attr("id").replace("fiche","");
				
				if ($("#fiche_ajax_"+ref).attr("class") == "fiche_ajax") {
					var offset = $(this).parent().offset();
					
					if ($("#fiche_ajax_"+ref).css("display") == "block") {
						$(this).attr("src","/images/fiche.jpg");
						$("html, body").animate({scrollTop : offset.top}, 500, function() {
							$("#fiche_ajax_"+ref).slideUp(500);
						});
					}
					else {
						$("#fiche_ajax_"+ref).slideDown(500);
						$(this).attr("src","/images/fiche_up.jpg");
					}
				}
				else {
					if (window.location.href.match("/voiture-neuve/"))
						var cat = "neuf";
					else if (window.location.href.match("/voiture-occasion/"))
						var cat = "occasion";
					
					fiche(ref, cat);
				}
			});
			
			//Afficher fiche au chargement
			if ( $(this).parent().attr("id") == window.location.href.replace(/.*#fiche([0-9]+)/g, "fiche$1") )
				$(this).click();
		});
		/*----- Fiche Ajax -----*/
		
		/*----- Fever -----*/
		/*--- Accueil ---*/
		if (document.getElementById("accueil")) {
			$.post("/adfever/accueil.php", {
				s: "mandataire auto"
			},
				function(data){
					$("#accueil").before(data);
				}
			);
			
			$.post("/adfever/accueil.php", {
				s: "voiture neuve"
			},
				function(data){
					$("#accueil").after(data);
				}
			);
		}
		/*--- Accueil ---*/
		
		/*--- Catalogue ---*/
		if (document.getElementById("fever")) {
			$.post("/adfever/accueil.php", {
				s: $("#fever").attr("class").replace(/(voiture neuve|voiture occasion)/g, "mandataire")
			},
				function(data){
					$("#catalogue").after(data);
				}
			);
			
			$.post("/adfever/search.php", {
				s: $("#fever").attr("class")
			},
				function(data){
					$("#fever").append(data);
				}
			);
			
			
			// commentaires
			btn_com = "";
			$("#intro").next().prepend('<a id="btn_com2" style="float: right; padding: 2px 5px; background: #0057B9; color: white; font-size: 11px; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px" href="#" onclick="com_frame_close(\'2\'); return false;">Ajoutez un commentaire</a>');
			// commentaires
		}
		/*--- Catalogue ---*/
		/*----- Fever -----*/
		
		/*--- Créer Compte ---*/
		
		/*--- Créer Compte ---*/
	}
);


function menu_plus() {
	var menu_plus =  '<div id="menu_plus"></div>'
					+'<div id="menu_plus_ul">'
					+'	<div class="bloc">'
					+'		<a style="color: #0075B2; font-size: 13px; font-weight: bold" href="/formulaire-de-recherche">Formulaire de recherche détaillée</a>'
					+'		<p><a href="/formulaire-de-recherche">'
					+'			Vous souhaitez faire une demande à l\'ensemble de nos partenaires ? Alors remplissez le formulaire de recherche en détaillant au mieux vos critères importants ainsi'
					+'			que les questions que vous vous posez. Nos partenaires vous répondront directement si et seulement si ils disposent d\'une offre correspondant à votre recherche.'
					+'		</a></p>'
					+'		<a style="color: #539300" href="/formulaire-de-recherche">Remplir le formulaire</a>'
					+'	</div>'
					
					+'	<div class="bloc">'
					+'		<a style="color: #0075B2; font-size: 13px; font-weight: bold" href="/achat-voiture/1">Demandes des visiteurs</a>'
					+'		<p><a href="/achat-voiture/1">'
					+'			Retrouvez ici l\'ensemble des demandes formulées par nos visiteurs. Professionnels de l\'automobile, trouvez ici des prospects.'
					+'		</a></p>'
					+'		<a style="color: #539300" href="/achat-voiture/1">Consulter les demandes</a>'
					+'	</div>'
					+'</div>'
	
	$("#menu").after(menu_plus);
	$("#menu_plus").css({height: $("#menu_plus_ul").height()+"px", opacity: "0.5"});
	//$("#menu_plus_ul .bloc").css({padding: "0 0 0 25px", background: "url(/images/fleche_verte.gif) left center no-repeat"});
}

/* Scroll uniquement TRI
function scrollpub(top_left_pub, top_tri) {
	if ($(window).height() > $("#tri").height()) {
		var marge_tri = $(window).scrollTop() - top_tri;
		
		if (marge_tri > 0)
			$("#tri").animate({"marginTop": (marge_tri+20)+"px"}, function() {
				scrollpub(top_left_pub, top_tri);
			});
		else
			$("#tri").animate({"marginTop": "15px"}, function() {
				scrollpub(top_left_pub, top_tri);
			});
	}
}
*/
function scrollpub(top_left_pub, top_tri) {
	if ($(window).height() > $("#fever").height()) {
		var marge_tri_fever = $(window).scrollTop() - top_left_pub;
		
		if (marge_tri_fever > ( $("#catalogue").height() - $("#fever").height() - 10 ))
			marge_tri_fever = ( $("#catalogue").height() - $("#fever").height() - 10 );
		
		if (marge_tri_fever > 0)
			//if (($(window).scrollTop() + $(window).height()) < ($(document).height() - 10)) {
			$("#fever").animate({"marginTop": (marge_tri_fever+20)+"px"}, function() {
				scrollpub(top_left_pub, top_tri);
			});
			//}
		else
			$("#fever").animate({"marginTop": "15px"}, function() {
				scrollpub(top_left_pub, top_tri);
			});
	}
	
	if ($(window).height() > $("#tri").height()) {
		var marge_tri = $(window).scrollTop() - top_tri;
		
		if (marge_tri > ( $("#catalogue").offset().top + $("#catalogue").height() - top_tri - $("#tri").height() - 30 ))
			marge_tri = ( $("#catalogue").offset().top + $("#catalogue").height() - top_tri - $("#tri").height() - 30 );
		
		if (marge_tri > 0)
			//if (($(window).scrollTop() + $(window).height()) < ($(document).height() - 10))
			$("#tri").animate({"marginTop": (marge_tri+20)+"px"});
		else
			$("#tri").animate({"marginTop": "15px"});
	}
}
/*
function scrollpub(top_left_pub, top_tri) {
	if ($(window).height() > $("#fever").height()) {
		var marge_tri_fever = $(window).scrollTop() - top_left_pub;
		
		if (marge_tri_fever > 0) {
			if (($(window).scrollTop() + $("#fever").height()) < ($("#catalogue").next().offset().top - 10))
				$("#fever").animate({"marginTop": (marge_tri_fever+20)+"px"}, function() {
					scrollpub(top_left_pub, top_tri);
				});
			else
				$("#fever").animate({"marginTop": ($("#catalogue").next().offset().top - $("#fever").height())+"px"}, function() {
					scrollpub(top_left_pub, top_tri);
				});
		}
		else {
			$("#fever").animate({"marginTop": "15px"}, function() {
				scrollpub(top_left_pub, top_tri);
			});
		}
	}
	
	if ($(window).height() > $("#tri").height()) {
		var marge_tri = $(window).scrollTop() - top_tri;
		
		if (marge_tri > 0)
			if (($(window).scrollTop() + $("#tri").height()) < ($("#footer").offset().top - 10))
				$("#tri").animate({"marginTop": (marge_tri+20)+"px"});
			else
				$("#tri").animate({"marginTop": ($("#footer").offset().top - $("#tri").height())+"px"});
		else
			$("#tri").animate({"marginTop": "15px"});
	}
}
*/
/* en cours
function scrollpub(top_left_pub, top_tri) {
	if ($(window).height() > $("#fever").height()) {
		var marge_tri_fever = $(window).scrollTop() - top_left_pub;
		
		if (marge_tri_fever > 0) {
			if (($(window).scrollTop() + $("#fever").height()) >= ($("#catalogue").offset().top + $("#catalogue").height()))
				$("#fever").animate({"marginTop": ($("#catalogue").offset().top + $("#catalogue").height() - $("#fever").height())+"px"}, function() {
					scrollpub(top_left_pub, top_tri);
				});
			else
				$("#fever").animate({"marginTop": (marge_tri_fever+20)+"px"}, function() {
					scrollpub(top_left_pub, top_tri);
				});
		}
		else {
			$("#fever").animate({"marginTop": "15px"}, function() {
				scrollpub(top_left_pub, top_tri);
			});
		}
	}
	
	if ($(window).height() > $("#tri").height()) {
		var marge_tri = $(window).scrollTop() - top_tri;
		
		if (marge_tri > 0)
			if (($(window).scrollTop() + $("#tri").height()) >= $("#footer").offset().top)
				$("#tri").animate({"marginTop": ($("#footer").offset().top - $("#tri").height())+"px"});
			else
				$("#tri").animate({"marginTop": (marge_tri+20)+"px"});
		else
			$("#tri").animate({"marginTop": "15px"});
	}
}
*/

function thumbnail(cat, id, photo) {
	$.post("/thumbnail.php", {
		id: id,
		cat: cat,
		img_src: photo
	},
		function(data){
			if (data != "") $("#img_"+id).attr("src","/"+data);
	  	}
	);
}

function fiche(ref, cat) {
	$.post("/fiche_ajax.php", {
		id: ref,
		cat: cat
	},
		function(data){
			$("#fiche"+ref).find(".slide_fiche").before(data);
			$("#fiche_ajax_"+ref).slideDown(500);
			$("#fiche"+ref).find(".slide_fiche").attr("src","/images/fiche_up.jpg");
	  	}
	);
}

function selector_more() {
	$("#selector li a").prepend('<span class="more"></span>');
	
	$("#selector li a").mouseover(function() {
		$(this).find(".more").show();
	});
	$("#selector li a").mouseout(function() {
		$(this).find(".more").hide();
	});
	
	$(".more").each(function() {
		$(this).click(function() {
			var tab = $(this).parent().parent().attr("name").split("|");
			var marge = (tab[0] - 1) * 212;
			
			if (tab[0] == 1)
				var coin = '-moz-border-radius-topright: 5px; -webkit-border-top-right-radius: 5px; border-top-right-radius: 5px;';
			else if (tab[0] == 3)
				var coin = '-moz-border-radius-topleft: 5px; -webkit-border-top-left-radius: 5px; border-top-left-radius: 5px;';
			else
				var coin = '-moz-border-radius-topright: 5px; -webkit-border-top-right-radius: 5px; border-top-right-radius: 5px; -moz-border-radius-topleft: 5px; -webkit-border-top-left-radius: 5px; border-top-left-radius: 5px;';
			
			$(".more_box_title, .more_box").remove();
			
			var box = '<div class="more_box_title"><img class="close" src="/images/close.png" onclick="$(\'.more_box_title, .more_box\').remove();" />'+tab[1]+'</div>'
					+ '<div class="more_box" style="margin: 0 0 0 -'+marge+'px; '+coin+'">'
					+ '<a href="'+$(this).parent().attr("href")+'/::tri=Prix">Tous les modèles triés par prix</a>'
					+ '<a href="'+$(this).parent().attr("href")+'/::tri=Remise">Tous les modèles triés par remise</a>'
					+ '<div id="more_box_modeles"></div>'
					+ '<div style="clear: both"></div>'
					+ '</div>';
			
			$(this).parent().after(box);
			
			if (window.location.href == "http://www.mandataireauto.net/voiture-neuve/1") {
				$.post("/ajax_modeles.php", {
					marque: $(this).parent().parent().attr("name").replace(/^[0-9]\|(.+)$/g, "$1")
				},
					function(data){
						$("#more_box_modeles").append(data).slideDown();
					}
				);
			}
			
			return false;
		});
	});
	
	if (window.location.href != "http://www.mandataireauto.net/voiture-neuve/1") {
		$(".more_marque").toggle(
			function () {
				$(".more_box_title, .more_box").remove();
				$(this).css("background","url('/images/close.png') center no-repeat");
				selector_more_marque();
				return false;
			},
			function () {
				$(this).css("background","url('/images/btn_plus.png') center no-repeat");
				$('.more_box').slideUp(function() {
					$(this).remove();
				});
				return false;
			}
		);
	}
}
function selector_more_marque() {
	var box = '<div class="more_box" style="display: none; margin: -8px 0 0 0"></div>';
	$("#selector h2").after(box);
	
	$.post("/ajax_marques.php", {
		
	},
		function(data){
			$(".more_box").append(data).slideDown();
		}
	);
}

function creercompte() {
	$.post("/ajax_creercompte.php", function(data) {
		$("#content").prepend(data);
		
		$("#vignettes > ul > li > div > a").each(function() {
			$(this).wrap('<div class="bord8"><div class="bord7"><div class="bord6"><div class="bord5"><div class="bord4"><div class="bord3"><div class="bord2"><div class="bord1"></div></div></div></div></div></div></div></div>');
		});
	});
}

function add_search() {
	$("#add_search_box").toggle();
}
function add_search2() {
	$("#add_search_box button").after('<input type="hidden" name="add_search_mode" value="1" />');
	$(".tri_submit > button").click();
}
function add_search3(carburant, tri, portes, carrosserie) {
	$("input[name='add_search_mode']").remove();
	
	$.post("/add_search.php", {
		search_name: $("input[name='add_search']").val(),
		marque: $("input[name='add_marque']").val(),
		modele: $("input[name='add_modele']").val(),
		carburant: carburant,
		tri: tri,
		version: $("input[name='version']").val(),
		portes: portes,
		carrosserie: carrosserie,
		budget1: $("input[name='budget1']").val(),
		budget2: $("input[name='budget2']").val()
	},
		function(data){
			if (data == "pseudo")
				$("#add_search_box ul").append('<li style="margin: 0 0 0 5px">Vous devez être connecté !</li>');
			else if (data == "search_name")
				$("#add_search_box ul").append('<li style="margin: 0 0 0 5px">Vous devez donner un nom à cette recherche !</li>');
			else
				$("#add_search_box ul").append('<li style="margin: 0 0 0 5px">Recherche ajoutée !</li>');
		}
	);
}

function supp_fav(id) {
	$.post("/supp_fav.php", {
		id: id
	},
		function(data){
			$("#fav_"+data).remove();
		}
	);
}

// Commentaires
function com_frame(num) {
	//if ($("#com_frame").css("display") == "block")
		//$("#fleche_com_frame, #com_frame").remove();
	
		if (num == 1) {
			var fleche = "oui";
			var position = "position: absolute;";
			var marges1 = "margin: 20px 0 0 540px";
			var marges2 = "margin: 31px 0 0 200px";
		}
		else if (num == 2) {
			var fleche = "oui";
			var position = "position: absolute;";
			var marges1 = "margin: 20px 0 0 390px";
			var marges2 = "margin: 31px 0 0 0";
		}
		else {
			var fleche = "non";
			var position = "";
			var marges2 = "margin: 5px 0 0 0";
		}
		
		if (btn_com != 1 && btn_com != 2)
			$("#btn_com"+num).parent().append(((fleche == "oui") ? '<div id="fleche_com_frame" style="'+position+' display: none; '+marges1+'"></div>' : '')+'<div id="com_frame" style="'+position+' display: none; '+marges2+'"><div id="com_frame_close" onclick="com_frame_close()">Fermer</div></div>');
		else
			$("#btn_com"+num).after(((fleche == "oui") ? '<div id="fleche_com_frame" style="'+position+' display: none; '+marges1+'"></div>' : '')+'<div id="com_frame" style="'+position+' display: none; '+marges2+'"><div id="com_frame_close" onclick="com_frame_close()">Fermer</div></div>');
		
		$.post("/com_form.php", {
			
		},
			function(data){
				$(".loading").remove();
				//alert($("#com_frame").html());
				$("#com_frame").append(data);
				$("#fleche_com_frame, #com_frame").show(500);
				com_modele_select(la_marque);
				etoiles();
				
				if (btn_com.replace(/[0-9]/g,"") == "_citer") {
					$("textarea[name='com_com']").val('[quote Message de '+$("#com_frame").parent().prev().prev().find(".pseudo").text()+' :]'+$("#com_frame").parent().prev().html().replace(/[\n\r]+/g,'').replace(/<div class="?quote"?>.*<\/div>/gi,'').replace(/(<br>|<br \/>)/gi,'\n').replace(/^\s+/g,'').replace(/\s+$/g,'')+'[/quote]\n\n');
					$(".com_tr").hide();
				}
				
				if (la_marque != "")
					$("select[name='com_marque']").val(la_marque);
				
				$("select[name='com_marque']").change(function() {
					com_modele_select($(this).val());
				});
				
				$("button[name='com_submit']").click(function() {
					com_submit();
					return false;
				});
			}
		);
}
function com_frame_close(num) {
	if (btn_com != num) {
		btn_com = num;
		$("#btn_com"+num).append('<img class="loading" style="position: absolute; margin: 0 0 0 5px" src="/images/loading.gif" />');
		
		if ($("#com_frame").css("display") == "block") {
			$("#fleche_com_frame, #com_frame").hide(500, function() {
				$("#fleche_com_frame, #com_frame").remove();
				//alert($("#com_frame").html());
				/*
				if (num != "")
					com_frame(num);
				*/
			});
			
			if (num != "")
				setTimeout("com_frame('"+num+"')", 1000);
		}
		else {
			if (num != "")
				com_frame(num);
		}
	}
}
function com_modele_select(marque) {
	$.post("/com_modele_select.php", {
		marque: marque
	},
		function(data){
			$("select[name='com_modele']").empty();
			$("select[name='com_modele']").append(data);
			
			if (le_modele != "")
				$("select[name='com_modele']").val(le_modele);
		}
	);
}
function etoiles() {
	$("img[id^='etoile'], img[id='interdit']").mouseover(function() {
		$(this).css("cursor", "pointer");
	});
	
	var clickedstar = 0;
	
	$("img[id^='etoile']").mouseover(function() {
		var numstar = $(this).attr("id").replace("etoile", "");
		$("#interdit").attr("src","/images/interdit_gris.png");
		
		$("img[id^='etoile']").each(function() {
			if ($(this).attr("id").replace("etoile", "") <= numstar || $(this).attr("id").replace("etoile", "") <= clickedstar)
				$(this).attr("src","/images/etoile_jaune.png");
			else
				$(this).attr("src","/images/etoile_grise.png");
		});
	});
	$("img[id^='etoile']").mouseout(function() {
		if (clickedstar == 0) {
			$("img[id^='etoile']").attr("src","/images/etoile_grise.png");
			$("#interdit").attr("src","/images/interdit.png");
		}
		else {
			$("img[id='etoile1']").mouseover();
		}
	});
	$("img[id^='etoile']").click(function() {
		clickedstar = $(this).attr("id").replace("etoile", "");
		$("img[id='etoile1']").mouseover();
		$("input[name='com_note']").val(clickedstar);
	});
	
	$("img[id='interdit']").click(function() {
		$(this).attr("src","/images/interdit.png");
		$("img[id^='etoile']").attr("src","/images/etoile_grise.png");
		clickedstar = 0;
		$("input[name='com_note']").val("");
	});
}
function com_submit() {
	$("button[name='com_submit']").attr("disabled", "disabled");
	$("button[name='com_submit']").after('<img class="loading" style="position: absolute; margin: 0 0 0 5px" src="/images/loading.gif" />');
	
	$.ajax({
		type: "POST",
		url: "/com_add.php",
		data: $("form[name='commentaire']").serialize(),
		success: function(data){
			$(".loading").remove();
			
			if (data != "") {
				$(".com_error").remove();
				$("button[name='com_submit']").attr("disabled", "");
				
				if (data == "error") {
					$("button[name='com_submit']").after('<div style="margin: 10px 0 0 0; padding: 2px 0; background: red; color: white; font-weight: bold">Suite à un problème, votre commentaire n\'a pas été enregistré. Veuillez réessayer.</div>');
				}
				else {
					var tab = data.split("---");
					var l = tab.length;
					
					for (var i=1; i<=l; i++) {
						var datas = tab[i].split(":");
						$("[name='"+datas[0].replace("error_", "")+"']").parent().parent().before('<tr class="com_error"><td colspan="2" style="padding: 10px 0 0 0; text-align: center; color: red">'+datas[1]+'</td></tr>');
					}
				}
			}
			else {
				$(".com_error").remove();
				$("button[name='com_submit']").after('<div style="margin: 10px 0 0 0; padding: 2px 0; background: green; color: white; font-weight: bold">Votre commentaire a été enregistré !</div>');
				setTimeout("com_frame_close()", 2000);
			}
		}
	});
}
// Commentaires
