menyunazhim =   -124
menyuvkl =     -125
exit1 =       -126
vyhodnazhim =   -127
vyhodvkl =     -128

function Exit()
  
  exitWindow = true
  
  addstaticobjecttogame(exit1      ,"menu_texture1",284,104,"",496,471,489,383)
  addstaticobjecttogame(vyhodvkl    ,"menu_texture1",560,419,"",814,101,178,43 )
  addstaticobjecttogame(vyhodnazhim  ,"menu_texture1",560,421,"",814,58 ,178,42 )
  addstaticobjecttogame(menyuvkl    ,"menu_texture1",319,418,"",814,144,182,43 )
  addstaticobjecttogame(menyunazhim  ,"menu_texture1",315,422,"",766,423,178,38 )
  
  OnMouseOver(vyhodvkl)
  OnMouseOver(menyuvkl)
  
  set_visible_object(vyhodnazhim,false)
  set_visible_object(menyunazhim,false)
    
  SetAlfaValue(vyhodvkl,0.01)
  SetAlfaValue(menyuvkl,0.01)
  
  speciale_action(4,exit1)
  speciale_action(4,vyhodvkl)
  speciale_action(4,vyhodnazhim)
  speciale_action(4,menyuvkl)
  speciale_action(4,menyunazhim)
  
  setInputFunction("exitGameInput")
  
  function exitGameInput(sender, obj_id)
    Write(sender.."; "..obj_id.."\n")
    if threeStateButton(sender,obj_id,attachedID,vyhodvkl,vyhodnazhim) then
      if STATE == 1 then
        SaveGame()
      end
      do
        local filenameUsers=GetSavePath() .. "users";

        table.save(users,filenameUsers);
--        table.save(users,path);
      end
      savesetings()
      -- ÊÎÑÒÛËÜ, ×ÒÎÁÛ ÍÀÑÒÐÎÉÊÈ ÈÃÐÛ ÑÎÕÐÀÍßËÈÑÜ ÏÎÑËÅ ÊÎÑÒÛËß Â /script/init.lua
      local path = GetSavePath().."data.dat"
      local tmp=0
      do
        local file = io.open(path,"r")

        if file then
          tmp = file:read("*a")
          file:close()
        end
      end
      do
        local file = io.open ("data.dat", "w")

        if file then
          file:write(tmp)
          file:close()
        end
      end
      -- END
      exitgame()
    end
    if threeStateButton(sender,obj_id,attachedID,menyuvkl,menyunazhim) then
      del_object_from_game(exit1)
      del_object_from_game(menyuvkl)
      del_object_from_game(vyhodvkl)
      del_object_from_game(vyhodnazhim)
      del_object_from_game(menyunazhim)
      exitWindow = false
      setInputFunction()
      if STATE == 1 then
        freeCustomCursor()
        CloseSatelite()
        SaveGame()
        setstatemenu()
        --StopAllEffects()
        -- delete_tree_leaf("Root",gamedata.current_level);
      end
    end
  end
end

