function CreateZoomZoneClock()
    local zone = CreateZoomZone('area_clock',
                                'ZoomZoneClock',
                                 'zz_background',        true,
                                 'shesterenka_1',        false,
                                 'shesterenka_1_shadow', false,
                                 'shesterenka_2',        false,
                                 'shesterenka_2_shadow', false,
                                 'butil',       true,
                                 'overwood',    true,
                                 'Steklo_1',    true,
                                 'Steklo_2',    false,
                                 'Steklo_3',    false,
                                 'krishka',     true,
                                 'vint_1',      true,
                                 'vint_2',      true,
                                 'vint_3',      true,
                                 'vint_4',      true,
                                 'area_glass',  true,
                                 'area_1',      true,
                                 'area_2',      true,
                                 'area_3',      true,
                                 'area_4',      true);
    
    zone.on_open = function()
         play_field:GetObject('area_glass'):GetAnimation():SetColor('0x01FFFFFF')
         CreatePlayAnimation(play_field:GetObject('shesterenka_1'), M_TWO_PI)
         CreatePlayAnimation(play_field:GetObject('shesterenka_1_shadow'), M_TWO_PI)
         CreatePlayAnimation(play_field:GetObject('shesterenka_2'), -M_TWO_PI)
         CreatePlayAnimation(play_field:GetObject('shesterenka_2_shadow'), -M_TWO_PI)
         
         if game_state.mg_cover_hided then
            PlayPinionsSound();
         end
    end
    
    zone.on_close = function()
        StopPinionsSound();
    end
    
    play_field:GetObject('vint_1'):SetClipping(512-320, 384-240, 640, 480);
    play_field:GetObject('vint_2'):SetClipping(512-320, 384-240, 640, 480);
    play_field:GetObject('vint_3'):SetClipping(512-320, 384-240, 640, 480);
    play_field:GetObject('vint_4'):SetClipping(512-320, 384-240, 640, 480);
    
    RegisterActiveObject('krishka',    function(obj_name)
                                            ShowMonolog('C_15_ON_COVER_MECHANISM', 'C_15_ON_COVER_MECHANISM')
                                        end,
                                        function(obj_name)
                                        end,
                                        true)
                                        
    RegisterActiveObject('area_glass', function(obj_name)
                                            ShowMonolog('C_15_ON_GLASS_MECHANISM', 'C_15_ON_GLASS_MECHANISM')
                                        end,
                                        function(obj_name)
                                        end,
                                        true)
                                        
    RegisterActiveObject('Steklo_2', function(obj_name)
                                            ShowMonolog('C_15_ON_GLASS_MECHANISM', 'C_15_ON_GLASS_MECHANISM')
                                        end,
                                        function(obj_name)
                                        end,
                                        true)
    
    --[[
    if not HasGameState('ToolFound', '15_screwdriver') then
        FindTool('15_screwdriver')
    end
    if not HasGameState('ToolFound', '15_wrench') then
        FindTool('15_wrench')
    end
    if not HasGameState('ToolFound', '13_stone') then
        FindTool('13_stone')
    end
    --]]
    
    game_state.FALL_TIME = 2
    
    return zone;
end

function SetShesterenkiVisible()
    zoom_clock.SetObjectVisible('shesterenka_1', true)
    zoom_clock.SetObjectVisible('shesterenka_1_shadow', true)
    zoom_clock.SetObjectVisible('shesterenka_2', true)
    zoom_clock.SetObjectVisible('shesterenka_2_shadow', true)
end

function CreatePlayAnimation(obj, angle)
    local time = 5
    local af = CreateAnimationEffector()
    af:AttachTo(obj)
    af:SetMode(_ANIM_LOOP)
    af:SetKey(_TRACK_A, 0, 0)
    af:SetKey(_TRACK_A, time, angle)
    af:Play()
end

function VintAnimation(vint)
    local time = game_state.FALL_TIME;
    local af = CreateAnimationEffector()
    af:AttachTo(vint)
    af:SetKey(_TRACK_A, 0, 0)
    af:SetKey(_TRACK_A, time*0.5, 2 * M_TWO_PI)
    af:SetKey(_TRACK_Y, time*0.5, vint:GetY())
    af:SetKey(_TRACK_Y, time, vint:GetY() + 1000)
    af:Play()
end

