Index: /code/branches/usability/data/gui/scripts/AudioMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/AudioMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/AudioMenu.lua	(revision 7928)
@@ -43,5 +43,4 @@
     end
 
-    P:initButtons(1, 1)
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/AudioBackButton"),
Index: /code/branches/usability/data/gui/scripts/ControlsMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/ControlsMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/ControlsMenu.lua	(revision 7928)
@@ -8,6 +8,4 @@
 
     --buttons are arranged in a 3x1 matrix:
-    P:initButtons(3, 1)
-
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/MouseControlsButton"),
Index: /code/branches/usability/data/gui/scripts/CreditsMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/CreditsMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/CreditsMenu.lua	(revision 7928)
@@ -6,5 +6,4 @@
 
 function P.onLoad()
-    P:initButtons(1, 1)
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/CreditsBackButton"),
Index: /code/branches/usability/data/gui/scripts/DecisionPopup.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/DecisionPopup.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/DecisionPopup.lua	(revision 7928)
@@ -6,6 +6,4 @@
 
     --button are arranged in a 1x2 matrix
-    P:initButtons(1, 2)
-
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/DecisionPopup_button_yes"),
Index: /code/branches/usability/data/gui/scripts/GUISheet.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/GUISheet.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/GUISheet.lua	(revision 7928)
@@ -34,7 +34,5 @@
 
     -- set the selected button's state
-    if self.buttons and self:hasSelection() then
-        self:setButtonStateSelected()
-    end
+    self:setSelectedButtonsStateToSelected()
 
     self:onShow()
@@ -107,6 +105,5 @@
 
 -- Initializes the buttons table, used to control the menu with the keyboard
--- ratio: the button's with divided by the button's height (used to calculate distance between buttons - adjust this until you get the desired behavior)
-function P:initButtons(rows, columns, ratio)
+function P:initButtons(rows, columns)
     self.rows = rows
     self.columns = columns
@@ -114,16 +111,35 @@
     self.selectedRow = 0
     self.selectedColumn = 0
-
-    if ratio then
-        self.ratio = ratio
-    else
-        self.ratio = 1
-    end
+    self.ratio = 1
+end
+
+-- ratio: the button's with divided by the button's height (used to calculate distance between buttons - adjust this until you get the desired behavior)
+function P:setRatio(ratio)
+    self.ratio = ratio
 end
 
 -- Defines the button for a given position in the table. The upper-left button is at position (1, 1)
 function P:setButton(row, column, button)
-    assert(self.rows ~= nil and self.columns ~= nil and self.buttons ~= nil, "You have to call initButtons() before using setButton()")
-    assert(row > 0 and column > 0 and row <= self.rows and column <= self.columns, "(" .. row .. "/" .. column .. ") is not in the valid bounds of the table (1/1)-(" .. self.rows .. "/" .. self.columns .. ")")
+    if not self.buttons then
+        -- init the table
+        self:initButtons(row, column)
+    elseif row > self.rows or column > self.columns then
+        -- rearrange the table
+        local maxRows = math.max(self.rows, row)
+        local maxColumns = math.max(self.columns, column)
+
+        for r = self.rows, 1, -1 do
+            for c = self.columns, 1, -1 do
+                local b = self:getButton(r, c)
+                if b then
+                    self.buttons[(r - 1) * self.columns + (c - 1)] = nil
+                    self.buttons[(r - 1) * maxColumns + (c - 1)] = b
+                end
+            end
+        end
+
+        self.rows = maxRows
+        self.columns = maxColumns
+    end
 
     self.buttons[(row - 1) * self.columns + (column - 1)] = button
@@ -132,15 +148,23 @@
 -- Returns the button at a given position in the table. The upper-left button is at position (1, 1)
 function P:getButton(row, column)
-    return self.buttons[(row - 1) * self.columns + (column - 1)]
+    if self.buttons then
+        return self.buttons[(row - 1) * self.columns + (column - 1)]
+    else
+        return nil
+    end
 end
 
 -- Returns the selected button
 function P:getSelectedButton()
