// remap jQuery to $
(function($){

 	// Function ScrollTo (easing)
	$('.scrollMenu a').bind('click',function(event){
		var $anchor = $(this);

		$('html, body').stop().animate({
			scrollTop: $($anchor.attr('href')).offset().top-90
		}, 900,'easeOutExpo');
		
		event.preventDefault();
		
	});
	
	// autoscrolling if hash exist
	 if(window.location.hash) {
     	var $hash = window.location.hash; 
		 
		 $(document.body).animate({
  		  	'scrollTop':   $($hash).offset().top-90
		 }, 900,'easeOutExpo');
		 
  	  }
  	  
  	 
  	  
	$("#main_nav").find("li").eq(0).hover(function(event) {
		 $(this).stop().animate({ opacity: 0.5 }, {duration: 'slow',easing: 'easeOutQuint'}); 
			},function(){$(this).stop().animate({ opacity: 1 }, {duration: 'slow',easing: 'easeOutQuint'});
			   });
	
	$('#news_box').hover(function(event) {
		 $(this).stop().animate({ opacity: 0.5 }, {duration: 'slow',easing: 'easeOutQuint'}); 
			},function(){$(this).stop().animate({ opacity: 1 }, {duration: 'slow',easing: 'easeOutQuint'});
			   });
			   
	$('#stores_box').hover(function(event) {
		 $(this).stop().animate({ opacity: 0.5 }, {duration: 'slow',easing: 'easeOutQuint'}); 
			},function(){$(this).stop().animate({ opacity: 1 }, {duration: 'slow',easing: 'easeOutQuint'});
			   });
	
	$('#collection li').hover(function(event) {
		 $(this).stop().animate({ opacity: 0.3 }, {duration: 'slow',easing: 'easeOutQuint'}); 
			},function(){$(this).stop().animate({ opacity: 1 }, {duration: 'slow',easing: 'easeOutQuint'});
			   });

})(window.jQuery);


function check_day() {
	if (document.getElementById('disponibilite_1').checked == true) {
		document.getElementById('div_day_1').style.display = 'block';
		document.getElementById('div_day_2').style.display = 'block';
	} else {
		document.getElementById('div_day_1').style.display = 'none';
		document.getElementById('div_day_2').style.display = 'none';
		document.getElementById('disponibilite_4').checked = false;
		document.getElementById('disponibilite_7').checked = false;
		document.getElementById('disponibilite_1').checked = false;
	}
}

function check_evening() {
	if (document.getElementById('disponibilite_2').checked == true) {
		document.getElementById('div_evening_1').style.display = 'block';
		document.getElementById('div_evening_2').style.display = 'block';
	} else {
		document.getElementById('div_evening_1').style.display = 'none';
		document.getElementById('div_evening_2').style.display = 'none';
		document.getElementById('disponibilite_5').checked = false;
		document.getElementById('disponibilite_8').checked = false;
	}
}

function check_night() {
	if (document.getElementById('disponibilite_3').checked == true) {
		document.getElementById('div_night_1').style.display = 'block';
		document.getElementById('div_night_2').style.display = 'block';
	} else {
		document.getElementById('div_night_1').style.display = 'none';
		document.getElementById('div_night_2').style.display = 'none';
		document.getElementById('disponibilite_6').checked = false;
		document.getElementById('disponibilite_9').checked = false;
	}
}


function newsletter_inscription() {
	var email = $('#email').val();
	


if ($("input[name='newsletter_lang']:checked").val() == 'fr') {
 var language_selected = 'fr';
}
else{
 var language_selected = 'en';
}
	
	
	var email_filter = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.) {2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);




	if (email == '' || !email_filter.test(email)) {
		$('#email_exists').hide();
		$('#email_success').hide();
		$('#email_error').fadeIn();
	}
	else {
		var data_string = 'email=' + email + '&lang=' + language_selected;
		$.ajax({
			type: 'GET',
			url: 'infolettre_inscription.php',
			data: data_string,

			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert(errorThrown);
			},

			success: function(msg) {
				//$('#debug').html(msg);
				if (msg != '') {
					if (msg == 'WRONG_EMAIL') {
						$('#email_success').hide();
						$('#email_exists').hide();
						$('#email_error').fadeIn();
					}
					else if (msg == 'EMAIL_EXISTS') {
						$('#email_success').hide();
						$('#email_error').hide();
						$('#email_exists').fadeIn();
					}
					else if (msg == 'OK') {
						$('#email_error').hide();
						$('#email_exists').hide();
						$('#email_success').fadeIn();
					}
				}
			}
		});
	}
}

