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

if not flags.kladka then
  miniCreate()
else
  for i=1,9 do
    SetAlfaValue(i,1)
    StopOnMouseOver(i)
    if not flags.fotoBaleriny then
      setCursor(i,13)
    end
  --  speciale_action(4,i)
  end
  for i=11,19 do
    set_visible_object(i,false)
  end
  for i=41,49 do
    speciale_action(2,i)
  end  
  if flags.fotoBaleriny then
    set_visible_object(51,true)
    speciale_action(2,52)
  else
    if flags.tajnikPodKaminom then
      speciale_action(2,49)
      speciale_action(2,54)
    end
  end
end

local nowAttached = nil
local nowActive = nil
local state = {false,false,false,false,false,false,false,false,false}
local layer = {1,1,2,2,3,3,4,4,5}

function gameinput (sender,obj_id,attachedID)
  Write("sender="..sender.." ; obj_id="..obj_id.."\n");
  MiniInterfaceHandler(sender, obj_id,attachedID);
  sendersProcessing(sender,obj_id,attachedID)
  if wrongItemWarning(sender, obj_id, attachedID, "gerb_7_14") then
    return
  end
  if sender==16 then
    if obj_id>=61 and obj_id<=64 then
      speciale_action(2,obj_id,true,1)
      speciale_action(2,obj_id+1,true,1.2)    
    return;end;
    if obj_id==65 then
      StartTimer(timerID,0.1,"unBlock_Show_Cur")
      setCursor(60,2)
    return;end;
  return;end;
  if sender==1 then
  
    if flags.kladka then
      if obj_id >= 1 and obj_id <= 9 then
        if obj.gerb_7_14 and attachedID == obj.gerb_7_14.id then
          removeFromMouse()
          UnStoreObj(obj.gerb_7_14.id)
          flags.tajnikPodKaminom = true
          Block_Show_Cur(true)
          for i=1,9 do
            setCursor(i,3)
          end
          speciale_action(2,75,true,1)
          StartTimer(timerID,1.5,"frame1")
        else
          CreatePlashechka("640")
        end
      end
      if obj_id == 60 then
        Block_Show_Cur(true)
        flags.fotoBaleriny = true
        
        neighbors.BedroomKaminGame.lock = true
        
        Journal:addText(8,"9014",145,120,330)
        Journal:addPicture(8,"page8",111,198,339,0,430,419);
        
        frame2()
      end
      if obj_id == 51 then
        if flags.videlbalerinu then
          CreatePlashechka("571")
        else
          CreatePlashechka("572")
        end
      end
    else
      if not nowAttached then
        if obj_id>=11 and obj_id<=19 then
          nowAttached = obj_id+10
          local x,y = GetCursorPos()
          local a,b = GetObjectSize(nowAttached)
          SetObjectPosition(nowAttached,x-a/2,y-b/2)
          playeffect("block")
          set_visible_object(nowAttached,true)
          add_to_mouse(nowAttached)
          set_visible_object(obj_id,false)
        end
      end
    end
  end
  if sender == 8129 then
    if nowAttached then
      removeFromMouse(nowAttached)
         verno=false

    --  messageboxi(nowActive)
      for i=41,49,1 do
      if (layer[i-40]==curr_layer) and
        (obj_id>=xp1[i] and obj_id<=xp2[i] and attachedID>=yp1[i] and attachedID<=yp2[i] and i==nowAttached+20)  
      then
         --out("X = "..obj_id.."\n")
         --out(" Y= "..attachedID.."\n")
         qqq=i
         --out(" nowAttached= "..qqq.."\n")
         --out(" nowAttached X1 = "..xp1[i].."\n")
         --out(" nowAttached X2 = "..xp2[i].."\n")
         --out(" nowAttached Y1 = "..yp1[i].."\n")
         --out(" nowAttached Y2 = "..yp2[i].."\n")      
         sdfs=i-40
        --out("i-40 = "..sdfs.."\n")
        SetAlfaValue(i-40,1)
        counter=counter+1
        state[i-40] = true
          verno=true
        checkMini()
      end;
      end;
      set_visible_object(nowAttached,false)    
      if  verno then            
      else
        set_visible_object(nowAttached-10,true)
      end;  
      nowAttached = nil

    end
  end
  if sender == 10 then
    for i=1,9 do
      SetAlfaValue(i,1)
      StopOnMouseOver(i)
      setCursor(i,13)
    end
    for i=11,19 do
      set_visible_object(i,false)
    end
        for i=41,49 do
      set_visible_object(i,false)
    end
    playeffect("mini_complete")
    CreatePlashechka("640")
    flags.kladka = true
  end

  -- if sender == 35 then
    -- nowActive = obj_id
  -- end
  -- if sender == 39 then
    -- if obj_id == nowActive then
      -- nowActive = nil
    -- end
  -- end
end

function checkMini()
  if counter==2 or counter==3 then  curr_layer=4  end;
  if counter==4 or counter==5 then  curr_layer=3  end;
  if counter==6 or counter==7 then  curr_layer=2  end;
  if counter==8 or counter==9 then  curr_layer=1  end;
  for i=1,9 do
    if not state[i] then
      return
    end
  end
  finish_mini_game(true)
end

function frame1()
  -- StartTimer(timerID,1.5,"frame2")
  -- Block_Show_Cur(false)
  playeffect("move_p")
  speciale_action(2,54,true,1)
  speciale_action(2,60,true,1)
  speciale_action(2,61,true,1.2)
--  StartTimer(timerID,1.1,"unBlock_Show_Cur")
  --speciale_action(2,49,true,1)
  --StartTimer(timerID,1.1,"unBlock_Show_Cur")
end

function frame2()
  set_visible_object(51,true)
  speciale_action(2,49,true,0.1)
  speciale_action(2,52,true,1)
  speciale_action(2,54,true,1)
  StartTimer(timerID,1.1,"unBlock_Show_Cur")
end