$(document).ready(function(){
		
	
//rating:

	
	$("#onglet_resa_2").live('click',function(){
		$("#onglet_resa_1").removeClass("choose");
		$("#onglet_resa_1").addClass("no-select");
		$(this).removeClass("no-select");
		$(this).addClass("choose");
		//on met à jour la bordure
		$("#onglet_resa_2").css("border-left","none");
		$("#onglet_resa_1").css("border-right","1px solid #444");
		
		//reset du css
		document.forms["form_resa"].reset();
		$("#hidden_resa").attr('value','emp');
		var current=date_ini();
		$("#begin").attr("value",date_ini);
	});
	
	$("#onglet_resa_1").live('click',function(){
		$("#onglet_resa_2").removeClass("choose");
		$("#onglet_resa_2").addClass("no-select");
		$(this).removeClass("no-select");
		$("#onglet_resa_1").addClass("choose");
		//on met à jour la bordure
		$("#onglet_resa_1").css("border-right","none");
		$("#onglet_resa_2").css("border-left","1px solid #444");
		//reset du css
		document.forms["form_resa"].reset();
		$("#hidden_resa").attr('value','loc');
		var current=date_ini();
		$("#begin").attr("value",date_ini);
	});
		
	
});

$(window).scroll(function(){
var naviguator=whichBrs();

if (naviguator=="Safari")
{
var top_menu=document.body.scrollTop;
}
else
{
var top_menu=document.documentElement.scrollTop;
}
var neg=top_menu-2*top_menu;
if ($("#head").hasClass('min_menu'))
{
	if (top_menu<=77)
	{	
		$("#head").css('top',neg);
		$("#logo2").fadeOut("fast");
	}
	else
	{	
		$("#head").css('top',-77);
		$("#logo2").fadeIn("slow");
	}
}
else
{
	if (top_menu<=77)
	{
		if ($("#head").hasClass('min_menu')==false)
		{
		$("#head").css('top',neg);
		$("#logo2").fadeOut("fast");
		}
	}
	else
	{
		$("#head").stop(true,true).animate({top:-77},600,'easeOutQuad',function(){
			$(this).addClass('min_menu');
			$("#logo2").fadeIn("slow");
		});
	}
}
});


var current=date_ini();
$("#begin, #contact_date").attr("value",date_ini);

 function date_ini()
 {
 var maintenant = new Date();
  var jour=maintenant.getDate();
  if (jour==0){jour=7;}
  var annee=maintenant.getFullYear();
  var month=maintenant.getMonth();
  month=month+1;
  if(jour<10){jour = "0"+jour;}
  if(month<10){month = "0"+month;}
  return jour+"/"+month+"/"+annee;
 }
 
 function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'IE';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}

// partie diapo
var img_slider=new Array("./images/img_slider/img_1.png","./images/img_slider/img_2.png","./images/img_slider/img_3.png","./images/img_slider/img_4.png","./images/img_slider/img_5.png","./images/img_slider/img_6.png","./images/img_slider/img_7.png");  //tableau contenant le no
nbr=img_slider.length;
var img=1;
var diapo = setInterval('affiche()',6000);
var first_div=1;

function affiche()
{
	if (img==nbr-1){img=0;}	else{img=img+1;}
	var new_img="url("+img_slider[img]+") center top no-repeat";
	if (first_div==1)
	{
		$("#slider_back2").animate({opacity:1},800,'linear');
		$("#slider_back1").animate({opacity:0},800,'linear',function(){
			var index=$(this).css('z-index');
			index=index-2;
			$(this).css('z-index','index');
			$(this).css('background',new_img);
			// $(this).css('opacity','1');
		});
		first_div=2;
	}
	else
	{
		$("#slider_back1").animate({opacity:1},800,'linear');
		$("#slider_back2").animate({opacity:0},800,'linear',function(){
			var index=$(this).css('z-index');
			index=index-2;
			$(this).css('z-index','index');
			$(this).css('background',new_img);
			// $(this).css('opacity','1');
		});
		first_div=1;
	}
}

