layoutPorch.shownPorchScare = false
layoutPorch.mTimeUntilFirstGoal = 0
-- ----------------------------------------------------------------------------
layoutPorch.mExits =
{
	[objectPorchShed] = 
	{
		target = layoutShed,
		mirrors = {objectPorchShedLit},
		arrowX = 890,
		arrowY = 540,
		arrowAngle = 0.1 * math.pi,
		labelX = 904,
		labelY = 444,
		labelAnchorpoint = ANCHOR_CENTER,
	},
	[objectPorchDoorOpen] = 
	{
		target = layoutLivingroom,
		mirrors = {objectPorchDoorLights},
		arrowX = 500,
		arrowY = 425,
		arrowAngle = 1.65 * math.pi,
		labelX = 455,
		labelY = 355,
		labelAnchorpoint = ANCHOR_CENTER,
	},
}
layoutPorch.mPOIs = 
{
	[objectPorchDoorknob] = 
	{	
		target = layoutPorchDoorknob,
	},
	[objectPorchNote] = 
	{	
		target = layoutPorchNote,
	},
	[objectPorchRockUnlit] = 
	{	
		target = layoutPorchRock,
		mirrors = {objectPorchRockLit}
	},
	[objectPorchSuitcaseOpen] = 
	{	
		target = layoutPorchSuitcase,
		sparkleX = 668,
    	sparkleY = 561,	
	},
	[objectPorchShutterClosed] = 
	{	
		target = layoutPorchWindow,
	    sparkleX = 158,
    	sparkleY = 280,	
	},
}
layoutPorch.mHOs =
{
	[objectPorchLipstick] = 
	{
		siblings = {objectPorchLipstickDark, objectPorchLipstickPocket},
	},
	[objectPorchMakeupbrush] = 
	{
		siblings = {objectPorchMakeupbrushDark},
	},
	[objectPorchMirror] = 
	{
		siblings = {objectPorchMirrorDark, objectPorchMirrorPocket},
	},
	[objectPorchParfum] = 
	{
		siblings = {objectPorchParfumDark, objectPorchParfumPocket},
	},
	[objectPorchRaggedshirt] = 
	{
		siblings = {objectPorchRaggedshirtDark},
	},
	[objectPorchShoe] = 
	{
		siblings = {objectPorchShoeDark},
	},
	[objectPorchSkirt] = 
	{
		siblings = {objectPorchSkirtDark},
	},
	[objectPorchSock] =
	{
		siblings = {objectPorchSockDark, objectPorchSockPocket},
	},
	[objectPorchToothbrush] =
	{
		siblings = {objectPorchToothbrushDark, objectPorchToothbrushPocket},
	},
	[objectPorchWallet] =
	{
		siblings = {objectPorchWalletDark},
	},
	[objectPorchWindowlever] =
	{
		siblings = {objectPorchWindowleverDark, objectPorchWindowleverPocket},
	},
}
layoutPorch.mIOs =
{
	[objectPorchCrowloop] =
	{
		cursors = kCursorPointer,
	}
}
layoutPorch.mGroups = 
{
	[objectStackoclothes] =
	{
		children = {objectPorchLipstick, objectPorchMakeupbrush, objectPorchMirror, objectPorchParfum,
					objectPorchRaggedshirt, objectPorchShoe, objectPorchSkirt, objectPorchSock,
					objectPorchToothbrush, objectPorchWallet },
		inventory = true,
		shoppinglist = false,
	}
}
layoutPorch.mEffectMist = nil
layoutPorch.mEffectMosquitos = nil
-- ----------------------------------------------------------------------------
function layoutPorch:onConstruct()
	
	Layout.onConstruct(self)

	objectPorchBackgroundLit:ss(kInactive)
	objectPorchBackgroundLitFront:ss(kInactive)
    objectPorchWindowClosed:ss(kDone)
    objectPorchShutterOpen:ss(kInactive)
    objectPorchWindowOpenLit:ss(kInactive)
    objectPorchDoorLights:ss(kInactive)
    objectPorchRockLit:ss(kInactive)
    objectPorchShadow:ss(kInactive)
    objectPorchBirdsloop:ss(kInactive)
    objectPorchBirdsflight:ss(kInactive)
    objectPorchDoorOpen:ss(kInactive)
    objectPorchShed:ss(kIdle)
    objectPorchShedLit:ss(kInactive)
    
    objectPorchSuitcaseOpen:ss(kInactive)
    objectPorchMakeupbrush:ss(kInactive)
    objectPorchMirror:ss(kInactive)
    objectPorchParfum:ss(kInactive)
    objectPorchToothbrush:ss(kInactive)
    objectPorchWallet:ss(kInactive)
    objectPorchLipstick:ss(kInactive)
    objectPorchSock:ss(kInactive)
    objectPorchShoe:ss(kInactive)
    objectPorchRaggedshirt:ss(kInactive)
    objectPorchSkirt:ss(kInactive)
    objectPorchNoteFlapping:ss(kIdle)
    
    objectPorchMechRustShine:ss(kInactive)
    objectPorchRockInsect:ss(kInactive)
    objectPorchSuitcaseShine:ss(kInactive)
    objectPorchDoorknobShine:ss(kInactive)
    
    self:onConstructPorchWindow()

    self.mEffectMist = self:newChildParticle( { name = "PARTICLE_PORCH_OUTSIDE_MIST", x=630, y=420, library="PARTICLE_OUTSIDE_MIST", section="particles", play=true, removeWhenFinished=false} )
    self.mEffectMist:addInitialTime(15000)
    self.mEffectMist:moveBehind(objectPorchBackgroundLitFront)
    
    self.mEffectMosquitos = self:newChildParticle( { name = "PARTICLE_PORCH_LAMP_MOSQUITOS", x=565, y=232, library="PARTICLE_LAMP_MOSQUITOS", section="particles", play=false, removeWhenFinished=false } )
    
