function OnWarpEnter() 
	-- HACK for DAY 4: in case we didn't discover the map yet, putting the 2 pieces together
	-- while in this warp will create an inconsistent situation when we exit the inventory.
	-- The marker to move the books will not appear. Solution is to create a temp var that says
	-- we are in this warp, that can be used in the toolbox when resolving the map zoom.
	D4_InW058 = true
	Music_Change = false
--	SetMarker("cs\\Warp_0059.wp" , 0 , 0) 
	SetMarker("cs\\Warp_0056.wp" , 0 , 0)

	if not Part3 then
		ETAT_DAY = "D4" 
		SetCesarDressable(true)
		SetMadeleineDressable(true)
		AddToBagWithoutNotification("A_briquet")
		AddToBagWithoutNotification("A_pierre_nostradamus")
		AddToBagWithoutNotification("C_petite_tombe")
		AddToBagWithoutNotification("A_recipient")
		AddToBagWithoutNotification("C_clef_philiber")
		AddToBagWithoutNotification("C_note_scribe2")
		AddToBagWithoutNotification("A_aphrodisiaque")
		AddToBagWithoutNotification("C_plan2")

		SetDiaryPage(0, "Page0")
		SetDiaryPage(1, "Page1")
		SetDiaryPage(2, "Page2")
		SetDiaryPage(3, "Page3")
		SetDiaryPage(4, "Page4_02")
		SetDiaryPage(5, "Page5_04")
		SetDiaryPage(6, "Page6_02")
		SetDiaryPage(7, "Page7_02")
		SetDiaryPage(9, "Page9")
		SetDiaryPage(10, "Page10_04")
		SetDiaryPage(11, "Page11")
		SetDiaryPage(12, "Page12_02")
		SetDiaryPage(13, "Page13")
		SetDiaryPage(14, "Page14_01")
		SetDiaryPage(15, "Page15_01")
		SetDiaryPage(16, "Page16")

		SetRecipiesPage(0, "Page0")
		SetRecipiesPage(1, "Page1")
		SetRecipiesPage(2, "Page2")
		SetRecipiesPage(3, "Page3")
		SetRecipiesPage(4, "Page4")
		SetRecipiesPage(5, "Page5")
		SetRecipiesPage(6, "Page6")
		SetRecipiesPage(7, "Page7")
		SetRecipiesPage(8, "Page8")
		SetRecipiesPage(9, "Page9")

		SetWartVisible(true)
		ShowDocument("ChoixCostume")
		
		Part2 = true
		Bucket_up_empty = true  -- Puits pour Tisane
		Rope_Ready_027 = true  -- Puits pour Tisane
		O_lighter_008 = true -- Comme le briquet est dans l'inventaire
		balcony_open = true
		Map = true
		DRESS_MADELEINE = true
		TOOK_MAP_FRAGMENT_D4 = true
		MOVED_BOOKS = true
		OPENED_HIDDEN_ROOM = true
		ALREADY_OPENED_HIDDEN_ROOM_ONCE = true
		JEAN_AT_LIBRARY_D4 = false
		Aphrodisiac_212 = true
		NotExpectedW63 = true
		Cesar_Constance_D3 = true
		O_papier_philibert_0071 = true
		Music_Change = true
		PlayMusic("Sounds/Musiques/M_FouillerChambre.ogg")

		Part3 = true
	end

	if ETAT_DAY == "D4" then
		
		-- portes de l'armoire
		AnimationSetToEnd("fbc1",false)
		-- ouverture du passage secret
		AnimationSetToStart("fec1",false)
		if TOOK_MAP_FRAGMENT_D4 then
			if not MOVED_BOOKS then
				-- ouverture du passage secret
				AnimationSetToStart("fec1",false)
				SetMarker("fec1",4,0)
			elseif not OPENED_HIDDEN_ROOM  then
				-- ouverture du passage secret
				StartAnimationPart("fec1",1,2,-1,false)
				SetMarker("fec1",4,0)
			else
				SetMarker("cs\\Warp_0059.wp" , 0 , 0)
				if OPENED_HIDDEN_ROOM and not JEAN_AT_LIBRARY_D4 then
					AnimationSetToEnd("fec1",false)
				end
			end
		else
			-- ouverture du passage secret
			AnimationSetToStart("fec1",false)
		end
	end
 
	if ETAT_DAY == "D5" then 
		-- portes de l'armoire
		AnimationSetToEnd("fbc1",false)
		-- ouverture du passage secret
		AnimationSetToStart("fec1",false)
		OPENED_HIDDEN_ROOM = true
	end 
