// On page load :
$(document).ready(function(){
	var lutte = $("#lutte").html();
	$("#lutte").html("&gt; "+lutte);
	addHover(".important");

	$(".symptoms ul").hide();
	$("#hommemalade").empty();

	$("#hommemalade").append('<div id="mecreplay"><a href="#">Rejouer l\'animation</a></div>');
	$("#mecreplay").hide();
	$("#mecreplay").click( animate_mecmalade );

	$("#hommemalade").append('<img id="mecmalade_flou" src="../images/visual-tiredness/mecmalade_flou.jpg" galleryimg="no"/>');
	$("#hommemalade").append('<img id="mecmalade" src="../images/visual-tiredness/mecmalade.jpg" galleryimg="no"/>');
	$("#hommemalade").append('<img id="mecfond" src="../images/visual-tiredness/mecmalade_fond3.gif" galleryimg="no"/>');
	$("#hommemalade").append('<div id="meclegende"></div>');
	$("#mecmalade_flou").css({ position: "absolute", top: "30px", left: "30px", width: "230px", height: "240px" });
	$("#mecmalade").css({ position: "absolute", top: "30px", left: "30px", width: "230px", height: "240px" });
	$("#mecfond").css({ position: "absolute", top: "0px", left: "0px", width: "290px", height: "300px"});
	$("#meclegende").css({ opacity: 0.8 });
	$("#meclegende").html($(".symptoms li:first-child").html());
	$(".symptoms").css({ background: "none"});
	if( isMecMoving == false ){
		$(".symptoms").mouseover( check_animate_mecmalade );
	}
	
});


var isMecMoving = false;
function check_animate_mecmalade()
{
	if( !isMecMoving ){
		isMecMoving = true;
		animate_mecmalade();
	}
}


function animate_mecmalade()
{
	var mecmalade = $("#mecmalade");
	var mecmalade_flou = $("#mecmalade");
	var meclegende = $("#meclegende");
	$("#mecreplay").hide();

	if( $("#meclegende").html() != $(".symptoms li:first-child").html() ){
		$("#meclegende").fadeOut(200);
		$("#meclegende").html($(".symptoms li:first-child").html());
		$("#meclegende").fadeIn(200);
	}

	mecmalade.animate(
		{
			top: "0px",
			left: "0px",
			width: "290px",
			height: "300px",
			opacity: 0.8
		},
		1500,
		"linear",
	function()
	{
	mecmalade.animate(
		{
		top: "0px",
		left: "30px",
		width: "230px",
		height: "300px",
		opacity: 0.8
	},
	1200,
	"linear",
	function()
	{
	mecmalade.animate(
	{
		top: "0px",
		left: "0px",
		width: "290px",
		height: "300px"
	},
	1500,
	"linear",
	function()
	{
	mecmalade.animate(
	{
		top: "30px",
		left: "30px",
		width: "230px",
		height: "240px"
	},
	1600,
	"linear",

	function()
	{
	meclegende.hide();
	meclegende.html($(".symptoms li:nth-child(2)").html());
	meclegende.fadeIn(200);
	mecmalade.animate(
	{
		top: "20px",
		left: "20px",
		width: "250px",
		height: "260px",
		opacity: 0.3
		},
		1000,
		"linear",
	function()
	{
	mecmalade.animate(
	{
		top: "30px",
		left: "30px",
		width: "230px",
		height: "240px",
		opacity: 0.8
	},
	2000,
	"linear",
	function()
	{
	mecmalade.animate(
	{
		top: "20px",
		left: "20px",
		width: "250px",
		height: "260px",
		opacity: 0.3
	},
	1000,
	"linear",
	function()
	{
	mecmalade.animate(
	{
		top: "30px",
		left: "30px",
		width: "230px",
		height: "240px",
		opacity: 0.8
	},
	2000,
	"linear",

	function()
	{
	meclegende.fadeOut(200);
	meclegende.html($(".symptoms li:last-child").html());
	meclegende.fadeIn(200);
	mecmalade.animate(
	{
		top: "0px",
		left: "0px",
		width: "290px",
		height: "300px",
		opacity: 0.1
	},
	500,
	"linear",
	function()
	{
	mecmalade.animate(
	{
		top: "30px",
		left: "30px",
		width: "230px",
		height: "240px",
		opacity: 0.7
	},
	1100,
	"linear",
	function()
	{
	mecmalade.animate(
	{
		top: "0px",
		left: "0px",
		width: "290px",
		height: "300px",
		opacity: 0.1
	},
	500,
	"linear",
	function()
	{
	mecmalade.animate(
	{
		top: "30px",
		left: "30px",
		width: "230px",
		height: "240px",
		opacity: 0.8
	},
	1100,
	"linear",

	function()
	{
	mecmalade.animate(
	{
		top: "0px",
		left: "0px",
		width: "290px",
		height: "300px",
		opacity: 0.1
	},
	500,
	"linear",
	function()
	{
	mecmalade.animate(
	{
		top: "30px",
		left: "30px",
		width: "230px",
		height: "240px",
		opacity: 0.8
	},
	1100,
	"linear",

	function()
	{
	mecmalade.animate(
	{
		top: "30px",
		left: "30px",
		width: "230px",
		height: "240px"
	},
	1000,
	"linear",



	function(){
		$("#mecreplay").show();
	}

	);}
	);}
	);}
	);}
	);}
	);}
	);}
	);}
	);}
	);}
	);}
	);}
	);}
	);}
	);
}