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

local miniGameActive = false

if flags.postavilKist then
  speciale_action(2,32)
end

if flags.postavilPalitru then
  for i=20,26 do
    speciale_action(2,i)
  end
  speciale_action(2,33)
end

if flags.videlKartinu and flags.postavilKist and flags.postavilPalitru then
  miniGameActive = true
  speciale_action(2,34)
  miniCreate()
end

local colors =
{
  [20] = {"brown"  ,0.57,0.30,0.10};
  [21] = {"pink"  ,0.72,0.23,0.51};
  [22] = {"blue"  ,0.44,0.76,0.90};
  [23] = {"yellow",1.00,0.76,0.14};
  [24] = {"red"  ,0.74,0.05,0.10};
  [25] = {"white"  ,1.00,1.00,1.00};
  [26] = {"green"  ,0.17,0.60,0.28};
}

local state = {}
local STATE = {25,22,25,25,21,21,20,26,24,21,26,26,22,23,23,23}

local currentColor = nil
local brush = false

-- for i=1,15 do


function gameinput (sender,obj_id,attachedID)
  -- if brush then
    -- if sender == 14 then
      -- return
    -- end
  -- end
  MiniInterfaceHandler(sender,obj_id,attachedIDd,brush);
--  if not brush then
    sendersProcessing(sender, obj_id, attachedID);
--  end
  if wrongItemWarning(sender, obj_id, attachedID,"palitra_12_1","kist_4_10",30) then
    return
  end
  if sender==1 then
    if miniGameActive and not flags.minipaintOK then
      if obj_id == 32 then
        brush = true
        SetObjectPosition(10000002,2000,2000)
        SetCustomCursor(31)
        set_visible_object(32,false)
      end
      if brush and obj_id >= 20 and obj_id <= 26 then
        currentColor = obj_id
        setcolor(30,colors[currentColor][2],colors[currentColor][3],colors[currentColor][4],1)
        AddObjectToCursor(30,30,0,4)
        playeffect("brush_in")
      end
      if obj_id >= 1 and obj_id <= 16 then
        if currentColor then
          state[obj_id] = currentColor
          if currentColor~=25 then
          setcolor(obj_id,colors[currentColor][2],colors[currentColor][3],colors[currentColor][4],0.6)
          else
          setcolor(obj_id,colors[currentColor][2],colors[currentColor][3],colors[currentColor][4],1)
          end;
          checkMini()
          playeffect("brush_out")
        end
      end
    else
      if obj_id == 34 then
        if obj.palitra_12_1 and attachedID == obj.palitra_12_1.id then
          removeFromMouse()
          UnStoreObj(obj.palitra_12_1.id)
          speciale_action(2,33,true,0.5)
          flags.postavilPalitru = true
          for i=20,26 do
            speciale_action(2,i,true,0.5)
          end
        elseif obj.kist_4_10 and attachedID == obj.kist_4_10.id then
          removeFromMouse()
          UnStoreObj(obj.kist_4_10.id)
          speciale_action(2,32,true,0.5)
          flags.postavilKist = true
        else
          if not flags.postavilKist or not flags.postavilPalitru then
            CreatePlashechka("630")
          else
            if flags.videlKartinu then
              CreatePlashechka("625")
            end
          end
        end
        if flags.videlKartinu and flags.postavilKist and flags.postavilPalitru then
          speciale_action(2,34,true,0.1)
          miniGameActive = true
          miniCreate()
        end
      end
    end
    if obj_id == obj.kartina_9_16.id then
      neighbors.BedroomHidden.lock = false
      neighbors.Molbert.lock = true
      for i=1,16 do
        set_visible_object(i,false)
      end
      StoreObj(obj.kartina_9_16.id)
    end
  end
  if sender == 8 and miniGameActive then
    brush = false
    freeCustomCursor()
    FreeObjectFromCursor()
    SetObjectPosition(31,2000,0)
    SetObjectPosition(30,2000,0)
    set_visible_object(32,true)
    currentColor = nil
  end
  if sender == 10 then
    Block_Show_Cur(true)
    playeffect("mini_complete")

    flags.minipaintOK=true
    speciale_action(2,obj.kartina_9_16.id,true,2)
    StartTimer(timerID,2.1,"unBlock_Show_Cur")
    gameinput(8)
  end
  if sender == 26 then
  --  CloseSatelite()
  end
  if sender == 30 then
    if neighbors.Molbert.lock then
      dofile("./data/9/0/comics.lua")
    end
  end
end

function checkMini()
  --out("state={")
  for i=1,16 do
    out(tostring(state[i])..",")
  end
  --out("}\n")
  for i=1,16 do
    if not state[i] or state[i] ~= STATE[i] then
      return
    end
  end
  finish_mini_game(true)
end