//animation du petit slider:
var current_mini=1;
var nb_img_mini=$("#mini-slider img").length;
$(".right-btn").stop(true,true).click(function(){
		if (current_mini==nb_img_mini){current_mini=1;}	else{current_mini=current_mini+1;}
		$("#mini-slider img").animate({opacity:0},500,'linear',function(){
			$(".img_mini_"+current_mini).animate({opacity:1},500,'linear');
		});
});

$(".left-btn").stop(true,true).click(function(){
		if (current_mini==1){current_mini=nb_img_mini;}	else{current_mini=current_mini-1;}
		$("#mini-slider img").animate({opacity:0},500,'linear',function(){
			$(".img_mini_"+current_mini).animate({opacity:1},500,'linear');
		});
});

//clique filtre promo
$("#promo-legend span:nth-child(3)").click(function(){

	if ($(this).hasClass("current_filtre")==false)
	{
	$("#promo-legend span").removeClass("current_filtre");
	var rech=$(".flash").parent();
	rech.insertBefore($("#promo-legend").next());	
	$(this).addClass("current_filtre");
	}
});

$("#promo-legend span:nth-child(2)").click(function(){
	
	if ($(this).hasClass("current_filtre")==false)
	{
	$("#promo-legend span").removeClass("current_filtre");
	var rech=$(".couple").parent();
	rech.insertBefore($("#promo-legend").next());	
	$(this).addClass("current_filtre");
	}
});

$("#promo-legend span:nth-child(1)").click(function(){
	
	if ($(this).hasClass("current_filtre")==false)
	{
	$("#promo-legend span").removeClass("current_filtre");
	var rech=$(".last").parent();
	rech.insertBefore($("#promo-legend").next());	
	$(this).addClass("current_filtre");
	}
});



