
/******
 *
 * VARIABLES INIT
 * 
 *****/
var visuel; 
var logo; 
var vInit = new Object();
var lInit = new Object();
/******
 *
 * ON DOCUMENT READY
 * 
 *****/
$(document).ready(function(){

	
	var firstVal = $(".champTxt").val();
	$(".champTxt").focus(function(){
		if($(".champTxt").val() == firstVal){
			$(".champTxt").val("");
		}
	}).blur(function(){      
		if($(".champTxt").val() == ""){
			$(".champTxt").val(firstVal);
		}
	});
	$("#alertMail").submit(function(){
	
	   
		
		var elmt = $(this),
		mail = $(".champTxt").val(); 
		
		elmt.find(".feedback").remove();
			
		var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
		if(reg.test(mail)) {  
			$.ajax({
				type: "POST",
				url: "mail.php",
				data: "mail="+mail,
				success: function(e){
					if(e == "OK") {
						elmt.append('<span class="feedback valid">Votre email a bien été enregistré</span>');
					} else {
						elmt.append('<span class="feedback valid">'+e+'</span>');
					}
				}
			});
		} else {     
			elmt.append('<span class="feedback error">Votre email n\'est pas valide</span>');          
			return false;
		} 
		
		return false;
			
	});

	visuel = $("#visuel .visuel1, #visuel .visuel2, #visuel .visuel3, #visuel .visuel4, #visuel .visuel5");
	logo = $("#visuel .logo");
	$("body").append('<div id="overlay" />');	

});
/******
 *
 * ON IMAGES LOADED
 * 
 *****/
$(window).load(function(){
	initDimensions(); 
    resizeImage();  
	initAnimation();
});
/******
 *
 * WINDOW RESIZE
 * 
 *****/
 $(window).resize(function(){
     resizeImage();
 });
/******
 *
 * INITIALIZE ANIMATION
 * 
 *****/
function initAnimation(){      
	var overlay = $("#overlay");
	var visuel1 = $("#visuel .visuel1");
	var visuel2 = $("#visuel .visuel2");
	
	$("#visuel .visuel3, #visuel .visuel4, #visuel .visuel5").fadeTo(0, 0);
	var logo = $("#visuel .logo");
	var content = $("#content .wrapper2");
	visuel1.fadeTo(0,0); 
	visuel2.fadeTo(0,0);
	
	logo.find(".lt").css({
		"left" : "28.3%",
		"top" : "35%"
	});
	logo.find(".rt").css({
		"right" : "40%",
		"top" : "35%"
	});
	logo.find(".rb").css({
		"right" : "26.5%",
		"bottom" : "35%"
	});
	logo.find(".lb").css({
		"left" : "35%",
		"bottom" : "35%"
	}).fadeTo(0, 0);	
	
	content.css({
		"position" : "relative",
		"left" : -550
	});
	overlay.fadeOut(800, function(){
		overlay.remove();
	});
	visuel1.delay(2000).animate({
		opacity: 1
	}, 600);
	
	logo.find(".lt").delay(3400).animate({
		"left" : "1.3%",
		"top" : "-1.2%"
	}, 600);
	logo.find(".rt").delay(3400).animate({
		"right" : "12.3%",
		"top" : "-1%"
	}, 600);
	logo.find(".rb").delay(3400).animate({
		"right" : "-1.2%",
		"bottom" : "0%"
	}, 600);
	logo.find(".lb").delay(3400).animate({
		"left" : "10.9%",
		"bottom" : "0.6%",
		"opacity" : 1
	}, 600); 
	
	visuel2.delay(3600).animate({
		opacity: 1
	}, 600, function(){
		initSlider();
	}); 
		
	content.delay(6000).animate({
		left: 0
	}, 1000);
}
function initDimensions(){
	// INIT BIG IMAGE
	vInit.width = visuel.width();
	vInit.height = visuel.height();
	vInit.ratio = visuel.height()/visuel.width();
	// INIT LOGO
	lInit.width = logo.width();
	lInit.height = logo.height();
	lInit.ratio = logo.height()/logo.width();
	// INIT LOGO LT
	lInit.ltwidth = logo.find(".lt").width();
	lInit.ltheight = logo.find(".lt").height();
	lInit.ltratio = logo.find(".lt").height()/logo.find(".lt").width();
	// INIT LOGO RT
	lInit.rtwidth = logo.find(".rt").width();
	lInit.rtheight = logo.find(".rt").height();
	lInit.rtratio = logo.find(".rt").height()/logo.find(".rt").width();
	// INIT LOGO RB
	lInit.rbwidth = logo.find(".rb").width();
	lInit.rbheight = logo.find(".rb").height();
	lInit.rbratio = logo.find(".rb").height()/logo.find(".rb").width();
	// INIT LOGO LB
	lInit.lbwidth = logo.find(".lb").width();
	lInit.lbheight = logo.find(".lb").height();
	lInit.lbratio = logo.find(".lb").height()/logo.find(".lb").width();
}
function resizeImage(){
	
	/*** RESIZE VISUEL ***/	
	visuel.css({
		"width" : "100%",
		"height" : "auto"
	}); 	
	if(visuel.height() < $(window).height()){
		visuel.css({
			"width" : "auto",
			"height" : "100%"
		});
	}	
	visuel.css({
		"position" : "absolute",
		"top" : "50%",
		"left" : "50%",
		"marginTop" : -Math.round(visuel.height()/2)+"px",
		"marginLeft" : -Math.round(visuel.width()/2)+"px"
	});
	
	var visuRatio = visuel.width()/vInit.width;
	
	/*** RESIZE LOGO ***/	
	logo.css({
		"width" : lInit.width * visuRatio,
		"height" : lInit.height * visuRatio    
	}); 	
	logo.css({
		"position" : "absolute",
		"top" : "50%",
		"left" : "50%",
		"marginTop" : -Math.round(logo.height()/2)+"px",
		"marginLeft" : -Math.round(logo.width()/2)+"px"   
	});
	
	/*** RESIZE LOGO LT ***/	
	logo.find(".lt").css({
		"width" : lInit.ltwidth * visuRatio,
		"height" : lInit.ltheight * visuRatio    
	}); 
	
	/*** RESIZE LOGO RT ***/	
	logo.find(".rt").css({
		"width" : lInit.rtwidth * visuRatio,
		"height" : lInit.rtheight * visuRatio    
	}); 		
	
	/*** RESIZE LOGO rb ***/	
	logo.find(".rb").css({
		"width" : lInit.rbwidth * visuRatio,
		"height" : lInit.rbheight * visuRatio    
	}); 		
	
	/*** RESIZE LOGO lb ***/	
	logo.find(".lb").css({
		"width" : lInit.lbwidth * visuRatio,
		"height" : lInit.lbheight * visuRatio    
	}); 	
}


var current = 2;
min = 2;
max = 5;
var timer;
function initSlider(){
	timer = setInterval("move()", 6000);	
}

function move(){
	current++;
	if(current > max) {
		current = min;
	}
	var elmt = $("#visuel .visuel"+current).fadeTo(300, 1);
	visuel.not(elmt).fadeTo(300, 0);
}