end
-- ----------------------------------------------------------------------------
function layoutPorch:onConstructPorchWindow()

	objectPorchMechClean:ss(kInactive)
	objectPorchMechScrew:ss(kInactive)
	objectPorchMechScrewAffix:ss(kInactive)
	
end
-- ----------------------------------------------------------------------------
function layoutPorch:onInitialize()
    
    Layout.onInitialize(self)
    
    objectPorchCrowflight:ss(kInactive)
    objectPorchCrowloop:ss(kActive)
    
    animLoop(objectPorchCrowloop, "PorchCrowLoop", 300, 320, 2500, 3500)
    
    objectPorchBirdsloop:ss(kIdle)
    objectPorchBirdsloop:animate("PorchBirdsLoop",
	{ startframe=0,	endframe=19,		frametime=300,		loops="forever"			}
	)
	
end
-- ----------------------------------------------------------------------------
function layoutPorch:onMessageFinish(messageId, messageType)

	if (messageId == "GOAL_01_THOUGHTS" and messageType == 0) then
		self:showNoteHighlight()		
	end

	Layout.onMessageFinish(self, messageId, messageType)

end
-- ----------------------------------------------------------------------------
function layoutPorch:onTick(time)

	if (self.mTimeUntilFirstGoal > 0) then
		-- default cursor
		cursor:reset()
		
		-- decrease timer until we can start the game
		self.mTimeUntilFirstGoal = self.mTimeUntilFirstGoal - time
		if (self.mTimeUntilFirstGoal <= 0) then
			self:setInputActive(true)
			self.mTimeUntilFirstGoal = -1
		end	
	else
		Layout.onTick(self, time)
	end

end
-- ----------------------------------------------------------------------------
function layoutPorch:onShow()
	
	Layout.onShow(self)
	
	if (objectPorchSuitcaseClosed:isLocked() and layoutLivingroom.showedScaryShadow) then
		objectPorchSuitcaseClosed:ss(kInactive)
		objectPorchSuitcaseClosed:animate("playSuitcaseGoneScareSound",
			{ command="playTrack track=MEDIUM_SCAREMOMENT", target=self }
		)		
		think("MESSAGE_PORCH_SUITCASE_INTRO")
		objectPorchSuitcaseMock:ss(kActive)
	end
	
	if (self.shownPorchScare == false and goalInvestigateNoise:isFinished()) then
		self:showPorchScare()
	end