-    return self:getButton(self.selectedRow, self.selectedColumn)
+    if self:hasSelection() then
+        return self:getButton(self.selectedRow, self.selectedColumn)
+    else
+        return nil
+    end
 end
 
 -- Presses the selected button if any
 function P:pressSelectedButton()
-    if self:hasSelection() then
+    if self:getSelectedButton() then
         self.pressedEnter = true
         self:getSelectedButton().callback()
@@ -151,14 +175,49 @@
 -- Sets the selection to a given row and column. The upper-left button is at position (1, 1)
 function P:setSelection(row, column)
+    if not self.buttons then
+        return
+    end
+
     assert(row > 0 and column > 0 and row <= self.rows and column <= self.columns, "(" .. row .. "/" .. column .. ") is not in the valid bounds of the table (1/1)-(" .. self.rows .. "/" .. self.columns .. ")")
 
-    if self:hasSelection() then
-        self:setButtonStateNormal()
-    end
+    self:setSelectedButtonsStateToNormal()
 
     self.selectedRow = row
     self.selectedColumn = column
 
-    self:setButtonStateSelected()
+    self:setSelectedButtonsStateToSelected()
+end
+
+-- Sets the selection to the button closest to the given row and column. The upper-left button is at position (1, 1)
+function P:setSelectionNear(row, column)
+    if not self.buttons then
+        return
+    end
+
+    assert(row > 0 and column > 0 and row <= self.rows and column <= self.columns, "(" .. row .. "/" .. column .. ") is not in the valid bounds of the table (1/1)-(" .. self.rows .. "/" .. self.columns .. ")")
+
+    if self:getButton(row, column) then
+        self:setSelection(row, column)
+    else
+        local min = 1000000
+        local minRow, minColumn
+
+        for r = 1, self.rows do
+            for c = 1, self.columns do
+                if self:getButton(r, c) then
+                    local distance = math.sqrt((row - r)^2 + ((column - c) * self.ratio)^2)
+                    if distance < min then
+                        min = distance; minRow = r; minColumn = c
+                    end
+                end
+            end
+        end
+
+        if minRow and minColumn then
+            self:setSelection(minRow, minColumn)
+        else
+            self:resetSelection()
+        end
+    end
 end
 
@@ -175,7 +234,11 @@
 -- Generic move function, the values are determined at runtime depending on the arguments
 function P:moveSelection(relMove, selectedThis, selectedOther, limitThis, limitOther, isRow)
+    if not self.buttons then
+        return
+    end
+
     -- if there's no selection yet, prepare it such that the selection enters the table from the desired side
     if self.selectedRow > 0 or self.selectedColumn > 0 then
-        self:setButtonStateNormal()
+        self:setSelectedButtonsStateToNormal()
     else
         if relMove > 0 then
@@ -199,5 +262,5 @@
     -- if the button is deactivated, search the button closest to the desired location
     if self:getSelectedButton() == nil then
-        local min = self.rows + self.columns * self.ratio
+        local min = 1000000
         local minV1, minV2
         local limit, step
@@ -247,14 +310,10 @@
     end
 
-    if self:hasSelection() == true then
-        self:setButtonStateSelected()
-    end
+    self:setSelectedButtonsStateToSelected()
 end
 
 -- Resets the selection
 function P:resetSelection()
-    if self:hasSelection() then
-        self:setButtonStateNormal()
-    end
+    self:setSelectedButtonsStateToNormal()
 
     self.selectedRow = 0
@@ -286,20 +345,20 @@
 
 -- Sets the selected button's state to normal
-function P:setButtonStateNormal()
-    self:setButtonState("Normal")
+function P:setSelectedButtonsStateToNormal()
+    self:setSelectedButtonsState("Normal")
 end
 
 -- Sets the selected button's state to selected
-function P:setButtonStateSelected()
-    self:setButtonState("Selected")
+function P:setSelectedButtonsStateToSelected()
+    self:setSelectedButtonsState("Selected")
 end
 
 -- Sets the selected button's state to pushed
-function P:setButtonStatePushed()
-    self:setButtonState("Pushed")
+function P:setSelectedButtonsStateToPushed()
+    self:setSelectedButtonsState("Pushed")
 end
 
 -- Sets the selected button's state
