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

local nowAttached = nil
local a = 116
local l,t = 357,205
local w,h = 321,218

local index = {14,11,9,10,12,13,6,7,5,8,4,2,3,1,nil}

local last = nil

local field=
{
  {x=246,y=96};
  {x=354,y=96};
  {x=462,y=96};
  {x=570,y=96};
  {x=678,y=96};
  {x=678,y=205};
  {x=246,y=205};
  {x=678,y=313};
  {x=246,y=313};
  {x=246,y=421};
  {x=354,y=421};
  {x=462,y=421};
  {x=570,y=421};
  {x=678,y=421};
  {x=460,y=255};
}

if flags.podnosComplete then
  SetObjectPosition(16,352,151)
  SetObjectPosition(17,352,364)
  ActivateObject(obj.gems_7_13.id,true)
  setCursor(obj.gems_7_13.id,4)
else
  miniCreate()
end
  
function gameinput (sender,x,y)
  MiniInterfaceHandler(sender, x, y);
  sendersProcessing(sender,x,y)
  if wrongItemWarning(sender, x, y) then
    return
  end
  
  Write("sender="..sender.."; x="..x.."; y="..y.."\n")

  if sender == 1 then
    if x == obj.gems_7_13.id then
      StoreObj(obj.gems_7_13.id)
      neighbors.Rune.lock = true
    end
    if not flags.podnosComplete then
      local x,y = GetCursorPos()
      local j = nil
      for i=1,15 do
        if x >= field[i].x and x <= field[i].x+a and y >= field[i].y and y <= field[i].y+a then
          j = i
          break
        end
      end
      if j then
        if index[j] then
          add_to_mouse(index[j])
          nowAttached = index[j]
          index[j] = nil
          last = j
        end
      end
    end
  end
  
  if sender == 8129 then
    if nowAttached then
      local j = nil
      for i=1,14 do
        if x >= field[i].x and x <= field[i].x+a and y >= field[i].y and y <= field[i].y+a then
          j = i
          break
        end
      end
      removeFromMouse(nowAttached)
      playeffect("block")
      if j and not index[j] then
        SetObjectPosition(nowAttached,field[j].x,field[j].y)
        index[j] = nowAttached
      else
        if (x >= l and x <= l+w and y >= t and y <= t+h) and not index[15] then
          SetObjectPosition(nowAttached,field[15].x,field[15].y)
          index[15] = nowAttached            
        else
          SetObjectPosition(nowAttached,field[last].x,field[last].y)
          index[last] = nowAttached
        end
      end
      nowAttached = nil
      checkMini()
    end
  end
  
  if sender == 10 then
    flags.podnosComplete = true
    for i=1,14 do
      SetObjectPosition(i,field[i].x,field[i].y)
      setcolor(i,0.6,0.6,0.6,1)
    end
    playeffect("pl_mir")
    Block_Show_Cur(true)
    MoveObjectY(16,201,151,1)
    MoveObjectY(17,314,364,1)
    ActivateObject(obj.gems_7_13.id,true)
    setCursor(obj.gems_7_13.id,4)
    for i=1,14 do
      setCursor(i,3)
    end
    StartTimer(timerID,1.1,"unBlock_Show_Cur")
  end
  
  if sender == 26 then
--    CloseSatelite()
  end
end




function checkMini()
  Write("\n{")
  for i = 1,14 do
    Write(tostring(index[i])..",")
    if i ~= index[i] then
      setcolor(i,1,1,1,1)
    else
      setcolor(i,0.6,0.6,0.6,1)
    end
  end
  Write("}\n\n")
  for i = 1,14 do
    if i ~= index[i] then
      return false
    end
  end
  finish_mini_game(true)
  playeffect("mini_complete")
end


