$(document).ready(function(){
	$(".lien-ft").rollOver_lien_krealid();
	$(".contact").rollOver_lien_krealid();
	//
	//$('footer form').attr('id','formNewsletter');
	//
	if($(window).width() < $('footer section').width()){
		$('body').css({'overflow':'auto'});
	}else{
		$('body').css({'overflow':'hidden'});
	}
	$('#content').css({'width':$(window).width(),'height':$(window).height()});
	$('#detail').css({'width':$(window).width(),'height':$(window).height()});
	//
	var posNR = $('.nos-rea').offset();
	$('.contact').css({'left':posNR.left+'px'});
	//
	var posC = $('.confiance').offset();
	$('.facebook').css({'left':( (posC.left+$('.confiance').width()) - ($('.facebook').width()*5))+'px'});
	$('.twitter').css({'left':( (posC.left+$('.confiance').width()) - $('.twitter').width())+'px'});
	//
	var carrousel_footer = $('.carrousel-footer').find('ol').html();
	$('.carrousel-footer').find('ol').html(carrousel_footer+carrousel_footer);
	$('.carrousel-footer ol').css({'width':($('.carrousel-footer ol .item').length*$('.carrousel-footer ol .item').width())+'px'});
	//
	var footer_over = true;
	$('footer').mouseenter(function(){
		if(footer_over){
			footer_over = false;
			$(this).animate({'bottom':0});
			$(this).find('.toggle').css({'background-position':'center bottom'});
		}
	}).mouseleave(function(){
		$(this).animate({'bottom':-(($(this).find('section').height()+$(this).find('.adresse').height())+1)+'px'},function(){footer_over = true});
		$(this).find('.toggle').css({'background-position':'center top'});
	})
	//
	$('.roll-rea:first').css({'margin-right':10+'px'})
	$('.roll-rea').each(function(){
		var content = $(this).html();
		$(this).html(content+'<span>'+$(this).attr('title')+'</span>');
	});
	//
	$('.roll-rea').mouseenter(function(){
		$(this).find('span').animate({'opacity':1},200);
	}).mouseleave(function(){
		$(this).find('span').animate({'opacity':0},200);
	});
	//
	init_carrousel_footer();
	//
	$('#email').focus(function(){
		$(this).attr('style','')
		$('#message').html('');
	}).click(function(){
		$(this).attr('style','')
		$('#message').html('');
	});
	//
	$('#valid-form').click(function(){
		var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
		var valid = true;
		var message = '';
		$('#message').html(message);
		if($('#email').val() == '' && valid){
			message = '<span class="error">Merci de remplir ce champs.</span>';
			valid = false;
		}
		if(!$('#email').val().match(reg) && valid){
			message = '<span class="error">Cette adresse mail est invalide.</span>';
			valid = false;
		}
		if(!valid){
			$('#email').css({'border-color':'red'});
			$('#message').html(message);
		}else{
			message = '<span class="valid">Votre demande est acceptée.</span>';
			var form_data = {
				email: $('#email').val()
			};
			$.ajax({
				url: 'index.php/accueil/submit',
				type: 'POST',
				data: form_data,
				success: function() {
					$('#email').attr('value','');
					//$('#email').css({'border-color':'#eaff00'});
					$('#message').html(message);
					init_message_form();
				}
			});
			//$('#formNewsletter').submit();
		}
		return false;
	});
	//
	
				var largeurVideo = $('iframe').attr('width');
				var hauteurVideo = $('iframe').attr('height');
				var ratioVideo = hauteurVideo/largeurVideo;
				$('iframe').css({'position':'absolute','width':largeurVideo+'px','height':hauteurVideo+'px','left':($(window).width() - largeurVideo)/2+'px','top':($(window).height() - hauteurVideo)/2+'px'});
				$('iframe').removeAttr('width');
				$('iframe').removeAttr('height');
				if($(window).width() < (largeurVideo - 100)){
					largeurVideo = $(window).width() - 100;
					hauteurVideo = largeurVideo*ratioVideo;
					//$('#video_voeux').attr('width',largeurVideo);
					//$('#video_voeux').attr('height',hauteurVideo);
					$('iframe').css({'width':largeurVideo+'px','height':hauteurVideo+'px','left':($(window).width() - largeurVideo)/2+'px','top':($(window).height() - hauteurVideo)/2+'px'});
				}
				if($(window).height() < (hauteurVideo - 100)){
					hauteurVideo = $(window).height() - 100;
					largeurVideo = hauteurVideo*ratioVideo;
					//$('#video_voeux').attr('width',largeurVideo);
					//$('#video_voeux').attr('height',hauteurVideo);
					$('iframe').css({'width':largeurVideo+'px','height':hauteurVideo+'px','left':($(window).width() - largeurVideo)/2+'px','top':($(window).height() - hauteurVideo)/2+'px'});
				}
	
	
});
$(window).resize(function(){
	if($(window).width() < $('footer section').width()){
		$('body').css({'overflow':'auto'});
	}else{
		$('body').css({'overflow':'hidden'});
	}
	//
	var posNR = $('.nos-rea').offset();
	$('.contact').css({'left':posNR.left+'px'});
	//
	var posC = $('.confiance').offset();
	$('.facebook').css({'left':( (posC.left+$('.confiance').width()) - ($('.facebook').width()*5))+'px'});
	$('.twitter').css({'left':( (posC.left+$('.confiance').width()) - $('.twitter').width())+'px'});
	//
	$('#content').css({'width':$(window).width(),'height':$(window).height()});
	$('#detail').css({'width':$(window).width(),'height':$(window).height()});
	//
	
				var largeurVideo = $('iframe').width();
				var hauteurVideo = $('iframe').height();
				var ratioVideo = hauteurVideo/largeurVideo;	
				if($(window).width() < 1280){
					largeurVideo = $(window).width() - 100;
					hauteurVideo = ratioVideo*largeurVideo;
					//$('#video_voeux').attr('width',largeurVideo);
					//$('#video_voeux').attr('height',hauteurVideo);
					$('iframe').css({'width':largeurVideo+'px','height':hauteurVideo+'px','left':($(window).width() - largeurVideo)/2+'px','top':($(window).height() - hauteurVideo)/2+'px'});
				}else{
					$('iframe').css({'width':1280+'px','height':720+'px','left':($(window).width() - 1280)/2+'px','top':($(window).height() - 720)/2+'px'});
				}
	
	
}).resize();
function function_carrousel_footer(){
	$('.carrousel-footer ol').animate({'left':-(($('.carrousel-footer ol .item').length-2)*$('.carrousel-footer ol .item').width())+'px'},12000,'linear',init_carrousel_footer);
}
function init_carrousel_footer(){
	$('.carrousel-footer ol').css({'left':0});
	function_carrousel_footer();
}
function init_message_form(){
	$('#email').attr('style','')
	$('#message').find('span').animate({'opacity':0},8000);
	//$('#message').delay(3000).html('');
}
