$(function() {
	
//webroot = "/reputation-information/";
webroot = "/";
slidenum = 1;
	
	valnom = 'Nom/Prénom OU Société';
	valmail = 'E-mail';
	valtel = 'Téléphone';
	valdesc = 'Exposez votre problématique ou vos attentes en terme d\'E-reputation et vous recevrez rapidement une réponse qui vous aidera à avancer.';
				
	
	$('.QapTcha').QapTcha({autoRevert:true});
	
	$('#m'+page).addClass("menubg");
	
	$('.m5').click(function() {
		
		$('html, body').animate( { scrollTop: 1600 }, 1000 );
		return false;
	});
	
	$('.sliderdescb a.m2').click(function() {
		
		$('html, body').animate( { scrollTop: 680 }, 1000 );
		return false;
	});
	
	/* slider */
	toslide = setInterval("slide()",6000); 
	
	$('#stxt').mouseover(function () {
		clearInterval(toslide);
	}).mouseout(function() {
		toslide = setInterval("slide()",6000); 
	});
	
	$('#s1, #s2, #s3').click(function() {
		
		
		
		$('#slider_navigation img').attr('src',webroot+'css/img/slide_inactive.png');
		$(this).attr('src',webroot+'css/img/slide_active.png');
		
		
		$('.slidertxt').fadeOut();	
		
		if($(this).attr('id') == 's1') slidenum = 1;
		else if($(this).attr('id') == 's2') slidenum = 2;
		else if($(this).attr('id') == 's3') slidenum = 3;
		
		setTimeout("$('#slidertxt'+slidenum).fadeIn(200)",400);
	});
	
	
	
	$('#menu a').mouseover(function() {
		$('#menu a').removeClass("menubg");
		$(this).addClass("menubg");
	}).mouseout(function() {
		$(this).removeClass("menubg");
		$('#m'+page).addClass("menubg");
	});
	
	$('#vid1').click(function() {
		
		$('#thevid').html('<iframe src="http://player.vimeo.com/video/28304080?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="500" height="370" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>');
		
	});
	
	
	$('#vid2').click(function() {
		
		$('#thevid').html('<iframe src="http://player.vimeo.com/video/19658085?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="500" height="370" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>');
		
	});
	
	
	$('#vid3').click(function() {
		
		$('#thevid').html('<iframe src="http://player.vimeo.com/video/30126371?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="500" height="370" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>');
		
	});
	
	$("#videos a").fancybox();
	
	
	$('#nom').focus(function() {

		if($(this).val() == "Nom/Prénom OU Société") $(this).val('');
	}).focusout(function() {
		if($(this).val() == "") $(this).val(valnom);
	});
	
	$('#mail').focus(function() {

		if($(this).val() == "E-mail") $(this).val('');
	}).focusout(function() {
		if($(this).val() == "") $(this).val(valmail);
	});
	
	$('#tel').focus(function() {

		if($(this).val() == "Téléphone") $(this).val('');
	}).focusout(function() {
		if($(this).val() == "") $(this).val(valtel);
	});
	
	$('#desc').focus(function() {

		if($(this).val() == valdesc) $(this).val('');
	}).focusout(function() {
		if($(this).val() == "") $(this).val(valdesc);
	});
	
	
	//contact form
	
	$('form .d').live("click", (function() {
		
		if($('#nom').val() != valnom && $('#mail').val() != valmail && $('#tel').val() != valtel && $('#desc').val() != valdesc &&
		$('#nom').val().length > 3 && $('#mail').val().length > 6 && $('#tel').val().length > 6 && $('#desc').val().length > 10) {
			
			$.ajax({
				url: webroot+"mail.php", 
				async: true,
				type: 'POST',
				data: $("#contactform").serialize(),
				success: function(thedata) { 
					
					$('#nom').val(valnom);
					$('#mail').val(valmail);
					$('#tel').val(valtel);
					$('#desc').val(valdesc);
					
					$('.QapTcha').html('');
					$('.QapTcha').QapTcha({autoRevert:true});
					$('#confirm_notif').html('Merci, votre demande a bien été envoyée');
					$('#confirm_notif').fadeIn();
					setTimeout("$('#confirm_notif').fadeOut();encours = false;",4000);
				}
				
			});
		}
		else {
			
			$('#error_notif').html('Tous les champs sont obligatoires');
			$('#error_notif').fadeIn();
			setTimeout("$('#error_notif').fadeOut();encours = false;",4000);
		}
		
	}));

});



function slide() {

	$('.slidertxt').fadeOut();	
	slidenum += 1;
	if(slidenum > 3) slidenum = 1;
	setTimeout("$('#slidertxt'+slidenum).fadeIn(200)",400);
	
	$('#slider_navigation img').attr('src',webroot+'css/img/slide_inactive.png');
	$('#s'+slidenum).attr('src',webroot+'css/img/slide_active.png');

	
}