//partie pour le plan interactif
$("#plan #info").mouseover(function(){
	$(".plan_acc").stop(true,true).fadeIn("fast");
})
$("#plan #info").mouseout(function(){
	$(".plan_acc").stop(true,true).fadeOut("fast");
})
$("#plan #jeuxvideo").mouseover(function(){
	$(".plan_jeux").stop(true,true).fadeIn("fast");
})
$("#plan #jeuxvideo").mouseout(function(){
	$(".plan_jeux").stop(true,true).fadeOut("fast");
})
$("#plan #course").mouseover(function(){
	$(".plan_epicerie").stop(true,true).fadeIn("fast");
})
$("#plan #course").mouseout(function(){
	$(".plan_epicerie").stop(true,true).fadeOut("fast");
})
$("#plan #snack").mouseover(function(){
	$(".plan_bar").stop(true,true).fadeIn("fast");
})
$("#plan #snack").mouseout(function(){
	$(".plan_bar").stop(true,true).fadeOut("fast");
})
$("#plan #sani").mouseover(function(){
	$(".plan_sanitaire").stop(true,true).fadeIn("fast");
})
$("#plan #sani").mouseout(function(){
	$(".plan_sanitaire").stop(true,true).fadeOut("fast");
})
$("#plan #bbq").mouseover(function(){
	$(".plan_barbec").stop(true,true).fadeIn("fast");
})
$("#plan #bbq").mouseout(function(){
	$(".plan_barbec").stop(true,true).fadeOut("fast");
})
$("#plan #swim").mouseover(function(){
	$(".plan_piscine").stop(true,true).fadeIn("fast");
})
$("#plan #swim").mouseout(function(){
	$(".plan_piscine").stop(true,true).fadeOut("fast");
})
$("#plan #kid").mouseover(function(){
	$(".plan_pato").stop(true,true).fadeIn("fast");
})
$("#plan #kid").mouseout(function(){
	$(".plan_pato").stop(true,true).fadeOut("fast");
})
$("#plan #airejeux").mouseover(function(){
	$(".plan_aire_jeux").stop(true,true).fadeIn("fast");
})
$("#plan #airejeux").mouseout(function(){
	$(".plan_aire_jeux").stop(true,true).fadeOut("fast");
})
$("#plan #pong").mouseover(function(){
	$(".plan_pingpong").stop(true,true).fadeIn("fast");
})
$("#plan #pong").mouseout(function(){
	$(".plan_pingpong").stop(true,true).fadeOut("fast");
})
$("#plan #etang").mouseover(function(){
	$(".plan_etang").stop(true,true).fadeIn("fast");
})
$("#plan #etang").mouseout(function(){
	$(".plan_etang").stop(true,true).fadeOut("fast");
})
$("#plan #emplacement_plan, #plan #emplacement_plan5").mouseover(function(){
	$(".plan_emp").stop(true,true).fadeIn("fast");
})
$("#plan #emplacement_plan, #plan #emplacement_plan5").mouseout(function(){
	$(".plan_emp").stop(true,true).fadeOut("fast");
})
$("#plan #emplacement_plan2").mouseover(function(){
	$(".plan_emp2").stop(true,true).fadeIn("fast");
})
$("#plan #emplacement_plan2").mouseout(function(){
	$(".plan_emp2").stop(true,true).fadeOut("fast");
})
$("#plan #emplacement_plan3").mouseover(function(){
	$(".plan_emp3").stop(true,true).fadeIn("fast");
})
$("#plan #emplacement_plan3").mouseout(function(){
	$(".plan_emp3").stop(true,true).fadeOut("fast");
})
$("#plan #emplacement_plan4").mouseover(function(){
	$(".plan_emp4").stop(true,true).fadeIn("fast");
})
$("#plan #emplacement_plan4").mouseout(function(){
	$(".plan_emp4").stop(true,true).fadeOut("fast");
})
$("#plan #kiwi, #plan #kiwi2, #plan #kiwi3, #plan #kiwi4").mouseover(function(){
	$(".plan_kiwi2").stop(true,true).fadeIn("fast");
})
$("#plan #kiwi, #plan #kiwi2, #plan #kiwi3, #plan #kiwi4").mouseout(function(){
	$(".plan_kiwi2").stop(true,true).fadeOut("fast");
})
$("#plan #plan_mobil").mouseover(function(){
	$(".plan_mobil").stop(true,true).fadeIn("fast");
})
$("#plan #plan_mobil").mouseout(function(){
	$(".plan_mobil").stop(true,true).fadeOut("fast");
})
$("#plan #plan_mobil2, #plan #plan_mobil3").mouseover(function(){
	$(".plan_mobil2").stop(true,true).fadeIn("fast");
})
$("#plan #plan_mobil2, #plan #plan_mobil3").mouseout(function(){
	$(".plan_mobil2").stop(true,true).fadeOut("fast");
})
$("#plan #plan_mobil4").mouseover(function(){
	$(".plan_mobil3").stop(true,true).fadeIn("fast");
})
$("#plan #plan_mobil4").mouseout(function(){
	$(".plan_mobil3").stop(true,true).fadeOut("fast");
})

//like des posts
$(".left-side .like").click(function(){

	var toto=$(this).children('img').attr('id');
	var dataString='id='+toto;
	var select=$(this).parent();
	var toto2=$(this);
	$.ajax
		({
			type: "POST",
			url: "ajax/vote.php",
			data: dataString,
			success: function(html)
			{
				if (html!='aie')
				{
				select.before(html);
				toto2.css("background","rgba(16,69,126,0.67) repeat");
				toto2.children('img').css("display","block");
					$(".notif_news").animate({width:104},500,'easeOutCubic');
				}				
			}
		});
});

$(".notif_news").live('click',function(){
	$(this).fadeOut("normal",function(){
		$(this).remove();
	});
});

