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
--	SetMarker("cs\\Warp_0059.wp" , 0 , 0) 
	SetMarker("cs\\Warp_0056.wp" , 0 , 0) 
--	SetMarker("cs\\Warp_0159.wp" , 0 , 0) 


	if ETAT_DAY == "D3" then 
		-- portes de l'armoire
		AnimationSetToEnd("fbc1",false)
		-- ouverture du passage secret
		AnimationSetToStart("fec1",false)
		if MONK_AT_LIBRARY_0056_D3 then
			-- moine assis
			StartAnimationPart("evc1",110,120,-1,true)
		end
	end

	if ETAT_DAY == "D4" then
		
		-- portes de l'armoire
		AnimationSetToEnd("fbc1",false)
		-- ouverture du passage secret
		AnimationSetToStart("fec1",false)
		if Map 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
--		if ESCAPE_FROM_CHAVIGNY then
--			LookAt(173,002) -- à changer
--		end
	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)
			OPENED_HIDDEN_ROOM = true
			--[[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")]]
			SetMarker("cs\\Warp_0059.wp" , 0 , 0)
			PlaySound("Sounds/SFX/J_Cle.ogg",1)
		end
	end
end

function OnDocumentClosed(documentId)
	if documentId == "EndPart2" then
		StopSound("Sounds/SFX/M_Cine008.ogg")
		-- RETOUR MENU
		FinishGame()
	end
end

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

function OnMovieFinished(name)

    if (name == "Videos/vision1-vision2-cine003-cine007.ogv") then
		O_SmallPacket_058 = true
		AddToBag("C_petit_paqu")
--		AddToBag("C_papier_amp")
--		RemoveFromBag("C_papier_philibert1")
--		SetDiaryPage(8, "Page8_01")
		RemoveObject("fdc1")
		SetMarker("fdc1",-1,0)
		DrawText("Ma3529","Ma3529.ogg",0) -- Qu'est-ce qui m'arrive ? On aurait dit le bibliothécaire mort !
    end
end


function OnWarpObjectHit(objectName)

	if objectName == "3D\\cs\\Warp_0059.wp" then 
		if OPENED_HIDDEN_ROOM then
			PlayMusic("Sounds/Musiques/silence5s.ogg")
			PlaySound("Sounds/SFX/M_Cine008.ogg",1)
			ShowDocument("EndPart2")
			--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 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.
				elseif 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.
				else
					SetMarker("fec1",-1,0)
					DrawText("Ma1706","Ma1706.ogg",0) -- C'est fermé à clef.
				end
			end
		end
	end
end
