function add_fibrillation_effector_door_light(obj, delay)
	local duration = 7.0

	eff= CreateAnimationEffector()
	eff:AttachTo(obj)
	eff:SetMode(_ANIM_LOOP)

    local dopacity = -0.

	eff:SetKey(_TRACK_O, 0.0 + delay, 1.0 + dopacity)
	eff:SetKey(_TRACK_O, duration * 1.0/4.0 + delay, 0.75 + dopacity)
	eff:SetKey(_TRACK_O, duration * 2.0/4.0 + delay, 1.0 + dopacity)
	eff:SetKey(_TRACK_O, duration * 3.0/4.0 + delay, 0.59 + dopacity)
	eff:SetKey(_TRACK_O, duration * 4.0/4.0 + delay, 1.0 + dopacity)
	eff:Play()
end

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/26_Backyard_Main.lua', 'quest')

	local condition_16 = function()
		return not HasGameState('LinkDisabled', '26_to_16')
	end
	local on_condition_16_fail = function()
		ShowMonolog('C_26_LINK_TO_16_DISABLED', 'C_26_LINK_TO_16_DISABLED')
		game_state.ignore_on_highlight['area_back_to_16'] = true
		AddGameState('IgnoreOnHighlight', 'area_back_to_16')
	end
	LinkScene('area_back_to_16', 'CursorDoorDown', 'data/Scenes/16_Theatre_Dead_End_Main.lua', false, condition_16, on_condition_16_fail)
	LinkScene('area_ho', 'CursorGlass', 'data/Scenes/26_Backyard_HO.lua', true)
	LinkScene('area_door', 'CursorGlass', 'data/Scenes/26_Rings.lua', false)

	play_field:IgnoreOnTestPoint('Layer_Light_Open_Door')

	if HasGameState('MiniGameCompleted', 'Rings') == true then
		if(mini_game == true) then
			TimerDoString("OpenDoor();", 0.3, play_field:GetTimer())
			mini_game = false;
		else
			play_field:GetObject('Layer_Door_Open'):SetOpacity(1.)
			play_field:GetObject('Layer_Light_Open_Door'):SetOpacity(1.);
			--play_field:GetObject('Layer_Light_Open_Door'):Show()
			LinkScene('area_door', 'CursorDoorUp', 'data/Scenes/27_Master_Hall_Main.lua', false)
		end
	else
		play_field:GetObject('Layer_Door_Open'):SetOpacity(0.)
		play_field:GetObject('Layer_Light_Open_Door'):Hide()
	end

	add_fibrillation_effector_door_light(play_field:GetObject('Layer_Light_Open_Door'), 0.)

	LoadSound('26_doorOpen', 'data/Sound/26_Backyard/DoorOpen.ogg');
	LoadSound('26_sea', 'data/Sound/26_Backyard/Sea.ogg');
	
	MakeSoundEntity('26_sea'):Play(true);
	
	local showPlayGroundComment = function(obj_name)
	    ShowMonolog('play_garden_monolog', SelectRandom('C_26_PLAYGARDEN_1', 'C_26_PLAYGARDEN_2'));
		game_state.ignore_on_highlight['area_playgarden_1'] = true
		game_state.ignore_on_highlight['area_playgarden_2'] = true
	end
	local on_area_playgarden_clicked = function(obj_name)	
		game_state.ignore_on_highlight['area_playgarden_1'] = true
		game_state.ignore_on_highlight['area_playgarden_2'] = true
	end
	RegisterActiveObject('area_playgarden_1', showPlayGroundComment, on_area_playgarden_clicked, true, 'CursorGlass');
	RegisterActiveObject('area_playgarden_2', showPlayGroundComment, on_area_playgarden_clicked, true, 'CursorGlass');
	
end

function OpenDoor()
	play_field:GetObject('Layer_Door_Open'):ChangeOpacity(0., 1., 0.3)
	play_field:GetObject('Layer_Light_Open_Door'):Show()
	game_state.locked_objects['area_door'] = false
	LinkScene('area_door', 'CursorDoorUp', 'data/Scenes/27_Master_Hall_Main.lua', false)
	PlaySound('26_doorOpen');
end

function OnSceneFree(screen)
    DefaultOnSceneFree()
    FreeData(screen)
end

function OnUpdate(dt)
    DefaultOnUpdate(dt)
end

function OnAllItemsFound()
    DefaultOnAllItemsFound()
end

function OnLose()
    DefaultOnLose()
end

function OnExit()
    DefaultOnExit()
end

function OnClose()
    DefaultOnClose()
end

function OnObjectMouseEnter(object)
    DefaultOnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
    DefaultOnObjectMouseLeave(object)
end

function OnObjectMouseDown(object)
    local is_wrong_click = not DefaultOnObjectMouseDown(object)
    local obj_name = object:GetName()
    local pf = play_field

    DefaultOnObjectMouseDownProcessed(is_wrong_click);
end

function OnObjectMouseUp(object)
    DefaultOnObjectMouseUp(object)
end

function OnObjectFound(object)
    DefaultOnObjectFound(object)
end

function OnToolFound(tool)
    DefaultOnToolFound(tool)
end

function OnToolApply(tool, object)
    DefaultOnToolApply(tool, object)
end

function OnObjectReachPanel(object)
    DefaultOnObjectReachPanel(object)
end

function OnButtonPress(title)
    DefaultOnButtonPress(title)
end

function OnMouseMove(previous_pos, current_pos)
    DefaultOnMouseMove(previous_pos, current_pos)
end

function OnSetTool(tool)
    DefaultOnSetTool(tool)
end

function LevelLoaded(level)
    local screen = level;

    local anim = screen:CreateAnimation('data/Texture/Scenes/Common/Clouds.png');
	anim:SetPosXY(512, 220);
	anim:SetOpacity(0.6);
	anim:SetScaleXY(1, 1.057);
	anim:SetPosZ(47);

	local effector = CreateTextureEffector();
	effector:AttachToAnimation(anim);
	effector:SetSpeed(-16);
	effector:Play();
end

function OnSceneDestroy(playfield)
    DefaultOnSceneDestroy(playfield)
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData(screen)
	local anim = CreateAnimation('data/Texture/Scenes/26_Backyard/Zone_Main/Layers/BG_Backyard.JPG',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_Backyard',anim,512,384,45,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/26_Backyard/Zone_Main/Layers/Layer_Top.PNG',0,0,1024,452,1,0)
	anim:SetHotSpot(0,0)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Top',anim,0,0,50,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_door',anim,737,419,110,0,17,23)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_back_to_16',anim,792,710,100,0,60,15)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_ho',anim,908,438,100,0,20,20)
	local anim = CreateAnimation('data/Texture/Scenes/26_Backyard/Zone_Main/Layers/Layer_Light_Open_Door.PNG',0,0,270,230,1,0)
	anim:SetHotSpot(135,115)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Light_Open_Door',anim,648,371,57,0,2,2)
	local anim = CreateAnimation('data/Texture/Scenes/26_Backyard/Zone_Main/Layers/Layer_Door_Open.PNG',0,0,118,193,1,0)
	anim:SetHotSpot(59,96)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_Door_Open',anim,728,420,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_playgarden_1',anim,360,500,100,-65,25,10)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_playgarden_2',anim,542,500,100,0,12,13.5)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
