layoutPorchWindowMechdetail.ragUseCount = 0
layoutPorchWindowMechdetail.antirustUseCount = 0
layoutPorchWindowMechdetail.foamFadeOutTime = 1250
layoutPorchWindowMechdetail.manualFound = false
layoutPorchWindowMechdetail.timeDelayBeforeShutterOpening = 1000
-- ----------------------------------------------------------------------------
layoutPorchWindowMechdetail.mExits =
{
}
layoutPorchWindowMechdetail.mPOIs = 
{
}
layoutPorchWindowMechdetail.mHOs = 
{
}
layoutPorchWindowMechdetail.mIOs =
{
	[objectPorchWindowMechdetailPin] = 
	{
		links = {objectPorchWindowlever},
	},
	[objectPorchWindowMechdetailRust1] = 
	{
		links = {objectShedLawnmowerAntirust},
		mirrors = {objectPorchWindowMechdetailRust2, objectPorchWindowMechdetailRust3},
	},
	[objectPorchWindowMechdetailRust1FRdy] = 
	{
		links = {objectShedRag},
		mirrors = {objectPorchWindowMechdetailRust2FRdy, objectPorchWindowMechdetailRust3FRdy},
	},
	[objectPorchWindowMechdetailScrewOnly] = 
	{
		links = {objectShedScrewdriver},
	},
	[objectPorchWindowMechdetailScrewhole] = 
	{
		links = {objectShedScrew},
	},
	[objectIoWindowShutterManual] = 
	{
	},
	[objectIoWindowShutterManualOpen] = 
	{
	},
}
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:onConstruct()

	Layout.onConstruct(self)

	objectPorchWindowMechdetailClean:ss(kInactive)
	objectPorchWindowMechdetailScrew:ss(kInactive)
	objectPorchWindowMechdetailScrewOnly:ss(kInactive)
	objectPorchWindowMechdetailScrewhole:ss(kInactive)
	objectPorchWindowMechdetailLeverDown:ss(kInactive)
	objectPorchWindowMechdetailScrewAffix:ss(kInactive)
	objectPorchWindowMechdetailLever:ss(kInactive)
	objectPorchWindowMechdetailLeverAffix:ss(kDone)
	
	objectPorchWindowMechdetailRust1:ss(kActive)
	objectPorchWindowMechdetailRust2:ss(kActive)
	objectPorchWindowMechdetailRust3:ss(kActive)
	objectPorchMechRustFoam1:ss(kInactive)
	objectPorchMechRustFoam2:ss(kInactive)
	objectPorchMechRustFoam3:ss(kInactive)
	objectPorchWindowMechRustFoam1:ss(kInactive)
	objectPorchWindowMechRustFoam2:ss(kInactive)
	objectPorchWindowMechRustFoam3:ss(kInactive)
	objectPorchWindowMechdetailRustFoam1:ss(kInactive)
	objectPorchWindowMechdetailRustFoam2:ss(kInactive)
	objectPorchWindowMechdetailRustFoam3:ss(kInactive)
	objectPorchWindowMechdetailRust1FRdy:ss(kInactive)
	objectPorchWindowMechdetailRust2FRdy:ss(kInactive)
	objectPorchWindowMechdetailRust3FRdy:ss(kInactive)
	objectPorchWindowMechdetailPin:ss(kIdle)
	
	objectIoWindowShutterManual:ss(kInactive)
	objectIoWindowShutterManualOpen:ss(kInactive)

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

	if (object == objectIoWindowShutterManual) then	
		-- the user found the manual here
		-- remove the other manual in the drawer
		objectShedShuttermanualManualClosed:ss(kDone)
	
		objectIoWindowShutterManual:ss(kInactive)
		objectIoWindowShutterManualOpen:ss(kActive)
		playAudioTrack("MANUAL_PAGE")
		return true, false
	
	elseif (object == objectIoWindowShutterManualOpen) then
		objectIoWindowShutterManual:ss(kActive)
		objectIoWindowShutterManualOpen:ss(kInactive)
		playAudioTrack("MANUAL_PAGE")
		return true, false
		
	end

	if (gSelection == objectShedLawnmowerAntirust) then
		
		if (object == objectPorchWindowMechdetailRust1) then
			objectPorchMechRust1:ss(kDone)
			objectPorchWindowMechRust1:ss(kDone)
			objectPorchMechRustFoam1:ss(kIdle)
			objectPorchWindowMechRustFoam1:ss(kIdle)
			objectPorchWindowMechdetailRust1FRdy:ss(kActive)
			
			objectPorchWindowMechdetailRustFoam1:setAlpha(1)
			objectPorchWindowMechdetailRustFoam1:ss(kIdle)
			
			local foamY = objectPorchWindowMechdetailRustFoam1:y()
			objectPorchWindowMechdetailRustFoam1:setY(foamY - 10)
			
			objectPorchWindowMechdetailRustFoam1:animate("applyFoam1",
				{ 
					{alpha=0,		duration=self.foamFadeOutTime},
					{ y = foamY, style="easeInOut", duration = self.foamFadeOutTime}
				}
			)
			
			self:removeAntirustObject(object)
			return true
		end
		
		if (object == objectPorchWindowMechdetailRust2) then
			objectPorchMechRust2:ss(kDone)
			objectPorchWindowMechRust2:ss(kDone)
			objectPorchMechRustFoam2:ss(kIdle)
			objectPorchWindowMechRustFoam2:ss(kIdle)
			objectPorchWindowMechdetailRust2FRdy:ss(kActive)
			
			objectPorchWindowMechdetailRustFoam2:setAlpha(1)
			objectPorchWindowMechdetailRustFoam2:ss(kIdle)
			
			local foamY = objectPorchWindowMechdetailRustFoam2:y()
			objectPorchWindowMechdetailRustFoam2:setY(foamY - 10)
			
			objectPorchWindowMechdetailRustFoam2:animate("applyFoam2",
				{ 
					{alpha=0,		duration=self.foamFadeOutTime},
					{ y = foamY, style="easeInOut", duration = self.foamFadeOutTime}
				}
			)
			
			self:removeAntirustObject(object)
			return true
		end
		
		if (object == objectPorchWindowMechdetailRust3) then
			objectPorchMechRust3:ss(kDone)
			objectPorchWindowMechRust3:ss(kDone)
			objectPorchMechRustFoam3:ss(kIdle)
			objectPorchWindowMechRustFoam3:ss(kIdle)
			objectPorchWindowMechdetailRust3FRdy:ss(kActive)
			
			objectPorchWindowMechdetailRustFoam3:setAlpha(1)
			objectPorchWindowMechdetailRustFoam3:ss(kIdle)
			
			local foamY = objectPorchWindowMechdetailRustFoam3:y()
			objectPorchWindowMechdetailRustFoam3:setY(foamY - 10)
			
			objectPorchWindowMechdetailRustFoam3:animate("applyFoam3",
				{ 
					{alpha=0,		duration=self.foamFadeOutTime},
					{ y = foamY, style="easeInOut", duration = self.foamFadeOutTime}
				}
			)
			
			self:removeAntirustObject(object)
			return true	
		end
		
	elseif (gSelection == objectShedRag) then
		
		if (object == objectPorchWindowMechdetailRust1FRdy) then
			objectPorchMechRustFoam1:ss(kDone)
			objectPorchWindowMechRustFoam1:ss(kDone)
			
			object:setAlpha(1)
			object:ss(kIdle)
			object:animate("removeFoam1_blocking",
				{ alpha=0,		duration=kTimeFadeSwitch	}
			)
			
			return true
		end
		
		if (object == objectPorchWindowMechdetailRust2FRdy) then
			objectPorchMechRustFoam2:ss(kDone)
			objectPorchWindowMechRustFoam2:ss(kDone)
			
			object:setAlpha(1)
			object:ss(kIdle)
			object:animate("removeFoam2_blocking",
				{ alpha=0,		duration=kTimeFadeSwitch	}
			)

			return true
		end
		
		if (object == objectPorchWindowMechdetailRust3FRdy) then
			objectPorchMechRustFoam3:ss(kDone)
			objectPorchWindowMechRustFoam3:ss(kDone)
			
			object:setAlpha(1)
			object:ss(kIdle)
			object:animate("removeFoam3_blocking",
				{ alpha=0,		duration=kTimeFadeSwitch	}
			)
			
			return true	
		end
	
	else
	
		if ((object == objectPorchWindowMechdetailRust1) or
		 	(object == objectPorchWindowMechdetailRust2) or
		 	(object == objectPorchWindowMechdetailRust3) or
		 	(object == objectPorchWindowMechdetailRust1FRdy) or
		 	(object == objectPorchWindowMechdetailRust2FRdy) or
		 	(object == objectPorchWindowMechdetailRust3FRdy) 
		   ) then
		 	
		 	think("MESSAGE_PORCH_WINDOW_NEEDS_CLEAN")
		 	
		end
	
	end
	
	return Layout.onClickIO(self, object, x, y)
	
