function mini_create()
  init_mini(true)
  create_mini(8128);
end

if flags.svitokActive then
  set_visible_object(22,false)
  speciale_action(2,20)
  speciale_action(2,23)
  setCursor(25,4)
  for i=1,7 do
    set_visible_object(i,true)
  end
  miniCreate()
end

local x0,y0,x1,y1 = 0,0,0,0,0,0
local att = nil
local over = nil
local state = {11,12,13,nil,14,15,16}
local t1 = {11,12,13}
local t2 = {14,15,16}
local pressed = nil

function gameinput (sender,obj_id,attachedID)
  MiniInterfaceHandler(sender, obj_id);
  sendersProcessing(sender, obj_id, attachedID);
  --out("("..tostring(sender)..","..tostring(obj_id)..","..tostring(attachedID)..")\n")
  if sender==1 then
    if obj_id == 24 then
      pressed = obj_id
      SetAlfaValue(pressed,1)
    end
    if obj_id == 22 then
      if obj.svitok_6_12 and attachedID == obj.svitok_6_12.id then
        removeFromMouse()
        Block_Show_Cur(true)
        UnStoreObj(obj.svitok_6_12.id)
        playeffect("grav")
        speciale_action(2,21,true,1)
        speciale_action(2,22)
        setCursor(22,3)
        StartTimer(timerID,1.5,"frame1")
        flags.svitokActive = true
        setCursor(25,4)
        
      else
        CreatePlashechka("612")
      end
    end
    if obj_id >= 1 and obj_id <= 7 then
      out(tostring(obj_id).."\n")
      if state[obj_id] then
        att = obj_id
        
        add_to_mouse(state[att])
        x0,y0 = GetObjectPosition(att)
        over = nil
      end
    end
  end
  if sender == 8129 then
    if pressed then
      SetAlfaValue(pressed,0.01)
      pressed = nil
      
      x0,y0,x1,y1 = 0,0,0,0,0,0
      att = nil
      over = nil
      state = {11,12,13,nil,14,15,16}
      t1 = {11,12,13}
      t2 = {14,15,16}
      local pressed = nil
      
      SetObjectPosition(11,178,151)
      SetObjectPosition(12,278,151)
      SetObjectPosition(13,378,151)
      SetObjectPosition(14,577,151)
      SetObjectPosition(15,677,151)
      SetObjectPosition(16,777,151)
      
      for i=1,7 do
        speciale_action(4,i)
      end
    end
    if att then
      RemoveFromMouse(state[att])
      if over and not state[over] and math.abs(over - att) <=2 and ((state[att] >=11 and state[att] <= 13 and over > att) or (state[att] >=14 and state[att] <= 16 and over < att)) then
        x0,y0 = GetObjectPosition(over)
        SetObjectPosition(state[att],x0,y0)
        playeffect("pero")
        speciale_action(4,over)
        state[att],state[over] = state[over],state[att]
        checkMini()
      else
        SetObjectPosition(state[att],x0,y0)
        speciale_action(4,att)
      end
      att = nil
      over = nil
    end
  end
  if sender == 10 then
    --out("COMLETE!!!\n")
    setCursor(25,3)
    neighbors.Perja.lock = true
    for i=1,7 do
      ActivateObject(i,false)
    end
    playeffect("mini_complete")
    StartTimer(timerID,2,"CloseSatelite")
    for i=51,54 do
      speciale_action(2,i)
      speciale_action(2,i+4)
    end
      SetObjectPosition(14,178,151)
      SetObjectPosition(15,278,151)
      SetObjectPosition(16,378,151)
      SetObjectPosition(11,577,151)
      SetObjectPosition(12,677,151)
      SetObjectPosition(13,777,151)    
  end
  if sender == 35 then
    if obj_id >= 1 and obj_id <= 7 then
      over = obj_id
    end
  end
  if sender == 39 then
    if obj_id >= 1 and obj_id <= 7 then
      over = nil
    end
  end
end

function frame1()

  speciale_action(2,20,true,2)
  speciale_action(2,21,true,2)
  speciale_action(2,23,true,2)
  for i=1,7 do
    set_visible_object(i,true)
  end
  StartTimer(timerID,2.1,"frame2")
end

function frame2()
miniCreate()
StartTimer(timerID,0.6,"unBlock_Show_Cur")
end;
function checkMini()
  local n = 0
  for i=1,3 do
    local j = i + 4
    for k=1,3 do
      if state[i] == t2[k] then
        n = n + 1
      end
      if state[j] == t1[k] then
        n = n + 1
      end
    end
  end
  --out("n="..tostring(n).."\n")
  if n == 6 then
    finish_mini_game(true)
  end
end