layoutCrypt.mExits =
{
	[objectExitCryptCemetery] = 
	{
		target = layoutCemetery,
		arrowX = 424,
		arrowY = 452,
		arrowAngle = 1.7 * math.pi,
		labelX = 290,
		labelY = 380,
		labelAnchorpoint = ANCHOR_CENTER_LEFT,
	},
}
layoutCrypt.mPOIs = 
{
	[objectPoiHitchhikerPuzzle] = 
	{
		target = layoutCryptHitchhiker,
		mirrors = {objectPoiHitchhikerPuzzleComplete, objectPoiHitchhikerPuzzleOpen},
	},
	[objectPoiHookmanPuzzleClosed] = 
	{
		target = layoutCryptHookman,
		mirrors = {objectPoiHookmanPuzzleOpen, objectPoiHookmanPuzzleClosedFull}
	},
	[objectPoiKeypad] = 
	{
		target = layoutCryptKeypad,
		mirrors = {objectPoiKeypadBroken}
	},
	[objectPoiMedfileChristine] =
	{
		target = layoutCryptMedfile,
	},
	[objectPoiRotascopeCryptClosed] = 
	{
		target = layoutCryptRotascope,
		mirrors = {objectPoiRotascopeCryptOpen}
	},
	[objectPoiSecretDoorCrypt] = 
	{
		target = layoutCryptSecretDoor,
	},
	[objectPoiShrine] = 
	{
		target = layoutCryptShrine,
	},
	[objectPoiStoveClosed] = 
	{
		target = layoutCryptStove,
		mirrors = {objectPoiStoveOpen}
	},
}
layoutCrypt.mHOs = 
{
	[objectHoFile01] = 
	{
		siblings = {objectHoFile01Lit, objectHoFile01Pocket}
	},
	[objectHoFile02] = 
	{
		siblings = {objectHoFile02Lit}
	},
	[objectHoFile03] = 
	{
		siblings = {objectHoFile03Lit, objectHoFile03Pocket}
	},
	[objectHoFile04] = 
	{
		siblings = {objectHoFile04Lit, objectHoFile04Pocket}
	},
	[objectHoHmSlidingPiece03] = 
	{
		siblings = {objectHoHmSlidingPiece03Lit},
	},	
	[objectHoHmSlidingPiece04] = 
	{
		siblings = {objectHoHmSlidingPiece04Lit, objectHoHmSlidingPiece04Pocket},
	},	
	[objectHoHmSlidingPiece05] = 
	{
		siblings = {objectHoHmSlidingPiece05Lit},
	},	
	[objectHoHmSlidingPiece06] = 
	{
		siblings = {objectHoHmSlidingPiece06Lit}
	},
	[objectHoHmSlidingPiece07] = 
	{
		siblings = {objectHoHmSlidingPiece07Lit, objectHoHmSlidingPiece07Pocket}
	},
	[objectHoHmSlidingPiece08] = 
	{
		siblings = {objectHoHmSlidingPiece08Lit, objectHoHmSlidingPiece08Pocket}
	},
	[objectHoHook] = 
	{
		siblings = {objectHoHookLit, objectHoHookPocket}
	},
	[objectHoMetalStick] = 
	{
		siblings = {objectHoMetalStickLit, objectHoMetalStickPocket}
	},
	[objectHoSpecimen03] = 
	{
		siblings = {objectHoSpecimen03Lit, objectHoSpecimen03Pocket}
	},
}
layoutCrypt.mIOs =
{
}
layoutCrypt.mGroups =
{
	[objectHoHmSlidingGroup] =
	{
		children = {objectHoHmSlidingPiece01, objectHoHmSlidingPiece02, objectHoHmSlidingPiece03,
					objectHoHmSlidingPiece04, objectHoHmSlidingPiece05, objectHoHmSlidingPiece06,
					objectHoHmSlidingPiece07, objectHoHmSlidingPiece08},
		inventory = true,
		shoppinglist = false,
	},
	[objectHoFilesGroup] =
	{
		children = {objectHoFile01, objectHoFile02, objectHoFile03, objectHoFile04, objectHoFileChristine},
		inventory = true,
		shoppinglist = false,	
	}
}
layoutCrypt.mEffectCandle1 = nil
layoutCrypt.mEffectCandle2 = nil
layoutCrypt.mEffectKeypadSpark = nil
layoutCrypt.mEffectCryptFire = {}
layoutCrypt.justPlayedFirst = false
layoutCrypt.timeBetweenBangingSounds = 1200
layoutCrypt.bangingSoundTimer = 0
-- ----------------------------------------------------------------------------
function layoutCrypt:onConstruct()
	
	Layout.onConstruct(self)
	
	t1 = self:newChildParticle( { name = "PARTICLE_CRYPT_TORCH1_FIRE",    x=296,  y=213, library="PARTICLE_CRYPT_TORCH_FIRE", section="particles", play=true, removeWhenFinished=false } )
	t1:addInitialTime(10000)
	t2 = self:newChildParticle( { name = "PARTICLE_CRYPT_TORCH2_FIRE",    x=491,  y=238, library="PARTICLE_CRYPT_TORCH_FIRE", section="particles", play=true, removeWhenFinished=false } )
	t2:addInitialTime(10000)
	t2:setScale(0.8)
	
	self.mEffectCandle1 = self:newChildParticle( { name = "PARTICLE_CRYPT_CANDLE1_FIRE",    x=1433,  y=458, library="PARTICLE_CRYPT_CANDLE_FIRE", section="particles", play=true, removeWhenFinished=false } )
	self.mEffectCandle2 = self:newChildParticle( { name = "PARTICLE_CRYPT_CANDLE2_FIRE",    x=1493,  y=510, library="PARTICLE_CRYPT_CANDLE_FIRE", section="particles", play=true, removeWhenFinished=false } )
	
	self.mEffectKeypadSpark = self:newChildParticle( { name = "PARTICLE_CRYPT_KEYPAD_SPARK",    x=1983,  y=300, library="PARTICLE_CRYPT_KEYPAD_SPARK_LAYOUT", section="particles", play=false, removeWhenFinished=false } )
	
	self.mEffectCryptFire[1] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE1",    x=635,   y=395, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[2] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE2",    x=690,   y=474, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[3] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE3",    x=825,   y=534, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[4] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE4",    x=958,   y=498, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[5] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE5_1",  x=1186,  y=458, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[6] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE5_2",  x=1200,  y=452, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[7] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE5_3",  x=1214,  y=458, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[8] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE6_1",    x=1336,  y=450, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[9] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE6_2",    x=1349,  y=450, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[10] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE7",    x=1415,  y=495, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[11] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE8",    x=1521,  y=567, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCryptFire[12] = self:newChildParticle( { name = "PARTICLE_CRYPT_STOVE_EXPLODED_FIRE9",    x=1636,  y=390, library="PARTICLE_CRYPT_STOVE_EXPLODED_FIRE", section="particles", play=false, removeWhenFinished=false } )
	
	self.mEffectCryptFire[1]:setScale(0.8)
	self.mEffectCryptFire[2]:setScale(1)
	self.mEffectCryptFire[3]:setScale(1)
	self.mEffectCryptFire[4]:setScale(0.9)
	self.mEffectCryptFire[5]:setScale(1)
	self.mEffectCryptFire[6]:setScale(1)
	self.mEffectCryptFire[7]:setScale(1)
	self.mEffectCryptFire[8]:setScale(1)
	self.mEffectCryptFire[9]:setScale(1)
	self.mEffectCryptFire[10]:setScale(0.8)
	self.mEffectCryptFire[11]:setScale(1)
	self.mEffectCryptFire[12]:setScale(0.8)
	
