-- local state = {1,2,3,4,5,6,7,8}
-- local xs = {765,689,533,613,450,372,292,215}
-- local xs1 = {777,697,539,620,456,380,299,221}



function Show_Hide()
  for i=1,5 do
    speciale_action(2,i,true,0.5)
  end  
  
end;

if flags.otkrylDvercy  then
  if not flags.vstavilKnigu then
  for i=1,5 do
    setCursor(i,13)
  end
  end;
  set_visible_object(101,false)
  set_visible_object(102,false)
  set_visible_object(21,false)
  set_visible_object(22,false)
  set_visible_object(23,false)
end

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

end

if flags.proshelKnigi then
  for i=1,5 do
    ActivateObject(i,false)
    setCursor(i,3)
  end
  setCursor(obj.yabloko_18_10.id,4)
  speciale_action(4,obj.yabloko_18_10.id)
  set_visible_object(2,false)
else
  ActivateObject(obj.yabloko_18_10.id,false)
  if flags.vstavilKnigu then
    if flags.podKovromVTajnike then 
      for i=1,10 do
        local a = GetRandom(1,4)
        local b = GetRandom(1,4)
        state[a],state[b] = state[b],state[a]
      end
      update()
      for i=1,4 do
        setCursor(i,4)
      end
      miniCreate()
    end;  
  else
    setcolor(1,1,1,1,0.01)
  end
end

local sel = nil

function gameinput (sender,obj_id,attachedID)
  MiniInterfaceHandler(sender, obj_id, attachedID);
  sendersProcessing(sender, obj_id, attachedID);
  if wrongItemWarning(sender, obj_id, attachedID, "kniga_14_1", "card_16_11") then
    return
  end
  if sender==1 then
    if obj_id == 23 then
      if obj.card_16_11 and attachedID == obj.card_16_11.id then
        removeFromMouse()
        UnStoreObj(obj.card_16_11.id)
        flags.otkrylDvercy = true
        playeffect("zashc")
        setCursor(23,3)
        set_visible_object(23,false)
        Block_Show_Cur(true)
        SetAlfa(21,0,1,1,"frame3")
      else
        CreatePlashechka("658")
      end
    end
    if obj_id >= 1 and obj_id <= 5 then
      if flags.vstavilKnigu then
        
        if flags.podKovromVTajnike then
          if sel then
            local a,b = nil,nil
            for i=1,5 do
              if state[i] == obj_id then
                a = i
              end
              if state[i] == sel then
                b = i
              end
            end
            set_visible_object(sel+10,false)
            sel = nil
            playeffect("book_ins")
            state[a],state[b] = state[b],state[a]
            update()
          else
            sel = obj_id
            set_visible_object(sel+10,true)
          end
        else
          CreatePlashechka("672")
        end
      else
        if obj.kniga_14_1 and attachedID == obj.kniga_14_1.id then
          removeFromMouse()
          UnStoreObj(obj.kniga_14_1.id)
          playeffect("book_ins")
          Block_Show_Cur(true)
          SetAlfa(1,0.01,1,1,"frame7")
          flags.vstavilKnigu = true
        else
          CreatePlashechka("656")
        end
      end
    end
    if obj_id >= 11 and obj_id <= 18 then
      set_visible_object(obj_id,false)
      sel = nil
    end
    if obj_id == obj.yabloko_18_10.id then
      StoreObj(obj.yabloko_18_10.id)
    
      neighbors.OlderShkaf.lock = true
      neighbors.Zapiska.lock = false
    end
  end
  if sender == 10 then
    Block_Show_Cur(true)
    state = {1,2,3,4,5}
    update()
    for i=1,5 do
      ActivateObject(i,false)
      setCursor(i,3)
    end
    ActivateObject(obj.yabloko_18_10.id,true)
    flags.proshelKnigi = true
    speciale_action(4,19)
    speciale_action(4,20)
    SetAlfa(1,1,0,1)
    playeffect("book_out")
    SetAlfa(20,0,1,1,"frame1")
  end
  if sender == 26 then

  --  CloseSatelite()
  end
  if sender == 30 and obj.yabloko_18_10.is_collapsed then
    dofile("./data/18/0/comics.lua")
  end
end

function frame1()
  SetAlfa(20,1,0,1)
  SetAlfa(19,0,1,1,"frame2")
end

function frame2()
  SetAlfa(19,1,0,1,"unBlock_Show_Cur")
  setCursor(obj.yabloko_18_10.id,4)
  -- SetAlfa(obj.yabloko_18_10.id,0,1,1)
end

function frame3()
playeffect("book_open")
  SetAlfa(21,1,0,1)
  SetAlfa(22,0,1,1,"frame4")
end

function frame4()
  SetAlfa(22,1,0,1)
  SetAlfa(101,0,1,1)
  StartTimer(timerID,2,"frame5")
end

function frame5()
  SetAlfa(101,1,0,1)
  SetAlfa(102,1,0,1,"frame6")
end

function frame6()
  for i=1,5 do
    setCursor(i,13)
  end
  Block_Show_Cur(false)
end

function frame7()
StartTimer(23423423,0.6,"frame8")
speciale_action(2,obj.yabloko_18_10.id)
Show_Hide()

end;

function frame8()
  local iMixed=0;
  local a=0
  local b=0

  StartTimer(23423423,0.2,"frame9")
  for i=1,10 do
    a = GetRandom(1,5)
    b = GetRandom(1,5)
    state[a],state[b] = state[b],state[a]
  end
  for i=1,5,1 do
    if state[i] == i then
      iMixed=iMixed+1
    end;
  end;
  if iMixed==5 then
    a = GetRandom(1,5)
    b = GetRandom(1,5)
    state[a],state[b] = state[b],state[a]
  end
  update()
  for i=1,5 do
    setCursor(i,4)
  end
  
  if flags.podKovromVTajnike then
    miniCreate()
  end
end
function frame9()
--out("frame9 \n")
Show_Hide()

StartTimer(23423423,0.6,"frame10")
end;
function frame10()
--out("frame8 \n")
speciale_action(2,obj.yabloko_18_10.id)
Block_Show_Cur(false)
end;