end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:onSolveStart()
	Layout.onSolveStart(self)
	
	self:solveFinish()
	
	--self:placeLever()
	layoutPorchWindowMechdetail:hide()
	layoutPorchWindow:hide()
		
	objectPorchWindowMechdetailLeverDown:ss(kDone)
	objectPorchWindowMechdetailScrewAffix:ss(kDone)
	objectPorchWindowMechdetailLever:ss(kDone)
		
	objectPorchWindowMechdetailLeverDown:animate("delayBeforeShutterOpening",
		{ delay=self.timeDelayBeforeShutterOpening	}
	)
end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:removeAntirustObject(object)

	self.antirustUseCount = self.antirustUseCount + 1
	object:ss(kDone)
	
	playAudioTrack("RUST_SPRAY")
	
	if (self.antirustUseCount == 3) then
		objectShedLawnmowerAntirust:ss(kUsed)
	else
		objectShedLawnmowerAntirust:ss(kSelected)
	end
	
end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:removeRagObject(object)
	self.ragUseCount = self.ragUseCount + 1
	object:ss(kDone)
	
	playAudioTrack("RUST_RUB")
	
	if (self.ragUseCount == 3) then
		objectShedRag:ss(kUsed)
		self:removedRust()
	else
		objectShedRag:ss(kSelected)
	end