end
-- ----------------------------------------------------------------------------
function layoutCrypt:onInitialize()

	Layout.onInitialize(self)
	
	objectExitCryptCemetery:ss(kActive)
	
	objectPoiRotascopeCryptOpen:ss(kInactive)
	objectPoiStoveOpen:ss(kInactive)
	objectPoiStoveClosed:ss(kActive)	
	objectPoiHitchhikerPuzzle:ss(kActive)
	objectPoiHitchhikerPuzzleOpen:ss(kInactive)
	objectPoiHitchhikerPuzzleComplete:ss(kInactive)
	objectPoiHookmanPuzzleClosed:ss(kActive)
	objectPoiHookmanPuzzleClosedFull:ss(kInactive)
	objectPoiHookmanPuzzleOpen:ss(kInactive)	
	objectPoiKeypad:ss(kActive)
	objectPoiKeypadBroken:ss(kInactive)
	objectPoiRotascopeCryptClosed:ss(kActive)
	objectPoiSecretDoorCrypt:ss(kActive)
	objectPoiShrine:ss(kActive)
	objectBackgroundCryptCenterExplosion:ss(kInactive)
	objectBackgroundCryptCenterExplosionLit:ss(kInactive)
	objectBackgroundCryptLeftExplosion:ss(kInactive)
	objectBackgroundCryptRightExplosion:ss(kInactive)
	objectBackgroundCryptRightExplosionLit:ss(kInactive)
	objectPoiMedfileChristine:ss(kActive)
	objectCryptCenterPyromask:ss(kInactive)
	
	objectBouncingSecretDoor:ss(kInactive)
	objectBreakingSecretDoor:ss(kInactive)
	