end

function OnWarpLeave()
	D4_InW058 = false
end

function OnAnimationFinished(objectName)
	if ETAT_DAY == "D4" then
		-- ouverture du passage secret
		if objectName == "fec1" and not MOVED_BOOKS then
			StartAnimationPart("fec1", 1, 2, -1, false)
			SetMarker("fec1" , 4 , 0)
			MOVED_BOOKS = true
		elseif objectName == "fec1" and MOVED_BOOKS and not OPENED_HIDDEN_ROOM then
			StartAnimationPart("fec1", 30, 31, -1, false)
			SetMarker("cs\\Warp_0059.wp" , 0 , 0)
			OPENED_HIDDEN_ROOM = true
			if not ALREADY_OPENED_HIDDEN_ROOM_ONCE then
				PlaySound("Sounds/SFX/J_Cle.ogg",1)
				ALREADY_OPENED_HIDDEN_ROOM_ONCE = true
			end
			--PlayMusic("Sounds/Musiques/M_FouillerChambre.ogg")
		end
	end
end

function OnDialogFinished(dialogName)
	
	if dialogName == "Ma3516" or dialogName == "Ma1706" then
		SetMarker("fec1",4,0)
	end

end

function OnMovieFinished(name)
end


function OnWarpObjectHit(objectName)

	if objectName == "3D\\cs\\Warp_0059.wp" then 
		if OPENED_HIDDEN_ROOM then
			ChangeWarp(objectName)
		end
	end

	if objectName == "3D\\cs\\Warp_0056.wp" then
		if OPENED_HIDDEN_ROOM then
			PlaySound("Sounds/SFX/E_Armoire_Fermeture.ogg",1)
			OPENED_HIDDEN_ROOM = false
		end
		ChangeWarp(objectName)
	end

--DAY4
	if ETAT_DAY == "D4" then 
		-- moine assis
		if objectName == "evc1" then
		-- ouverture du passage secret
		elseif objectName == "fec1" then
			if Map then
				if JEAN_AT_LIBRARY_D4 then
					DrawText("Ma2788","Ma2788.ogg",0) -- Pas maintenant. Chavigny n'a pas besoin de connaître l'existence de cette pièce.
				elseif not MOVED_BOOKS then
					StartAnimationPart("fec1", 0, 1, 1, false)
					PlaySound("Sounds/SFX/N_FermetureTiroir.ogg",1)
					SetMarker("fec1", -1, 0)
				elseif not OPENED_HIDDEN_ROOM and Selected("C_clef_philiber")  then
					--RemoveFromBag()
					StartAnimationPart("fec1", 3, 30, 1, false)
					PlaySound("Sounds/SFX/E_ArmoireOuverture.ogg",1)
					SetMarker("fec1",-1,0)
				elseif not OPENED_HIDDEN_ROOM and Selected("C_clef_philibe") then
					SetMarker("fec1",-1,0)
					DrawText("Ma3516","Ma3516.ogg",0) -- J'étais pourtant sûre que la clef de Philibert marcherait. Elle entre mais ne tourne pas.
				else
					SetMarker("fec1",-1,0)
					DrawText("Ma1706","Ma1706.ogg",0) -- C'est fermé à clef.
				end
			end
		end
	end 

--DAY5
	if ETAT_DAY == "D5" then 

	end 
end

function OnShowedDocumentButtonValidated(page, buttonName)

	if page == "ChoixCostume_zoomed_0"  then
		if buttonName == "button0" then
			DRESS_MONK = false		
			DRESS_CESAR = false
			DRESS_MADELEINE = true
			HideDocument()
		elseif buttonName == "button1" then
			DRESS_MONK = false		
			DRESS_CESAR = true
			DRESS_MADELEINE = false
			HideDocument()
		end	
	else
		ShowDocument("ChoixCostume")
	end	
end