end
-- ----------------------------------------------------------------------------
function layoutPorch:onClickIO(object, x, y)

	if (object == objectPorchCrowloop) then
	
		ghf.cancelAnimation("PorchCrowLoop")
		objectPorchCrowloop:ss(kDone)
		objectPorchCrowflight:ss(kLocked)
		objectPorchCrowflight:animate("PorchCrowFlight",
			{ command="playTrack track=CROW_SCREAM",		target=self	},
			{ startframe=0, 		frametime=65				},
			{ alpha=0											}
		)
		return true

	end
	
	return false

end
-- ----------------------------------------------------------------------------
function layoutPorch:onClickFirefly(object, x, y)

	return Layout.onClickFirefly(self, object, x, y)

end
-- ----------------------------------------------------------------------------
function layoutPorch:animLightFlicker()
	
	local num       = math.random(3, 5)
	local delay		= math.random(4000, 8000)
	
	for i=1, num do
		
		local fadeOut 	= math.random(100, 150)
		local fadeIn	= math.random(100, 150)	
		local alpha 	= math.random(15, 25)
		
		alpha = alpha / 100	
		
		objectPorchBackgroundUnlit:animate("animPorchLightFlicker" .. i,
			{	delay=delay	},
			{	alpha=alpha, 		duration=fadeOut	},
			{	alpha=0,		duration=fadeIn		}
		)
	
		objectPorchBackgroundUnlitFront:animate("animPorchLightFlickerFront" .. i,
			{	delay=delay	},
			{	alpha=alpha, 	duration=fadeOut	},
			{	alpha=0,		duration=fadeIn		}
		)
		
		delay = delay + fadeOut + fadeIn + math.random(100, 200)
				
	end
	
	objectPorchBackgroundLit:animate("animPorchLightFlicker",
		{ delay=delay }
	)
	
	
end
-- ----------------------------------------------------------------------------
function layoutPorch:onAnimationFinish(animationName)

	Layout.onAnimationFinish(self, animationName)

	if (animationName == "PorchCrowLoop") then
		if (objectPorchCrowloop:getState() ~= kDone) then
			animLoop(objectPorchCrowloop, "PorchCrowLoop", 300, 320, 2500, 3500)	
		end
	
	elseif (animationName == "PorchBirdsFlight_blocking") then
		objectPorchBirdsflight:ss(kDone)
	
	elseif (animationName == "PorchShadowScare_blocking") then
		objectPorchShadow:ss(kDone)
		
		ghf.cancelAnimation("PorchBirdsLoop")
		objectPorchBirdsloop:ss(kInactive)
		
		objectPorchBirdsflight:ss(kIdle)
		objectPorchBirdsflight:animate("PorchBirdsFlight_blocking",
			{ startframe=0, 		frametime=65			},
			{ alpha=0										}
		)
		
	--	local delayTime = 7 * 65	-- frame number * bird flight frame time
	--	delayTime = delayTime + 1000
	
	elseif (animationName == "animPorchLightFlicker") then
		
		self:animLightFlicker();
		
	elseif (animationName == "porchRockInsect") then
	
		self:showRockHighlight()
	
	elseif (animationName == "porchShutterShine") then
	
		self:showShutterHiglight()
		
	elseif (animationName == "porchSuitcaseShine") then
	
		self:showSuitcaseHiglight()
		
	elseif (animationName == "porchDoorknobShine") then
	
		self:showDoorknobHiglight()
	
	elseif (animationName == "porchNoteShine") then
		self:showNoteHighlight()
		
	end