function CheckVints()
    return  game_state.wrench_applied and
            game_state.screwdriver_applied;
end

function HideCover(time)
    zoom_clock.SetObjectVisible('krishka', false, time)
    SetShesterenkiVisible();
    
    game_state.mg_cover_hided = true;
    
    if time == 0 then
        play_field:GetObject('Clock_2'):SetOpacity(1);
        play_field:GetObject('Clock_1'):SetOpacity(0);
    else
        play_field:GetObject('Clock_2'):ChangeOpacity(0, 1, time);
        play_field:GetObject('Clock_1'):ChangeOpacity(1, 0, time);
    end
end

function ScrewdriverOnApply(tool_name)
    game_state.screwdriver_applied = true;
    
    VintAnimation(play_field:GetObject('vint_4'))
    TimerDoString('zoom_clock.SetObjectVisible("vint_4", false, 1)', game_state.FALL_TIME, play_field:GetTimer())
    zoom_clock.SetObjectVisible("area_4", false);
    
    PlaySound('15_ScrewdriverApply');
    
    if CheckVints() then
        TimerDoString("HideCover(0.5)", game_state.FALL_TIME, play_field:GetTimer());
        
        play_field:TimerDoString("PlayPinionsSound()", game_state.FALL_TIME);
    end
end

function ScrewdriverOnApplied(tool_name)
    game_state.screwdriver_applied = true;
    
    zoom_clock.SetObjectVisible("vint_4", false)
    zoom_clock.SetObjectVisible("area_4", false)
    
    if CheckVints() then
        HideCover(0)
    end
end

function WrenchOnApply(tool_name, object_name)
    if object_name == 'area_1' then
        VintAnimation(play_field:GetObject('vint_1'))
        TimerDoString('zoom_clock.SetObjectVisible("vint_1", false, 1)', game_state.FALL_TIME, play_field:GetTimer())
        zoom_clock.SetObjectVisible("area_1", false)
        PlaySound('15_WrenchApply')
        
    elseif object_name == 'area_2' then
        VintAnimation(play_field:GetObject('vint_2'))
        TimerDoString('zoom_clock.SetObjectVisible("vint_2", false, 1)', game_state.FALL_TIME, play_field:GetTimer())
        zoom_clock.SetObjectVisible("area_2", false)
        PlaySound('15_WrenchApply2')
        
    elseif object_name == 'area_3' then
        VintAnimation(play_field:GetObject('vint_3'))
        TimerDoString('zoom_clock.SetObjectVisible("vint_3", false, 1)', game_state.FALL_TIME, play_field:GetTimer())
        zoom_clock.SetObjectVisible("area_3", false)
        PlaySound('15_WrenchApply3')
        
    else
        game_state.wrench_applied = true;
        
        if CheckVints() then
            TimerDoString("HideCover(0.5)", game_state.FALL_TIME, play_field:GetTimer());
            
            play_field:TimerDoString("PlayPinionsSound()", game_state.FALL_TIME);
        end
    end                                       
end

function WrenchOnApplied(tool_name, object_name)
    if object_name == 'area_1' then
        zoom_clock.SetObjectVisible('vint_1', false)
        zoom_clock.SetObjectVisible("area_1", false)
    elseif object_name == 'area_2' then
        zoom_clock.SetObjectVisible('vint_2', false)
        zoom_clock.SetObjectVisible("area_2", false)
    elseif object_name == 'area_3' then
        zoom_clock.SetObjectVisible('vint_3', false)
        zoom_clock.SetObjectVisible("area_3", false)
    else
        game_state.wrench_applied = true;
        for i = 1, 3 do
            zoom_clock.SetObjectVisible('vint_' .. i, false)
            zoom_clock.SetObjectVisible("area_" .. i, false)
        end
        
        if CheckVints() then
            HideCover(0)
        end
    end                            
end

