
function theRotator() {
	//Set the opacity of all images to 0
	$('div.imagerotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div.imagerotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div.imagerotator ul li.show')?  $('div.imagerotator ul li.show') : $('div.imagerotator ul li:first'));

    if ( current.length == 0 ) current = $('div.imagerotator ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.imagerotator ul li:first') :current.next()) : $('div.imagerotator ul li:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
    //var rndNum = Math.floor(Math.random() * sibs.length );
    //var next = $( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 4000);

	//Hide the current image
	current.animate({opacity: 0.0}, 4000)
	.removeClass('show');
	
};



$(document).ready(function() {		
	//Rotation des images header
	theRotator();
	$('div.imagerotator').fadeIn(1000);
    $('div.imagerotator ul li').fadeIn(1000); // tweek for IE
	// Focus photos des voyants
		$('.lesvoyants_right').children().hover(function() {
		$(this).siblings().stop().animate({'opacity': 0.4}, 'fast');
	}, function() {
		$(this).siblings().stop().animate({'opacity': 1.0}, 'fast');
	});

	
	$('#envoyerdemande').click(function () {
	
	var nom = $('input[name=nom]');
	var prenom = $('input[name=prenom]');
	var journaissance = $('select[name=journaissance]');
	var moisnaissance = $('select[name=moisnaissance]');
	var anneesnaissance = $('select[name=anneesnaissance]');
	var pays = $('select[name=pays]');
	var email = $('input[name=email]');
	 var question = $('textarea[name=question]');
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	var isValid = new Boolean(true); 
	if (prenom.val()=='') { prenom.addClass('labelalert'); isValid = false; } else prenom.removeClass('labelalert');
	 if (journaissance.val()=='' || moisnaissance.val()=='' || anneesnaissance.val()=='') { $('#selectdate').addClass('labelalert');  isValid = false; } else { $('#selectdate').removeClass('labelalert'); $('#selectdate').removeClass('noleftpad'); }
	 if (pays.val()=='') { $('#selectpays').addClass('labelalert');  isValid = false; } else { $('#selectpays').removeClass('labelalert'); $('#selectpays').removeClass('noleftpad'); }
		if ( !filter.test(email.val()) ) { email.addClass('labelalert');  isValid = false; } else email.removeClass('labelalert');
	
	if(!isValid) {return false;}
	
		 var toutlesinfos = 'nom=' + encodeURIComponent(nom.val()) + '&prenom=' + encodeURIComponent(prenom.val()) + '&pays=' + encodeURIComponent(pays.val()) + '&datenaissance=' + anneesnaissance.val() + '-' + moisnaissance.val() + '-' + journaissance.val() + '&email=' + encodeURIComponent(email.val()) + '&question=' + encodeURIComponent(question.val());
	// $('.texteform').attr('disabled','true');
$('.mailicone').hide();
$('.chargementicone').show();	
	//  alert(toutlesinfos);
	//return false;
	
	$.ajax({
			//this is the php file that processes the data and send mail
			url: "/voyance-gratuite/envoidemande.php",	
			
			//GET method is used
			type: "POST",

			//pass the data			
			data: toutlesinfos,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {				

				// alert(html);
				if (html==1) {					

					$('#formdemandemail').fadeOut('slow');					
					
					 var obj = document.getElementById('esp_txt_drt2');
					obj.style.height = "290px";
					
					$('#demandecomplet').fadeIn('slow');
										

				} else alert('Une erreur inattendue est survenue ! Merci de rééssayer plus tard');				
			}		
		});
		return false;
	});
	
	
		$('#envoyercontact').click(function () {
	
	var nom = $('input[name=nom]');
	var prenom = $('input[name=prenom]');
	var pays = $('select[name=pays]');
	var email = $('input[name=email]');
	 var question = $('textarea[name=question]');
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	var isValid = new Boolean(true); 
	if (prenom.val()=='') { prenom.addClass('labelalert'); isValid = false; } else prenom.removeClass('labelalert');
	 if (pays.val()=='') { $('#selectpays').addClass('labelalert');  isValid = false; } else { $('#selectpays').removeClass('labelalert'); $('#selectpays').removeClass('noleftpad'); }
		if ( !filter.test(email.val()) ) { email.addClass('labelalert');  isValid = false; } else email.removeClass('labelalert');
	
	if(!isValid) {return false;}
	
		 var toutlesinfos = 'nom=' + encodeURIComponent(nom.val()) + '&prenom=' + encodeURIComponent(prenom.val()) + '&pays=' + encodeURIComponent(pays.val()) + '&email=' + encodeURIComponent(email.val()) + '&question=' + encodeURIComponent(question.val());
	// $('.texteform').attr('disabled','true');
$('.mailicone').hide();
$('.chargementicone').show();	
	//  alert(toutlesinfos);
	//return false;
	
	$.ajax({
			//this is the php file that processes the data and send mail
			url: "/envoicontact.php",	
			
			//GET method is used
			type: "POST",

			//pass the data			
			data: toutlesinfos,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {				

				// alert(html);
				if (html==1) {					

					$('#formdemandemail').fadeOut('slow');					
					
					 var obj = document.getElementById('esp_txt_drt2');
					obj.style.height = "290px";
					
					$('#contactcomplet').fadeIn('slow');
					
					

				} else alert('Une erreur inattendue est survenue ! Merci de rééssayer plus tard');				
			}		
		});
		return false;
	});
});