end
-- ----------------------------------------------------------------------------
function layoutPorch:onMovieFinish(movieName)

	Layout.onMovieFinish(self, movieName)
	
	if (movieName == kMovieIntro) then
		self:setInputActive(false)
		self.mTimeUntilFirstGoal = 1500	
	end

end
-- ----------------------------------------------------------------------------
function layoutPorch:showPorchScare()
    
    self.shownPorchScare = true
    
    objectPorchShadow:setAlpha(0)
	objectPorchShadow:ss(kIdle)
	objectPorchShadow:animate("PorchShadowScare_blocking",
		{ alpha = 0 									},
		{ command="playTrack track=SHADOW_SCARE_2",		target=self	},
		{ delay=1000	 								},
		{ command="playTrack track=CROW_SCREAM",		target=self	},
		{ alpha = 1 									},
		{ startframe=0, 		frametime=65			}
	)

end
-- ----------------------------------------------------------------------------
function layoutPorch:showRockHighlight()

	if (objectPorchRockInsect:isIdle()) then
		objectPorchRockInsect:animate("porchRockInsect",
			{ delay = math.random(2000, 3000) },
			{ startframe=0, frametime=50 }
		)
	end

end
-- ----------------------------------------------------------------------------
function layoutPorch:showShutterHiglight()

	if (objectPorchMechRustShine:isIdle()) then
		objectPorchMechRustShine:animate("porchShutterShine",
			{ delay = math.random(2000, 3000) },
			{ startframe=0, frametime=50 }
		)
	end

end
-- ----------------------------------------------------------------------------
function layoutPorch:showSuitcaseHiglight()

	if (objectPorchSuitcaseShine:isIdle()) then
		objectPorchSuitcaseShine:animate("porchSuitcaseShine",
			{ delay = math.random(2000, 3000) },
			{ startframe=0, frametime=50 }
		)
	end

end
-- ----------------------------------------------------------------------------
function layoutPorch:showDoorknobHiglight()

	if (objectPorchDoorknobShine:isIdle()) then
		objectPorchDoorknobShine:animate("porchDoorknobShine",
			{ delay = math.random(2000, 3000) },
			{ startframe=0, frametime=50 }
		)
	end

end
-- ----------------------------------------------------------------------------
function layoutPorch:showNoteHighlight()

	if (objectPorchNoteFlapping:isIdle()) then
		objectPorchNoteFlapping:animate("porchNoteShine",
			{ delay = math.random(2000, 8000) },
			{ startframe=0, endframe=8, frametime=75 }
		)		
	end

end
-- ----------------------------------------------------------------------------
function layoutPorch:onStartAudio()

	-- Play some outside noises
	playAmbientAudio(kOutsideHutAmbientGroup)
	
	-- Sweeteners
	local catTrack = {}
	
	catTrack.group = kOutsideHutAmbientGroup
	catTrack.definition = "CAT_SWEETENER_1"
	catTrack.volume = 0.8
	
	getAudioManager():playTrack(catTrack)
	
	-- Check the radio sounds
	if (layoutBedroom ~= nil) then
		layoutBedroom:checkRadioStatic("verySoft")
	end
end
-- ----------------------------------------------------------------------------
function layoutPorch:onClickLocked(object, x, y)

	local isClothing = false
	
	isClothing = isClothing or (object == objectPorchLipstick)
	isClothing = isClothing or (object == objectPorchMakeupbrush)
	isClothing = isClothing or (object == objectPorchMirror)
	isClothing = isClothing or (object == objectPorchParfum)
	isClothing = isClothing or (object == objectPorchRaggedshirt)
	isClothing = isClothing or (object == objectPorchShoe)
	isClothing = isClothing or (object == objectPorchSkirt)
	isClothing = isClothing or (object == objectPorchSock)
	isClothing = isClothing or (object == objectPorchToothbrush)
	isClothing = isClothing or (object == objectPorchWallet)

	if (isClothing) then
		think("MESSAGE_SUITCASE_MISSING")
		return false
	end
	
	return Layout.onClickLocked(self, object, x, y)

end