function StoneOnApply(tool_name, object_name)
    if object_name == 'area_glass' then
        zoom_clock.SetObjectVisible('Steklo_2', true, 0.3)
        zoom_clock.SetObjectVisible('area_glass', false, 0)
        play_field:GetObject('Steklo_2'):SetZ(159)
        
        PlaySound('15_SmashGlass');
        
    elseif object_name == 'Steklo_2' then
        zoom_clock.SetObjectVisible('Steklo_2', false, 0.2)
        zoom_clock.SetObjectVisible('Steklo_3', true, 0.3)
        play_field:GetObject('Steklo_3'):SetZ(159)
        
        PlaySound('15_SmashGlass2');
    else
        zoom_clock.SetObjectVisible('Steklo_2', false, 0.2)
        zoom_clock.SetObjectVisible('Steklo_3', true, 0.3)
        
        play_field:GetObject('Clock_3'):ChangeOpacity(0, 1, 0.2);
        play_field:GetObject('Clock_2'):ChangeOpacity(1, 0, 0.2);
        
        play_field:IgnoreOnTestPoint('Steklo_1')
        play_field:IgnoreOnTestPoint('Steklo_3')
    end                                       
end

function StoneOnApplied(tool_name, object_name)
    if object_name == 'area_glass' then
        zoom_clock.SetObjectVisible('Steklo_2', true)
        zoom_clock.SetObjectVisible('area_glass', false)
        play_field:GetObject('Steklo_2'):SetZ(159)
        
    elseif object_name == 'Steklo_2' then
        zoom_clock.SetObjectVisible('Steklo_2', false)
        zoom_clock.SetObjectVisible('Steklo_3', true)
        play_field:GetObject('Steklo_3'):SetZ(159)
        
    else
        zoom_clock.SetObjectVisible('Steklo_2', false)
        zoom_clock.SetObjectVisible('Steklo_3', true)
        zoom_clock.SetObjectVisible('area_glass', false)
        
        play_field:GetObject('Clock_3'):SetOpacity(1);
        play_field:GetObject('Clock_2'):SetOpacity(0);
        
        play_field:IgnoreOnTestPoint('Steklo_1')
        play_field:IgnoreOnTestPoint('Steklo_3')
    end                                       
end

function PlayPinionsSound()
    play_field.pinionsSound = MakeSoundEntity('15_Pinions');
    play_field.pinionsSound:Play(true);
end

function StopPinionsSound()
    if play_field.pinionsSound then
        play_field.pinionsSound:StopSound();
        play_field.pinionsSound = nil;
    end
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData_zoomZoneClock(screen)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/background.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zz_background',anim,512,384,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/shesterenka_1.png',0,0,136,137,1,0)
	anim:SetHotSpot(68,68)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('shesterenka_1',anim,329,214,152,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/shesterenka_1_shadow.png',0,0,139,139,1,0)
	anim:SetHotSpot(69,69)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('shesterenka_1_shadow',anim,317,231,151,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/shesterenka_2.png',0,0,113,113,1,0)
	anim:SetHotSpot(56,56)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('shesterenka_2',anim,390,316,152,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/shesterenka_2_shadow.png',0,0,114,114,1,0)
	anim:SetHotSpot(57,57)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('shesterenka_2_shadow',anim,379,327,151,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/butil.png',0,0,117,170,1,0)
	anim:SetHotSpot(58,85)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('butil',anim,309,547,154,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/overwood.png',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('overwood',anim,512,384,155,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/Steklo_1.png',0,0,566,437,1,0)
	anim:SetHotSpot(283,218)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Steklo_1',anim,512,384,158,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/Steklo_2.png',0,0,444,387,1,0)
	anim:SetHotSpot(222,193)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Steklo_2',anim,430,426,157,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/Steklo_3.png',0,0,478,438,1,0)
	anim:SetHotSpot(239,219)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Steklo_3',anim,470,387,156,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/krishka.png',0,0,598,458,1,0)
	anim:SetHotSpot(299,229)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('krishka',anim,512,384,161,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/vint_1.png',0,0,38,40,1,0)
	anim:SetHotSpot(19,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('vint_1',anim,247,182,162,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/vint_2.png',0,0,40,41,1,0)
	anim:SetHotSpot(20,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('vint_2',anim,780,182,162,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/vint_3.png',0,0,40,38,1,0)
	anim:SetHotSpot(20,19)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('vint_3',anim,242,586,162,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_mechanizm/vint_4.png',0,0,40,40,1,0)
	anim:SetHotSpot(20,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('vint_4',anim,780,585,162,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_glass',anim,512,384,160,0,65,50)
	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_1',anim,247,182,165,0,15,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_2',anim,780,182,165,0,15,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_3',anim,242,586,165,0,15,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_4',anim,780,585,165,0,15,15)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
