layoutLakeside.mExits =
{
	[objectExitLakesideWoods1] = 
	{
		target = layoutWoods1,
		arrowX = 908,
		arrowY = 336,----
		arrowAngle = 0.45 * math.pi,
		labelX = 1007,
		labelY = 266,
		labelAnchorpoint = ANCHOR_CENTER_RIGHT,
	},
	[objectExitLakesideWoods2] = 
	{
		target = layoutWoods2,
		arrowX = 430,
		arrowY = 350,
		arrowAngle = 1.97 * math.pi,
		labelX = 428,
		labelY = 256,
		labelAnchorpoint = ANCHOR_CENTER,
	},
}

layoutLakeside.mPOIs = 
{
	[objectPoiBoathouseOpen] = 
	{
		target = layoutLakesideBoathouseDoor,
		mirrors = {objectPoiBoathouseClosed}
	},
	[objectPoiFirepit] = 
	{
		target = layoutLakesideCampfire,
		mirrors = {objectPoiFirepitWood, objectPoiFirepitKindling}
	},
	[objectPoiWatersource] = 
	{
		target = layoutLakesideWater,
	},
}

layoutLakeside.mHOs = 
{
	[objectHoWood04] = 
	{
		siblings = {objectHoWood04Lit, objectHoWood04Pocket}
	},
	[objectHoWood05] = 
	{
		siblings = {objectHoWood05Lit, objectHoWood05Pocket}
	},
	[objectHoWood06] = 
	{
		siblings = {objectHoWood06Lit}
	},
	[objectHoWood07] = 
	{
		siblings = {objectHoWood07Lit, objectHoWood07Pocket}
	},
	[objectHoWood08] = 
	{
		siblings = {objectHoWood08Lit, objectHoWood08Pocket}
	},
	[objectHoWood09] = 
	{
		siblings = {objectHoWood09Lit, objectHoWood09Pocket}
	},
	[objectHoWood10] = 
	{
		siblings = {objectHoWood10Lit, objectHoWood10Pocket}
	}				
}

layoutLakeside.mIOs =
{
}
layoutLakeside.showBlindingScare = false
layoutLakeside.showShadowScare = false
layoutLakeside.mEffectMist = nil
layoutLakeside.mEffectCampfire = nil
layoutLakeside.mFireOnSpikeCounter = 0
layoutLakeside.kWaterFrameTime = 160
-- ----------------------------------------------------------------------------
function layoutLakeside:onConstruct()
	
	Layout.onConstruct(self)
	
	p = self:newChildParticle( { name = "PARTICLE_LAKESIDE_OUTSIDE_MIST", x=0, y=320, library="PARTICLE_OUTSIDE_MIST", section="particles", play=true, removeWhenFinished=false } )
	p:setScale(0.7)
	p:setAlpha(0.5)
	p:addInitialTime(30000)
	p:moveBehind(objectBackgroundLakesideFront)
	
	self.mEffectCampfire = self:newChildParticle( { name = "PARTICLE_LAKESIDE_CAMPFIRE", x=560, y=530, library="PARTICLE_LAKESIDE_CAMPFIRE", section="particles", play=false, removeWhenFinished=false } )
	self.mEffectCampfire:addInitialTime(10000)
		
end
-- ----------------------------------------------------------------------------
function layoutLakeside:onInitialize()

	Layout.onInitialize(self)
	
	objectExitLakesideWoods1:ss(kActive)
	objectExitLakesideWoods2:ss(kActive)

	objectPoiBoathouseOpen:ss(kInactive)
	objectPoiBoathouseClosed:ss(kActive)
	objectPoiFirepit:ss(kActive)

	objectPoiFirepitWood:ss(kInactive)
	objectPoiFirepitKindling:ss(kInactive)
	
	objectScareFlashStart:ss(kInactive)
	objectScareFlashA:ss(kInactive)
	objectScareFlashB:ss(kInactive)
	objectScareFlashC:ss(kInactive)
	objectScareFlashFigure:ss(kInactive)
	objectScareShadowyFigure:ss(kInactive)
	objectScareShadowyFigureStart:ss(kInactive)
	objectEnigmaLightAntenna:ss(kInactive)
	
	objectFireOn:ss(kInactive)
	objectFireOnFront:ss(kInactive)
	
	objectLakesideWater:animate("LakesideWater",
		{ startframe=0,	endframe=9, frametime=self.kWaterFrameTime,	loops="forever" }
	)

end
-- ----------------------------------------------------------------------------
function layoutLakeside:onShow()

	Layout.onShow(self)
	
	if (self.showBlindingScare == true and (not objectScareFlashFigure:isDone())) then
		
		self.showBlindingScare = false
		self.showShadowScare = false -- don't show shadow scare if we first show blinding scare
		
		objectScareFlashFigure:ss(kIdle)
		
		objectScareFlashStart:setAlpha(0)
		objectScareFlashStart:ss(kIdle)
		objectScareFlashStart:animate("scareFlashStart_blocking",
			{ delay=1000	},		-- time shadowy figure without light
			{ alpha=1		},		
			{ delay=700		}		-- time flash start image visible
		)
	
	elseif (self.showShadowScare == true and not objectScareShadowyFigureStart:isDone()) then
		
		self.showShadowScare = false
		
		objectScareShadowyFigureStart:ss(kIdle)
		objectScareShadowyFigureStart:animate("scareShadow_blocking",
			{ command="playTrack track=SMALL_SCAREMOMENT", target=self },
			{ alpha=1, duration=1000	}
		)
		
	end
	
