--------------------------------------------------------------------------------
--  File     : Chapel_int
--  Author(s): Prokopovich Larisa
--
--  Summary  : Скрипт управления локацией.
--
--  Copyright © 2012 Floodlight Games.  All rights reserved.
--------------------------------------------------------------------------------
function OnFirstEntry()
	room:GetItem("CASKET_OPENED"):Disable ()

	music:Stop(true)
	music:PlayLoopWithDelay(0, "reprise_2")
	room.sfx:Play ("jingle_1")		--звук джингла при первом входе
	
	stars:Show("M_CABINET", "1")
	stars:Show("CASKET", "2")
	stars:Show("CASKET_OPENED", "2")
	stars:Show("NOTE_RUNES", "4")
end
--------------------------------------------------------------------------------
function OnEntry()
	ambient:Play("Chapel_int")
	music:PlayLoopWithDelay(10, "reprise_2")
end
--------------------------------------------------------------------------------
function OnMouseClickOnItem(item)
	local itemName = item:GetName()
	
	if itemName == "M_TO_EXT" then											--переход к часовне
		chapter:JumpRoom("Chapel_ext")
		return true
		
	elseif itemName == "M_CABINET" then										--переход в hidden object со шкафом
		chapter:JumpRoom("Chapel_int_Cupboard_HO")
		return true
		
	elseif (itemName == "CASKET") or										--переход в close-up со шкатулкой
		   ((itemName == "CASKET_OPENED") and not(item:IsEnabled())) then
		chapter:JumpCloseup("Chapel_int_Casket")
		return true
	end
	
	
	if itemName == "NOTE_RUNES" then				--записка про руны
		journal:AddItem("NOTE_RUNES", false, "note_runes")
		item:Hide()
		return true
	
	elseif itemName == "M_ELDER" then				--староста
		comment:Add("CMT_Elder_Player") 
		return true	
	end
end
--------------------------------------------------------------------------------
function OnClickItemOnItem(item)					
	local itemName = item:GetName()
	
	if (itemName == "CASKET") or											--переход в close-up со шкатулкой
	   ((itemName == "CASKET_OPENED") and not(item:IsEnabled())) then
		chapter:JumpCloseup("Chapel_int_Casket")
		return true
	end
end
--------------------------------------------------------------------------------
function OnChapterStoreEvent_Close_up_ChapelBox(value)						--закрыть close-up с шкатулкой
	if value == 1 then
		room:GetItem("CASKET"):Hide()
		room:GetItem("CASKET_OPENED"):Show()
	elseif value == 2 then
		room:GetItem("CASKET_OPENED"):Enable ()
		stars:Hide("CASKET_OPENED")
	end
end
--------------------------------------------------------------------------------
function OnChapterStoreEvent_Cupboard_HO(value)								--закрыть hidden object со шкафом
	if (value == 1) or (value == 3) then
		room:GetItem("M_CABINET"):Hide()
	elseif value == 2 then
		room:GetItem("M_CABINET"):Show()
	end
end
--------------------------------------------------------------------------------
function OnChapterStoreEvent_Cheat_ChapelInt1(value)			--выполнить все в локации  !!!
	room:GetItem("NOTE_RUNES"):Hide()
	cstore:SetKey("Close_up_ChapelBox", 1)
	cstore:SetKey("Close_up_ChapelBox", 2)
	if cstore:GetKey("Cupboard_HO") ~= 2 then
		cstore:SetKey("Cupboard_HO", 1)
	end
end
function OnChapterStoreEvent_Cheat_ChapelInt2(value)			
	cstore:SetKey("Cupboard_HO", 3)
end