end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:onUsedAll(object, props)

	if (object == objectPorchWindowMechdetailScrewhole) then
		
		self:placeScrew()
		return true
	
	elseif (object == objectPorchWindowMechdetailScrewOnly) then
		
		self:placeScrewDriver()
		return true
	
	elseif (object == objectPorchWindowMechdetailPin) then
		
		--self:solve()
		self:placeLever()
		return true
		
	end
	
	return Layout.onUsedAll(self, object, props)
	
end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:removedRust()
	
	-- update parent layouts first:
	objectPorchMechRusty:ss(kDone)
	objectPorchWindowMechRusty:ss(kDone)
	objectPorchMechClean:ss(kIdle)
	objectPorchWindowMechClean:ss(kActive)
	
	objectPorchWindowMechdetailClean:ss(kIdle)
	objectPorchWindowMechdetailRusty:animate("animRemoveRust_blocking",
		{ alpha=0,		duration=kTimeFadeSwitch	}
	)

end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:placeScrew()

	-- update parent layouts first:
	objectPorchMechClean:ss(kDone)
	objectPorchMechScrew:ss(kActive)
	objectPorchWindowMechClean:ss(kDone)
	objectPorchWindowMechScrew:ss(kActive)
	
	objectPorchWindowMechdetailScrewhole:ss(kDone)
	objectPorchWindowMechdetailScrew:setAlpha(0)
	objectPorchWindowMechdetailScrew:ss(kIdle)
	objectPorchWindowMechdetailScrew:animate("animPlaceScrew_blocking",
		{ alpha=1,		duration=kTimeFadeSwitch	}
	)
	objectPorchWindowMechdetailClean:animate(
		{ alpha=0,		duration=kTimeFadeSwitch	}
	)