end
-- ----------------------------------------------------------------------------
function layoutLakeside:animFireOn()
	if (self.mFireOnSpikeCounter <= 0) then
		self.mFireOnSpikeCounter = math.random(50, 100)
	end
	
	self.mFireOnSpikeCounter = self.mFireOnSpikeCounter	- 1
	
	if (self.mFireOnSpikeCounter == 0) then
		self:animFireOnFlame()
	else
		self:animFireOnContinues()
	end
end
-- ----------------------------------------------------------------------------
function layoutLakeside:animFireOnContinues()

	local delay		= math.random(100, 500)
	local fadeOut 	= math.random(75, 100)
	local fadeIn	= math.random(75, 100)
	local alpha 	= math.random(85, 90)
	
	alpha = alpha / 100	
		
	self:animFireOnFlicker(1, delay, fadeOut, fadeIn, alpha)
		
	delay = delay + fadeOut + fadeIn
		
	objectFireOn:animate("animFireOn",
		{ delay=delay }
	)
end
-- ----------------------------------------------------------------------------
function layoutLakeside:animFireOnFlame()
	
	local num = math.random(3,5)
	local delay = 0
	
	for i=1, num do
		
		local fadeOut 	= math.random(100, 150)
		local fadeIn	= math.random(100, 150)	
		local alpha 	= math.random(75, 85)
		
		alpha = alpha / 100	
		
		self:animFireOnFlicker(i, delay, fadeOut, fadeIn, alpha)
		
		delay = delay + fadeOut + fadeIn
				
	end
	
	objectFireOn:animate("animFireOn",
		{ delay=delay }
	)
	
end
-- ----------------------------------------------------------------------------
function layoutLakeside:animFireOnFlicker(index, delay, fadeOut, fadeIn, alpha)
	objectFireOn:animate("animFireOn" .. index,
		{	delay=delay	},
		{	alpha=alpha, 	duration=fadeOut	},
		{	alpha=1,		duration=fadeIn		}
	)
	
	objectFireOnFront:animate("animFireOnFront" .. index,
		{	delay=delay	},
		{	alpha=alpha, 	duration=fadeOut	},
		{	alpha=1,		duration=fadeIn		}
	)
end
-- ----------------------------------------------------------------------------
function layoutLakeside:onAnimationFinish(animationName)

	Layout.onAnimationFinish(self, animationName)
	
	if (animationName == "animFireOn") then
		self:animFireOn()
	
	elseif (animationName == "scareFlashStart_blocking") then
		objectScareFlashStart:ss(kDone)
		
		objectScareFlashA:ss(kIdle)
		objectScareFlashA:animate("scareFlashA_blocking",
			{ startframe=0, endframe=3,		frametime=65				}
		)
		
	elseif (animationName == "scareFlashA_blocking") then
		objectScareFlashA:ss(kDone)
		
		objectScareFlashB:ss(kIdle)
		objectScareFlashC:ss(kIdle)
		
		objectScareFlashB:animate("scareFlashBC_blocking",
			{ startframe=0, endframe=2,		frametime=65				}
		)
		objectScareFlashC:animate(
			{ startframe=0, endframe=2,		frametime=65				}
		)
	
	elseif (animationName == "scareFlashBC_blocking") then
		objectScareFlashB:ss(kDone)
		objectScareFlashC:ss(kDone)
		objectScareFlashFigure:ss(kDone)
		
		local st = 
		{
			draw = "color",
			name = "blindingSprite",
			alpha = 1,
			x = 0, 
			y = 0, 
			width = self:width(),
			height = self:height(),
			color = {alpha=1, red=1, green=1, blue=1}
		}
		
		local blindingSprite = self:newChildSprite(st)
		blindingSprite:animate("spriteAnimation",
			{ command="playTrack track=FLASHLIGHT_IN_FACE", target=self },
			{ alpha=0, duration = 2000	},	-- time fade out binding sprite
			{ call = function(aSprite) aSprite:setObsolete() end }
		)
		
	elseif (animationName == "scareShadow_blocking") then
		
		objectScareShadowyFigureStart:ss(kDone)
	
		objectScareShadowyFigure:ss(kIdle)	
		objectScareShadowyFigure:animate("scareShadowRun_blocking",
			{ startframe=0, endframe=6,		frametime=65	}	
		)
	
	elseif (animationName == "scareShadowRun_blocking") then
	
		objectScareShadowyFigure:ss(kDone)
	
	elseif (animationName == "animRedLight") then
		self:animRedLight()
		
	end
	
end
-- ----------------------------------------------------------------------------
function layoutLakeside:onStartAudio()

	-- Play some outside noises
	playAmbientAudio(kOutsideHutAmbientGroup)
	
	-- Sweeteners
	local waterTrack = {}
	waterTrack.group = kOutsideHutAmbientGroup
	waterTrack.tag = "RIPPLING_WATER"
	waterTrack.definition = "WATER_RIPPLE"
	waterTrack.volume = 1.0
	getAudioManager():playTrack(waterTrack)
	
	-- Fire possibly
	if (objectFireOn:isIdle()) then
		local fireTrack = {}
		fireTrack.tag = "FIRE"
		fireTrack.definition = "LAKESIDE_FIRE"
		fireTrack.volume = 0.4
		getAudioManager():playTrack(fireTrack)
	end

end
-- ----------------------------------------------------------------------------
function layoutLakeside:onStopAudio()
	stopAudioTrack("FIRE")
	stopAudioTrack("RIPPLING_WATER")
end
-- ----------------------------------------------------------------------------
function layoutLakeside:animRedLight()

	if (objectEnigmaLightAntenna:isIdle()) then
		objectEnigmaLightAntenna:animate("animRedLight",
			{ alpha=1,	duration=100	},
			{ delay=500					},
			{ alpha=0,	duration=100	},
			{ delay=1000				}
		)
	end

end