$(".share").click(function(){
var totoclick=$(this);
var areok=$(this).parent().prev().width();
// alert(areok);
	if (areok==104)
	{
		$(this).parent().prev().fadeOut('normal',function(){
			$(this).remove();
			var toto=totoclick.parent().prev();
			if(toto.css('display')=='none')
			{
			toto.stop(true,true).fadeIn("normal");
			}
			else
			{
			toto.fadeOut("normal");
			}
		});
	}
	else
	{
	var toto=$(this).parent().prev();
	if(toto.css('display')=='none')
	{
	toto.stop(true,true).fadeIn("normal");
	}
	else
	{
	toto.fadeOut("normal");
	}
	
	}
	
	
});


$("#sub-news").click(function(){

	var toto=$("#news").val();
	var what=validation(toto);
	var dataString='mail='+toto;
	if (what)
	{
		$.ajax
		({
			type: "POST",
			url: "ajax/newsletter.php",
			data: dataString,
			success: function(html)
			{
				if ((html==0) || (html==1))
				{
					$("#news").stop(true,true).animate({backgroundColor:'#ffbcbc'}, 400);
					$("#news").delay(6500).animate({backgroundColor:'#f7f7f7'}, 1500);
				}
				else
				{
					$("#news").stop(true,true).animate({backgroundColor:'#b3ffb3'}, 400);
					$("#news").delay(6500).animate({backgroundColor:'#f7f7f7'}, 600);
					
				}
			}
		});

	}
	else
	{
		$("#news").stop(true,true).animate({backgroundColor:'#ffbcbc'}, 400);
		$("#news").delay(6500).animate({backgroundColor:'#f7f7f7'}, 1500);
	}
	
});

// $("#news, #contact_prenom, #contact_nom, #contact_adr, #contact_cp, #contact_ville, #contact_pays, #contact_mail").live('click',function(){
		
		// $(this).stop(true,true).animate({backgroundColor:'#f7f7f7'}, 400);
	// });
	
$("#contact_prenom, #contact_nom, #contact_pays, #contact_mail, #contact_objet, #contact_rem").live('click',function(){
		
		$("#contact_prenom").css('border-color','#c7c7c7');
		$("#contact_nom").css('border-color','#c7c7c7');
		$("#contact_objet").css('border-color','#c7c7c7');
		$("#contact_pays").css('border-color','#c7c7c7');
		$("#contact_mail").css('border-color','#c7c7c7');
		$("#contact_rem").css('border-color','#c7c7c7');
		$(".fail_contact").fadeOut(400);
	});