end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:placeScrewDriver()

	-- update parent layouts first:
	objectPorchMechScrew:ss(kDone)
	objectPorchMechScrewAffix:ss(kActive)
	objectPorchWindowMechScrew:ss(kDone)
	objectPorchWindowMechScrewAffix:ss(kActive)
	
	objectPorchWindowMechdetailScrewOnly:ss(kDone)
	objectPorchWindowMechdetailScrew:ss(kIdle)
	objectPorchWindowMechdetailScrewAffix:setAlpha(0)
	objectPorchWindowMechdetailScrewAffix:ss(kIdle)
	objectPorchWindowMechdetailScrewAffix:animate("animScrewScrew_blocking",
		{ alpha=1,		duration=kTimeFadeSwitch	}
	)
	objectPorchWindowMechdetailScrew:animate(
		{ alpha=0,		duration=kTimeFadeSwitch	}
	)

end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:placeLever()
	
	-- update parent layouts first:
	objectPorchMechScrewAffix:ss(kDone)
	objectPorchWindowMechScrewAffix:ss(kDone)

	objectPorchWindowMechdetailPin:ss(kIdle)
	objectPorchWindowMechdetailLever:setAlpha(0)
	objectPorchWindowMechdetailLever:ss(kIdle)
	objectPorchWindowMechdetailLever:animate("animPlaceLever_blocking",
		{ alpha=0								},
		{ alpha=1,		duration=200			}
	)	

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

	Layout.onAnimationFinish(self, animationName)
	
	
	if (animationName == "applyFoam1") then
		objectPorchWindowMechdetailRustFoam1:ss(kDone)

	elseif (animationName == "applyFoam2") then
		objectPorchWindowMechdetailRustFoam2:ss(kDone)
	
	elseif (animationName == "applyFoam3") then
		objectPorchWindowMechdetailRustFoam3:ss(kDone)
		
	elseif (animationName == "removeFoam1_blocking") then
		self:removeRagObject(objectPorchWindowMechdetailRust1FRdy)
	
	elseif (animationName == "removeFoam2_blocking") then
		self:removeRagObject(objectPorchWindowMechdetailRust2FRdy)
		
	elseif (animationName == "removeFoam3_blocking") then
		self:removeRagObject(objectPorchWindowMechdetailRust3FRdy)
			
	elseif (animationName == "animRemoveRust_blocking") then
		objectPorchWindowMechdetailRusty:ss(kDone)
		objectPorchWindowMechdetailScrewhole:ss(kActive)
		
	elseif (animationName == "animPlaceScrew_blocking") then
		objectPorchWindowMechdetailClean:ss(kDone)
		objectPorchWindowMechdetailScrew:ss(kIdle)
		objectPorchWindowMechdetailScrewOnly:ss(kActive)
		
	elseif (animationName == "animScrewScrew_blocking") then
		objectPorchWindowMechdetailScrew:ss(kDone)
		objectPorchWindowMechdetailPin:ss(kActive)
		
	elseif (animationName == "animPlaceLever_blocking") then
		objectPorchWindowMechdetailPin:ss(kDone)
		
		objectPorchWindowMechdetailLever:animate("animLowerLever_blocking",
			{ alpha=0,		duration=900	},
			{ delay=300						}
		)	
		objectPorchWindowMechdetailLeverDown:setAlpha(0)
		objectPorchWindowMechdetailLeverDown:ss(kIdle)
		objectPorchWindowMechdetailLeverDown:animate(
			{ alpha=0									},
			{ alpha=1,		duration=kTimeFadeSwitch	}
		)
	
	elseif (animationName == "animLowerLever_blocking") then

		layoutPorchWindowMechdetail:solve()
		
	elseif (animationName == "delayBeforeShutterOpening") then		
		
		crossFadeImages(objectPorchShutterClosed, objectPorchShutterOpen, "openShutters_blocking")
	
	elseif (animationName == "openShutters_blocking") then
		objectPorchShutterClosed:ss(kDone)
		
	end

end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:onShow()

	if (self.manualFound == true) then
		objectIoWindowShutterManual:ss(kActive)
	else
		objectIoWindowShutterManual:ss(kInactive)
	end
	objectIoWindowShutterManualOpen:ss(kInactive)

	Layout.onShow(self)

end
-- ----------------------------------------------------------------------------
function layoutPorchWindowMechdetail:isSkippable()

	return false

end