-function P:setButtonState(state)
+function P:setSelectedButtonsState(state)
     if self:getSelectedButton() then
         local element = self:getSelectedButton().button
Index: /code/branches/usability/data/gui/scripts/GraphicsMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/GraphicsMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/GraphicsMenu.lua	(revision 7928)
@@ -86,5 +86,4 @@
     block = false
 
-    P:initButtons(1, 1)
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/GraphicsBackButton"),
Index: /code/branches/usability/data/gui/scripts/HostMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/HostMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/HostMenu.lua	(revision 7928)
@@ -15,6 +15,4 @@
     button:setSelected(false)
     P.createLevelList()
-
-    P:initButtons(1, 2)
 
     P:setButton(1, 1, {
Index: /code/branches/usability/data/gui/scripts/InGameMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/InGameMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/InGameMenu.lua	(revision 7928)
@@ -8,6 +8,4 @@
 
     --button are arranged in a 4x1 matrix, the left lower item is nil
-    P:initButtons(4, 1)
-
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/InGameMenu_ReturnButton"),
Index: /code/branches/usability/data/gui/scripts/KeyBindMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/KeyBindMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/KeyBindMenu.lua	(revision 7928)
@@ -101,5 +101,4 @@
     orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
 
-    P:initButtons(1, 1)
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/KeyBindBackButton"),
Index: /code/branches/usability/data/gui/scripts/MainMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/MainMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/MainMenu.lua	(revision 7928)
@@ -6,6 +6,4 @@
 function P.onLoad()
     --buttons are arranged in a 6x1 Matrix (list)
-    P:initButtons(6, 1)
-
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/QuickGameTestButton"),
Index: /code/branches/usability/data/gui/scripts/MiscConfigMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/MiscConfigMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/MiscConfigMenu.lua	(revision 7928)
@@ -85,5 +85,4 @@
     P.createLines()
 
-    P:initButtons(1, 1)
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"),
Index: /code/branches/usability/data/gui/scripts/MouseControlsMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/MouseControlsMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/MouseControlsMenu.lua	(revision 7928)
@@ -33,5 +33,4 @@
     end
 
-    P:initButtons(1, 1)
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/MouseControlsBackButton"),
Index: /code/branches/usability/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/MultiplayerMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/MultiplayerMenu.lua	(revision 7928)
@@ -10,7 +10,5 @@
     P.multiplayerMode = "startClient"
 
-    --button are arranged in a 2x2 matrix, the lower items are both the back button
-    P:initButtons(2, 3)
-
+    --button are arranged in a 3x2 matrix, Join and Host buttons are in the upper left and middle, the back button in the lower right of the table
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"),
Index: /code/branches/usability/data/gui/scripts/SettingsMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/SettingsMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/SettingsMenu.lua	(revision 7928)
@@ -6,7 +6,5 @@
 function P.onLoad()
     --"Gameplay" and "Multiplayer Options" are not integrated in the list
-    --buttons are arranged in a 4x2 matrix. The lower-right element is not in the matrix!
-    P:initButtons(4, 2)
-
+    --buttons are arranged in a 4x2 matrix.
     P:setButton(1, 2, {
             ["button"] = winMgr:getWindow("orxonox/SettingsMenu/GraphicsButton"),
Index: /code/branches/usability/data/gui/scripts/SheetManager.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/SheetManager.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/SheetManager.lua	(revision 7928)
@@ -133,6 +133,6 @@
 
     -- select first button if the menu was opened with the keyboard
-    if previous and previous.pressedEnter and menuSheet.buttons and menuSheet:hasSelection() == false then
-        menuSheet:moveSelectionRow(1)
+    if previous and previous.pressedEnter and menuSheet:hasSelection() == false then
+        menuSheet:setSelectionNear(1, 1)
     end
 
Index: /code/branches/usability/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- /code/branches/usability/data/gui/scripts/SingleplayerMenu.lua	(revision 7927)
+++ /code/branches/usability/data/gui/scripts/SingleplayerMenu.lua	(revision 7928)
@@ -14,6 +14,4 @@
 
     --buttons are arranged in a 1x2 matrix
-    P:initButtons(1, 2)
-
     P:setButton(1, 1, {
             ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