function validation(email)
		{
   			var verif 	= /^[a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/
   			if (verif.exec(email) == null)
			{
				return false;
			}
			else
			{
				return true;
			}	


		}

		//partie deroule pour plus d'info sur le mobil concerné
$(".more-info-mobil").stop(true,true).click(function(){

	if($(this).hasClass('deroule')==false)
	{
		var toto=$(".info-mobil p").height();
		$(".info-mobil").stop(true,true).animate({height:toto}, 750, 'easeInOutCubic');
		$(".img_more_info").empty();
		$(".img_more_info").append('- ');
		$(this).css('background','none');
		$(this).addClass('deroule');
	}
	else
	{
		$(".info-mobil").stop(true,true).animate({height:163}, 750, 'easeInOutCubic');
		$(".img_more_info").empty();
		$(".img_more_info").append('+ ');
		$(this).css('background','url(./images/more_points.png) no-repeat');
		$(this).removeClass("deroule");
	}
	
});

//changement du descriptif de mobil
$(".current_mobil_no").live('click',function(){
	var id_produit=$(this).attr('id');
	$("#mobil-list li .current").addClass("current_mobil_no");
	$("#mobil-list li .current").removeClass("current");
	$(this).addClass("current");
	$(this).removeClass("current_mobil_no");
	var dataString='id_produit='+id_produit;
	$.ajax
		({
			type: "POST",
			url: "ajax/new_view_mobil.php",
			data: dataString,
			success: function(html)
			{
				$("#sub_mobil_preview").fadeOut("normal",function(){
					$("#loader_mobil").fadeIn('normal');
					$("#mobil-preview").remove();
					$("#sub_mobil_preview").append(html);
					var new_img=$("#mobil-preview img:nth-child(1)").attr('src');
					var imamage = new Image();
					imamage.src=new_img;
					imamage.onload=function(){
						$("#loader_mobil").fadeOut('normal', function(){
							$("#sub_mobil_preview").fadeIn("normal");
						});
					}					
				});
			}
		});
		$.ajax
		({
			type: "POST",
			url: "ajax/new_desc_mobil.php",
			data: dataString,
			success: function(html)
			{
				$("#sub_mobil_desc").fadeOut("normal",function(){
				
					$("#mobil-desc").remove();
					$("#sub_mobil_desc").append(html);
					$(this).fadeIn("normal");
					
				});
			}
		});
});
$("#logo2").mouseover(function(){
	$(this).animate({opacity:1}, 400);
});
$("#logo2").mouseout(function(){
	$(this).animate({opacity:0.9}, 400);
});
$("#nav-slider-mobil p").live("click",function(){
	if($(this).hasClass('min_arrow1'))
		{
			var toto=$(".current-pic").prev('span').attr('id');
			if(isNaN(toto)){toto=$("#nav-slider-mobil span:last").attr('id');}
			$("#mobil-preview img").not("#mobil-preview #img_mobil_"+toto).fadeOut("normal");
			$("#mobil-preview #img_mobil_"+toto).fadeIn("normal");
			$("#nav-slider-mobil span").removeClass("current-pic");
			$("#nav-slider-mobil span:eq("+toto+")").addClass('current-pic');
		}
		if($(this).hasClass('min_arrow2'))
		{
			var toto=$(".current-pic").next('span').attr('id');
			if(isNaN(toto)){toto=$("#nav-slider-mobil span:first").attr('id');}
			$("#mobil-preview img").not("#mobil-preview #img_mobil_"+toto).fadeOut("normal");
			$("#mobil-preview #img_mobil_"+toto).fadeIn("normal");
			$("#nav-slider-mobil span").removeClass("current-pic");
			$("#nav-slider-mobil span:eq("+toto+")").addClass('current-pic');
		}

});

$("#nav-slider-mobil span").live("click",function(){
	var id=$(this).attr("id");
	$("#mobil-preview img").not("#mobil-preview #img_mobil_"+id).fadeOut("normal");
	$("#mobil-preview #img_mobil_"+id).fadeIn("normal");
	$("#nav-slider-mobil span").removeClass("current-pic");
	$(this).addClass('current-pic');
});

function contact_resa()
{
	var nom=$("#contact_nom").val();
	var prenom=$("#contact_prenom").val();
	var pays=$("#contact_pays").val();
	var mail=$("#contact_mail").val();
	var objet=$("#contact_objet").val();
	var toto=validation(mail);
	if ((nom=="")||(prenom=="")||(objet=="")||(pays=="")||(toto==false))
	{
		if (nom==""){$("#contact_nom").stop(true,true).animate({borderColor:'#ff7777'}, 400);$("#contact_nom").delay(6500).animate({borderColor:'#c7c7c7'}, 1500);}
		if (prenom==""){$("#contact_prenom").stop(true,true).animate({borderColor:'#ff7777'}, 400);$("#contact_prenom").delay(6500).animate({borderColor:'#c7c7c7'}, 1500);}
		if (objet==""){$("#contact_objet").stop(true,true).animate({borderColor:'#ff7777'}, 400);$("#contact_objet").delay(6500).animate({borderColor:'#c7c7c7'}, 1500);}
		if (pays==""){$("#contact_pays").stop(true,true).animate({borderColor:'#ff7777'}, 400);$("#contact_pays").delay(6500).animate({borderColor:'#c7c7c7'}, 1500);}
		if (toto==false){ $("#contact_mail").stop(true,true).animate({borderColor:'#ff7777'}, 400);$("#contact_mail").delay(6500).animate({borderColor:'#c7c7c7'}, 1500);}
		$(".fail_contact").stop(true,true).fadeIn(450);
		$(".fail_contact").delay(8500).fadeOut(1500);
		return false;
	}
	else
	{
		return true;
	}
}

function contact_avis()
{
	var nom=$("#contact_nom").val();
	var prenom=$("#contact_prenom").val();
	var remarque=$("#contact_rem").val();
	if ((nom=="")||(prenom=="")|| (remarque==""))
	{
		if (nom==""){$("#contact_nom").stop(true,true).animate({borderColor:'#ff7777'}, 400);$("#contact_nom").delay(6500).animate({borderColor:'#c7c7c7'}, 1500);}
		if (prenom==""){$("#contact_prenom").stop(true,true).animate({borderColor:'#ff7777'}, 400);$("#contact_prenom").delay(6500).animate({borderColor:'#c7c7c7'}, 1500);}
		if (remarque==""){$("#contact_rem").stop(true,true).animate({borderColor:'#ff7777'}, 400);$("#contact_rem").delay(6500).animate({borderColor:'#c7c7c7'}, 1500);}
		$(".fail_contact").stop(true,true).fadeIn(450);
		$(".fail_contact").delay(8500).fadeOut(1500);
		return false;
	}
	else
	{
		return true;
	}
}

$(".span_brochure").click(function(){

	if ($(this).hasClass('current_contact')==false)
	{
		$(".span_resa").removeClass('current_contact');
		$(".span_info").removeClass('current_contact');
		$(this).addClass('current_contact');
		var dataString='id=2';
		$(".current_form img").animate({left:269}, 600);
		$.ajax
		({
			type: "POST",
			url: "ajax/contact2.php",
			data: dataString,
			success: function(html)
			{
					$("#div_form_contact").fadeOut("normal",function(){
						$(this).empty();
						$(this).append(html);
						$(this).fadeIn("normal",function(){
							
						});
					});
			}
		});	
	}
});

$(".span_resa").click(function(){

	if ($(this).hasClass('current_contact')==false)
	{
		$(".span_brochure").removeClass('current_contact');
		$(".span_info").removeClass('current_contact');
		$(this).addClass('current_contact');
		var dataString='id=1';
		$(".current_form img").animate({left:60}, 600);
		$.ajax
		({
			type: "POST",
			url: "ajax/contact2.php",
			data: dataString,
			success: function(html)
			{
					$("#div_form_contact").fadeOut("normal",function(){
						$(this).empty();
						$(this).append(html);
						$(this).fadeIn("normal",function(){
								$("#contact_date").datepicker({
										
										altFormat: 'yy-mm-dd',
										dateFormat: 'dd/mm/yy',
										dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
										dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
										monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
										monthNamesShort: ['Jan','Fev','Mar','Avr','Mai','Jui','Jui','Aoû','Sep','Oct','Nov','Dec'],
										firstDay: 1,
										minDate: 0,
										showOn: 'focus',
										// maxDate: "+1M +10D" 
									});
						});
					});
			}
		});	
	}
});

$(".span_info").click(function(){

	if ($(this).hasClass('current_contact')==false)
	{
		$(".span_brochure").removeClass('current_contact');
		$(".span_resa").removeClass('current_contact');
		$(this).addClass('current_contact');
		var dataString='id=3';
		$(".current_form img").animate({left:439}, 600);
		$.ajax
		({
			type: "POST",
			url: "ajax/contact2.php",
			data: dataString,
			success: function(html)
			{
					$("#div_form_contact").fadeOut("normal",function(){
						$(this).empty();
						$(this).append(html);
						$(this).fadeIn("normal",function(){
							
						});
					});
			}
		});	
	}
});

