function frame1()
  RotateObject(8,0,8,0.45)
  StartTimer(timerID,0.5,"frame2")
end

function frame2()
  RotateObject(8,8,-8,0.95)
  StartTimer(timerID,1,"frame3")
end

function frame3()
  RotateObject(8,-8,8,0.95)
  StartTimer(timerID,1,"frame2")
end

function frame4()
  
  SetAlfa(10,0,1,1,"frame5")
end

function frame5()
  SetAlfa(10,1,0,1)
  SetAlfa(9,0,1,1)
  SetAlfa(obj.gems_17_14.id,0,1,1,"unBlock_Show_Cur")
end

function mini_create()
  init_mini(true)
  create_mini(8128);
  for i=1,5 do
    setCursor(i,4)
  end
end

if not flags.gruz1 then
  setCursor(2,13)
  setcolor(3,1,1,1,0)
end

if not flags.gruz2 then
  setCursor(4,13)
  setcolor(5,1,1,1,0)
end

if flags.clockMidComplete then
  -- frame1()
  RotateObject(8,0,8,0.45)
else
  setcolor(9,1,1,1,0)
  setcolor(10,1,1,1,0)
  setcolor(obj.gems_17_14.id,1,1,1,0)
  if flags.gruz1 and flags.gruz2 then
    miniCreate()
  end
end

if not flags.state then
  flags.state = {1,3,5}
end
local a = 50
local n = 0
local old = {}
local b = false

-- init ----------
set_pos_in_img(1,0,0+(5-flags.state[1])*a,91,473)
set_pos_in_img(2,91,0+(5-flags.state[2])*a,56,333)
set_pos_in_img(4,147,160+(5-flags.state[3])*a,56,333)
SetObjectPosition(3,500,(358-(5-flags.state[2])*a))
SetObjectPosition(5,635,(359-(5-flags.state[3])*a))
-------------------



function gameinput (sender,obj_id,attachedID)
  MiniInterfaceHandler(sender, obj_id,attachedID);
  sendersProcessing(sender,obj_id,attachedID)
  if wrongItemWarning(sender, obj_id, attachedID, "gruz_16_1","gruz_19_1") then
    return
  end
  if sender == 1 then
    if flags.gruz1 and flags.gruz2 and not flags.clockMidComplete then
      if obj_id == 1 then
        if flags.state[1] < 5 and flags.state[2] > 1 then
          old[1],old[2],old[3] = flags.state[1],flags.state[2],flags.state[3]
          flags.state[1] = flags.state[1] + 1
          flags.state[2] = flags.state[2] - 1
          n = 0
          Block_Show_Cur(true)
          update()
          playeffect("mayat_m")
        end
      end
      if obj_id == 2 or obj_id == 3 then
        if flags.state[2] < 5 and flags.state[3] > 1 then
          old[1],old[2],old[3] = flags.state[1],flags.state[2],flags.state[3]
          flags.state[2] = flags.state[2] + 1
          flags.state[3] = flags.state[3] - 1
          n = 0
          Block_Show_Cur(true)
          update()
          playeffect("mayat_m")
        end
      end
      if obj_id == 4 or obj_id == 5 then
        if flags.state[3] < 5 and flags.state[1] > 1 then
          old[1],old[2],old[3] = flags.state[1],flags.state[2],flags.state[3]
          flags.state[3] = flags.state[3] + 1
          flags.state[1] = flags.state[1] - 1
          n = 0
          Block_Show_Cur(true)
          update()
          playeffect("mayat_m")
        end
      end
      
    else
    
      if obj_id == obj.gems_17_14.id then
        StoreObj(obj.gems_17_14.id)
        neighbors.MidCyferblat.lock = true
      end
      if obj_id == 2 then
        if (obj.gruz_16_1 and attachedID == obj.gruz_16_1.id)
        or (obj.gruz_19_1 and attachedID == obj.gruz_19_1.id) then
          removeFromMouse()
          UnStoreObj(attachedID)
          flags.gruz1 = true
          playeffect("mayat")
          Block_Show_Cur(true)
          SetAlfa(3,0,1,1,"unBlock_Show_Cur")
          if flags.gruz1 and flags.gruz2 then
            miniCreate()
          end
        else
          CreatePlashechka("667")
        end
      end
      if obj_id == 4 then
        if (obj.gruz_16_1 and attachedID == obj.gruz_16_1.id)
        or (obj.gruz_19_1 and attachedID == obj.gruz_19_1.id) then
          removeFromMouse()
          UnStoreObj(attachedID)
          flags.gruz2 = true
          playeffect("mayat")
          Block_Show_Cur(true)
          SetAlfa(5,0,1,1,"unBlock_Show_Cur")
          if flags.gruz1 and flags.gruz2 then
            miniCreate()
          end
        else
          CreatePlashechka("667")
        end
      end
    end
  end
  
  if sender == 7 and obj_id == 8 then
    b = not b
    if b then
      RotateObject(8,8,-8,0.95)
    else
      RotateObject(8,-8,8,0.95)
    end
  end
  
  if sender == 10 then
    flags.clockMidComplete = true
    -- frame1()
    RotateObject(8,0,8,0.45)
    Block_Show_Cur(true)
set_pos_in_img(1,0,100,91,373)
set_pos_in_img(2,91,100,56,233)
set_pos_in_img(4,147,260,56,233)    
SetObjectPosition(3,500,358-100)
SetObjectPosition(5,635,359-100)    
    
    -- SetAlfa(10,0,1,1)
    StartTimer(timerID+1,3,"frame4")
    playeffect("tik")
  end
  if sender == 26 then
    --CloseSatelite()
  end
  if sender == 30 then
    StopTimer(timerID)
  end
end

function update()
  n = n + 1
  if n <= 25 then
    local dy = (flags.state[1] - old[1])*2
    set_pos_in_img(1,0,0+(5-old[1])*a-dy*n,91,473)
    
    local dy = (flags.state[2] - old[2])*2
    set_pos_in_img(2,91,0+(5-old[2])*a-dy*n,56,333)
    
    local dy = (flags.state[3] - old[3])*2
    set_pos_in_img(4,147,160+(5-old[3])*a-dy*n,56,333)
    
    local dy = (flags.state[2] - old[2])*2
    SetObjectPosition(3,500,358-(5-old[2])*a+dy*n)
    
    local dy = (flags.state[3] - old[3])*2
    SetObjectPosition(5,635,359-(5-old[3])*a+dy*n)
    
    StartTimer(timerID,0.04,"update")
  else
    Block_Show_Cur(false)
    if (flags.state[1] == flags.state[2]) and (flags.state[1] == flags.state[3]) then
      finish_mini_game(true)
    end
  end
end