end
-- ----------------------------------------------------------------------------
function layoutCrypt:onShow()
	Layout.onShow(self)
	
	-- check if we should play animKeypadSpark
end
-- ----------------------------------------------------------------------------
function layoutCrypt:animKeypadSpark()

	self.mEffectKeypadSpark:play()

	local delay = math.random(2000, 3500)
	
	self:animate("animKeypadSparkDelay",
		{ delay=delay } 
	)	

end
-- ----------------------------------------------------------------------------
function layoutCrypt:onAnimationFinish(animationName)

	Layout.onAnimationFinish(self, animationName)
	
	if (animationName == "breakingDoorLoop") then
		animLoop(objectBreakingSecretDoor, "breakingDoorLoop", 65, 100, 100, 500)
		
	elseif (animationName == "bangingDoorLoop") then
		animLoop(objectBouncingSecretDoor, "bangingDoorLoop", 65, 100, 2000, 2500)
		
		if (self.shouldHearBanging) then
			
			layoutCryptSecretDoor:shakeDoorBanging()
		
			if (self.justPlayedFirst) then
				playAudioTrack("PUSHDOOR_2")
				self.justPlayedFirst = false
			else
				playAudioTrack("PUSHDOOR_1")
				self.justPlayedFirst = true
			end
		end

	elseif (animationName == "animKeypadSparkDelay") then
		self:animKeypadSpark()		
	end

end
-- ----------------------------------------------------------------------------
function layoutCrypt:onStartAudio()

	-- Play some outside noises
	playAmbientAudio(kSpookyAmbientGroup)
	
	-- Sweeteners
	local windTrack = {}
	
	windTrack.group = kSpookyAmbientGroup
	windTrack.definition = "CRYPT_DRAUGHT"
	windTrack.volume = 0.8
	
	getAudioManager():playTrack(windTrack)
	
	-- stove fire
	getAudioManager():playTrack( { tag="CRYPT_FIRE", definition="CRYPT_FIRE", volume=1.0 } )	
	
	self:updateFireAudio(false)
	
end
-- ----------------------------------------------------------------------------
function layoutCrypt:onStopAudio()
	stopAudioTrack("CRYPT_FIRE")
end
-- ----------------------------------------------------------------------------
function layoutCrypt:updateFireAudio(poiActive)
	local volume = 1.0
	
	if (not poiActive and (objectPoiStoveClosed:isActive() or objectPoiStoveOpen:isActive())) then
		volume = 0.3
	end
	
	getAudioManager():setTrackVolume( { tag="CRYPT_FIRE", volume=volume } )
end
-- ----------------------------------------------------------------------------
function layoutCrypt:onMovieFinish(movieName)

	Layout.onMovieFinish(self, movieName)

	-- christine thinks
	think("MESSAGE_AFTER_EXPLOSION")

end