@@ -1,5 +1,6 @@
-KEY_BINDINGS_DISPLAYED = 17;
+KEY_BINDINGS_DISPLAYED = 21;
 KEY_BINDING_HEIGHT = 25;
+KEY_BINDING_ROW_NAME = "KeyBindingFrameKeyBinding";
 
 DEFAULT_BINDINGS = 0;
 ACCOUNT_BINDINGS = 1;
@@ -13,7 +14,7 @@ StaticPopupDialogs["CONFIRM_DELETING_CHA
 	button2 = CANCEL,
 	OnAccept = function(self)
 		SaveBindings(KeyBindingFrame.which);
-		KeyBindingFrameOutputText:SetText("");
+		KeyBindingFrame.outputText:SetText("");
 		KeyBindingFrame_SetSelected(nil);
 		HideUIPanel(KeyBindingFrame);
 		CONFIRMED_DELETING_CHARACTER_SPECIFIC_BINDINGS = 1;
@@ -32,10 +33,10 @@ StaticPopupDialogs["CONFIRM_LOSE_BINDING
 		KeyBindingFrame.bindingsChanged = nil;
 	end,
 	OnCancel = function(self)
-		if ( KeyBindingFrameCharacterButton:GetChecked() ) then
-			KeyBindingFrameCharacterButton:SetChecked();
+		if ( KeyBindingFrame.characterSpecificButton:GetChecked() ) then
+			KeyBindingFrame.characterSpecificButton:SetChecked();
 		else
-			KeyBindingFrameCharacterButton:SetChecked(1);
+			KeyBindingFrame.characterSpecificButton:SetChecked(true);
 		end
 	end,
 	timeout = 0,
@@ -43,47 +44,178 @@ StaticPopupDialogs["CONFIRM_LOSE_BINDING
 	showAlert = 1,
 };
 
+StaticPopupDialogs["CONFIRM_RESET_TO_DEFAULT_KEYBINDINGS"] = {
+	text = CONFIRM_RESET_KEYBINDINGS,
+	button1 = OKAY,
+	button2 = CANCEL,
+	OnAccept = function(self)
+		KeyBindingFrame_ResetBindingsToDefault();
+	end,
+	timeout = 0,
+	whileDead = 1,
+	showAlert = 1
+};
+
 function KeyBindingFrame_OnLoad(self)
 	self:RegisterForClicks("AnyUp");
+	KeyBindingFrame.scrollOffset = 0;
 	KeyBindingFrame_SetSelected(nil);
+	KeyBindingFrame_LoadCategories(self);
+	KeyBindingFrame_LoadKeyBindingButtons(self);
 end
 
-function KeyBindingFrame_OnShow()
-	KeyBindingFrame_Update();
+local defaultCategories = { BINDING_HEADER_MOVEMENT,
+							BINDING_HEADER_CHAT,
+							BINDING_HEADER_ACTIONBAR,
+							BINDING_HEADER_MULTIACTIONBAR,
+							BINDING_HEADER_TARGETING,
+							BINDING_HEADER_INTERFACE,
+							BINDING_HEADER_MISC,
+							BINDING_HEADER_CAMERA,
+							BINDING_HEADER_RAID_TARGET,
+							BINDING_HEADER_VEHICLE,
+							BINDING_HEADER_DEBUG,
+							BINDING_HEADER_ITUNES_REMOTE,
+							BINDING_HEADER_MOVIE_RECORDING_SECTION };
+
+function KeyBindingFrame_LoadCategories(self)
+	local keyBindingCategories = {};
+	local otherCategory = nil;
+	OptionsList_ClearSelection(KeyBindingFrame.categoryList, KeyBindingFrame.categoryList.buttons);
+	
+	for i = 1, GetNumBindings() do
+		local commandName, category, binding1, binding2 = GetBinding(i, self.mode);
+		
+		if ( not category ) then
+			--If there is no category name for the category of this keyBinding, put this
+			--keyBinding into the default "Other" category.
+			category = BINDING_HEADER_OTHER;
+			
+			otherCategory = otherCategory or {};
+			
+			tinsert(otherCategory, i);
+		else
+			--Check for global string values for category names.
+			category = _G[category] or category;
+			
+			keyBindingCategories[category] = keyBindingCategories[category] or {};
+			
+			tinsert(keyBindingCategories[category], i);
+		end
+	end
+	
+	local categoryButtons = self.categoryList.buttons;
+	local nextCategory = 1;
+	
+	for i = 1, #defaultCategories do
+		local categoryName = defaultCategories[i];
+		if ( keyBindingCategories[categoryName] ~= nil ) then
+			local element = { ["name"] = categoryName, ["category"] = keyBindingCategories[categoryName] };
+			OptionsList_DisplayButton(categoryButtons[nextCategory], element);
+			keyBindingCategories[categoryName] = nil;
+			nextCategory = nextCategory + 1;
+		end
+	end
+	
+	for key, value in pairs(keyBindingCategories) do
+		if ( nextCategory < #categoryButtons ) then
+			local element = { ["name"] = key, ["category"] = keyBindingCategories[key] };
+			OptionsList_DisplayButton(categoryButtons[nextCategory], element);
+			nextCategory = nextCategory + 1;
+		end
+	end
+	
+	if ( otherCategory ) then
+		local element = { ["name"] = BINDING_HEADER_OTHER, ["category"] = otherCategory };
+		OptionsList_DisplayButton(categoryButtons[nextCategory], element);
+		nextCategory = nextCategory + 1;
+	end
+	
+	for i = nextCategory, #categoryButtons do
+		OptionsList_HideButton(categoryButtons[i]);
+	end
+	
+	local defaultButton = categoryButtons[1];
+	self.cntCategory = defaultButton.element.category;
+	OptionsList_SelectButton(defaultButton:GetParent(), defaultButton);
+end
 
-	-- Update character button
-	KeyBindingFrameCharacterButton:SetChecked(GetCurrentBindingSet() == 2);
-	-- Update header text
-	if ( KeyBindingFrameCharacterButton:GetChecked() ) then
-		KeyBindingFrameHeaderText:SetFormattedText(CHARACTER_KEY_BINDINGS, UnitName("player"));
-	else
-		KeyBindingFrameHeaderText:SetText(KEY_BINDINGS);
+function KeyBindingFrame_LoadKeyBindingButtons(self)
+	local previousRow = CreateFrame("FRAME", KEY_BINDING_ROW_NAME.."1", KeyBindingFrame, "KeyBindingFrameBindingTemplate");
+	previousRow:SetPoint("TOP", 100, -78);
+	previousRow.key1Button.buttonIndex = 1;
+	previousRow.key1Button.rowIndex = 1;
+	previousRow.key2Button.buttonIndex = 2;
+	previousRow.key2Button.rowIndex = 1;
+	self.keyBindingRows = { previousRow };
+	
+	for i = 2, KEY_BINDINGS_DISPLAYED do
+		local newRow = CreateFrame("FRAME", KEY_BINDING_ROW_NAME..i, KeyBindingFrame, "KeyBindingFrameBindingTemplate");
+		newRow:SetPoint("TOP", previousRow, "BOTTOM", 0, 2);
+		newRow.key1Button.buttonIndex = 1;
+		newRow.key1Button.rowIndex = i;
+		newRow.key2Button.buttonIndex = 2;
+		newRow.key2Button.rowIndex = i;
+		self.keyBindingRows[i] = newRow;
+		
+		previousRow = newRow;
 	end
+end
 
+function KeyBindingFrame_OnShow(self)
+	KeyBindingFrame.mode = 1;
+	KeyBindingFrame_Update();
+	
+	-- Update character button
+	KeyBindingFrame.characterSpecificButton:SetChecked(GetCurrentBindingSet() == 2);
+	
+	KeyBindingFrame_UpdateHeaderText();
+	
 	-- Reset bindingsChanged
 	KeyBindingFrame.bindingsChanged = nil;
+	
+	Disable_BagButtons();
+	UpdateMicroButtons();
 end
 
 function KeyBindingFrame_Update()
-	local numBindings = GetNumBindings();
-	local keyOffset;
-	local keyBindingButton1, keyBindingButton2, commandName, binding1, binding2;
-	local keyBindingName, keyBindingDescription;
-	local keyBindingButton1NormalTexture, keyBindingButton1PushedTexture, keyBindingButton2NormalTexture, keyBindingButton2PushedTexture;
+	local self = KeyBindingFrame;
+	local cntCategory = self.cntCategory;
+	local numBindings = #cntCategory;
+	local keyOffset = FauxScrollFrame_GetOffset(KeyBindingFrameScrollFrame);
+	
+	if ( self.selected ) then
+		local offsetDifference = self.scrollOffset - keyOffset;
+		if ( offsetDifference ~= 0 ) then
+			self.selectedRowIndex = self.selectedRowIndex + offsetDifference;
+			if ( self.selectedRowIndex > 0 and self.selectedRowIndex <= #self.keyBindingRows ) then
+				local button;
+				if ( self.selectedButtonIndex == 1 ) then
+					button = self.keyBindingRows[self.selectedRowIndex].key1Button;
+				else
+					button = self.keyBindingRows[self.selectedRowIndex].key2Button;
+				end
+				KeyBindingFrame_SetSelected(self.selected, button);
+			else
+				KeyBindingFrame_SetSelected(self.selected, nil);
+			end
+		end
+	end
+	
+	self.scrollOffset = keyOffset;
+	
 	for i=1, KEY_BINDINGS_DISPLAYED, 1 do
-		keyOffset = FauxScrollFrame_GetOffset(KeyBindingFrameScrollFrame) + i;
-		if ( keyOffset <= numBindings) then
-			keyBindingButton1 = _G["KeyBindingFrameBinding"..i.."Key1Button"];
-			keyBindingButton1NormalTexture = _G["KeyBindingFrameBinding"..i.."Key1ButtonNormalTexture"];
-			keyBindingButton1PushedTexture = _G["KeyBindingFrameBinding"..i.."Key1ButtonPushedTexture"];
-			keyBindingButton2NormalTexture = _G["KeyBindingFrameBinding"..i.."Key2ButtonNormalTexture"];
-			keyBindingButton2PushedTexture = _G["KeyBindingFrameBinding"..i.."Key2ButtonPushedTexture"];
-			keyBindingButton2 = _G["KeyBindingFrameBinding"..i.."Key2Button"];
-			keyBindingDescription = _G["KeyBindingFrameBinding"..i.."Description"];
+		keyOffset = keyOffset + 1;
+		local keyBindingRow = self.keyBindingRows[i];
+		if ( keyOffset <= numBindings ) then
+			local keyBindingButton1 = keyBindingRow.key1Button;
+			local keyBindingButton2 = keyBindingRow.key2Button;
+			local keyBindingDescription = keyBindingRow.description;
 			-- Set binding text
-			commandName, binding1, binding2 = GetBinding(keyOffset, KeyBindingFrame.mode);
+			local commandName, category, binding1, binding2 = GetBinding(cntCategory[keyOffset], self.mode);
+			
 			-- Handle header
-			local headerText = _G["KeyBindingFrameBinding"..i.."Header"];
+			local headerText = keyBindingRow.header;
 			if ( strsub(commandName, 1, 6) == "HEADER" ) then
 				headerText:SetText(_G["BINDING_"..commandName]);
 				headerText:Show();
@@ -98,35 +230,26 @@ function KeyBindingFrame_Update()
 				keyBindingButton1.commandName = commandName;
 				keyBindingButton2.commandName = commandName;
 				if ( binding1 ) then
-					keyBindingButton1:SetText(GetBindingText(binding1, "KEY_"));
+					keyBindingButton1:SetText(GetBindingText(binding1));
 					keyBindingButton1:SetAlpha(1);
 				else
-					keyBindingButton1:SetText(NORMAL_FONT_COLOR_CODE..NOT_BOUND..FONT_COLOR_CODE_CLOSE);
+					keyBindingButton1:SetText(GRAY_FONT_COLOR_CODE..NOT_BOUND..FONT_COLOR_CODE_CLOSE);
 					keyBindingButton1:SetAlpha(0.8);
 				end
 				if ( binding2 ) then
-					keyBindingButton2:SetText(GetBindingText(binding2, "KEY_"));
+					keyBindingButton2:SetText(GetBindingText(binding2));
 					keyBindingButton2:SetAlpha(1);
 				else
-					keyBindingButton2:SetText(NORMAL_FONT_COLOR_CODE..NOT_BOUND..FONT_COLOR_CODE_CLOSE);
+					keyBindingButton2:SetText(GRAY_FONT_COLOR_CODE..NOT_BOUND..FONT_COLOR_CODE_CLOSE);
 					keyBindingButton2:SetAlpha(0.8);
 				end
 				-- Set description
-				keyBindingDescription:SetText(GetBindingText(commandName, "BINDING_NAME_"));
-				-- Handle highlight
-				keyBindingButton1:UnlockHighlight();
-				keyBindingButton2:UnlockHighlight();
-				if ( KeyBindingFrame.selected == commandName ) then
-					if ( KeyBindingFrame.keyID == 1 ) then
-						keyBindingButton1:LockHighlight();
-					else
-						keyBindingButton2:LockHighlight();
-					end
-				end
-				_G["KeyBindingFrameBinding"..i]:Show();
+				keyBindingDescription:SetText(GetBindingName(commandName));
+				
+				keyBindingRow:Show();
 			end
 		else
-			_G["KeyBindingFrameBinding"..i]:Hide();
+			keyBindingRow:Hide();
 		end
 	end
 	
@@ -137,13 +260,20 @@ function KeyBindingFrame_Update()
 	KeyBindingFrame_UpdateUnbindKey();
 end
 
+function KeyBindingFrame_OnHide(self)
+	ShowUIPanel(GameMenuFrame);
+	KeyBindingFrame.outputText:SetText("");
+	PlaySound("gsTitleOptionExit");
+	UpdateMicroButtons();
+end
+
 function KeyBindingFrame_UnbindKey(keyPressed)
 	local oldAction = GetBindingAction(keyPressed, KeyBindingFrame.mode);
 	if ( oldAction ~= "" and oldAction ~= KeyBindingFrame.selected ) then
 		local key1, key2 = GetBindingKey(oldAction, KeyBindingFrame.mode);
 		if ( (not key1 or key1 == keyPressed) and (not key2 or key2 == keyPressed) ) then
 			--Error message
-			KeyBindingFrameOutputText:SetFormattedText(KEY_UNBOUND_ERROR, GetBindingText(oldAction, "BINDING_NAME_"));
+			KeyBindingFrame.outputText:SetFormattedText(KEY_UNBOUND_ERROR, GetBindingName(oldAction));
 		end
 	end
 	SetBinding(keyPressed, nil, KeyBindingFrame.mode);
@@ -152,10 +282,7 @@ end
 function KeyBindingFrame_OnKeyDown(self, keyOrButton)
 	if ( GetBindingFromClick(keyOrButton) == "SCREENSHOT" ) then
 		RunBinding("SCREENSHOT");
-		return;
-	end
-
-	if ( KeyBindingFrame.selected ) then
+	elseif ( KeyBindingFrame.selected ) then
 		local keyPressed = keyOrButton;
 
 		if ( keyPressed == "UNKNOWN" ) then
@@ -257,7 +384,7 @@ function KeyBindingFrame_OnKeyDown(self,
 			SetBinding(key2, nil, KeyBindingFrame.mode);
 		end
 		-- Unbind the current key and rebind current action
-		KeyBindingFrameOutputText:SetText(KEY_BOUND);
+		KeyBindingFrame.outputText:SetText(KEY_BOUND);
 		KeyBindingFrame_UnbindKey(keyPressed);
 		if ( KeyBindingFrame.keyID == 1 ) then
 			KeyBindingFrame_SetBinding(keyPressed, KeyBindingFrame.selected, key1);
@@ -275,13 +402,81 @@ function KeyBindingFrame_OnKeyDown(self,
 		KeyBindingFrame_SetSelected(nil);
 		KeyBindingFrame.buttonPressed:UnlockHighlight();
 		KeyBindingFrame.bindingsChanged = 1;
+		
+		KeyBindingFrame_UpdateUnbindKey();
 	elseif ( GetBindingFromClick(keyOrButton) == "TOGGLEGAMEMENU" ) then
 		LoadBindings(GetCurrentBindingSet());
-		KeyBindingFrameOutputText:SetText("");
+		KeyBindingFrame.outputText:SetText("");
 		KeyBindingFrame_SetSelected(nil);
 		HideUIPanel(self);
 	end
-	KeyBindingFrame_UpdateUnbindKey();
+end
+
+function KeyBindingFrame_SetBinding(key, selectedBinding, oldKey)
+	if ( SetBinding(key, selectedBinding, KeyBindingFrame.mode) ) then
+		return;
+	else
+		if ( oldKey ) then
+			SetBinding(oldKey, selectedBinding, KeyBindingFrame.mode);
+		end
+		--Error message
+		KeyBindingFrame.outputText:SetText(KEYBINDINGFRAME_MOUSEWHEEL_ERROR);
+	end
+end
+
+function KeyBindingFrame_UpdateUnbindKey()
+	if ( KeyBindingFrame.selected ) then
+		KeyBindingFrame.unbindButton:Enable();
+	else
+		KeyBindingFrame.unbindButton:Disable();
+	end
+end
+
+function KeyBindingFrame_UpdateHeaderText()
+	if ( KeyBindingFrame.characterSpecificButton:GetChecked() ) then
+		KeyBindingFrame.header.text:SetFormattedText(CHARACTER_KEY_BINDINGS, UnitName("player"));
+	else
+		KeyBindingFrame.header.text:SetText(KEY_BINDINGS);
+	end
+	KeyBindingFrame.header:SetWidth(KeyBindingFrame.header.text:GetWidth() + 80);
+end
+
+function KeyBindingFrame_ChangeBindingProfile()
+	if ( KeyBindingFrame.characterSpecificButton:GetChecked() ) then
+		LoadBindings(CHARACTER_BINDINGS);
+	else
+		LoadBindings(ACCOUNT_BINDINGS);
+	end
+	KeyBindingFrame_UpdateHeaderText();
+	KeyBindingFrame.outputText:SetText("");
+	KeyBindingFrame_SetSelected(nil);
+	KeyBindingFrame_Update();
+end
+
+function KeyBindingFrame_SetSelected(value, keyBindingButton)
+	KeyBindingFrame.selected = value;
+	if ( KeyBindingFrame.selectedButton ) then
+		local oldSelectedButton = KeyBindingFrame.selectedButton;
+		oldSelectedButton.selectedHighlight:Hide();
+		oldSelectedButton:GetHighlightTexture():SetAlpha(1);
+	end
+	if ( keyBindingButton ) then
+		KeyBindingFrame.selectedButton = keyBindingButton;
+		keyBindingButton.selectedHighlight:Show();
+		keyBindingButton:GetHighlightTexture():SetAlpha(0);
+		KeyBindingFrame.selectedButtonIndex = keyBindingButton.buttonIndex;
+		KeyBindingFrame.selectedRowIndex = keyBindingButton.rowIndex;
+	end
+end
+
+function KeyBindingFrame_OnMouseWheel(self, delta)
+	if ( self.selected ) then
+		if ( delta > 0 ) then
+			KeyBindingFrame_OnKeyDown(self, "MOUSEWHEELUP");
+		else
+			KeyBindingFrame_OnKeyDown(self, "MOUSEWHEELDOWN");
+		end
+	end
 end
 
 function KeyBindingButton_OnClick(self, button)
@@ -292,13 +487,13 @@ function KeyBindingButton_OnClick(self,
 			-- Deselect button if it was the pressed previously pressed
 			if (KeyBindingFrame.buttonPressed == self) then
 				KeyBindingFrame_SetSelected(nil);
-				KeyBindingFrameOutputText:SetText("");
+				KeyBindingFrame.outputText:SetText("");
 			else
 				-- Select a different button
 				KeyBindingFrame.buttonPressed = self;
-				KeyBindingFrame_SetSelected(self.commandName);
+				KeyBindingFrame_SetSelected(self.commandName, self);
 				KeyBindingFrame.keyID = self:GetID();
-				KeyBindingFrameOutputText:SetFormattedText(BIND_KEY_TO_COMMAND, GetBindingText(self.commandName, "BINDING_NAME_"));
+				KeyBindingFrame.outputText:SetFormattedText(BIND_KEY_TO_COMMAND, GetBindingName(self.commandName));
 			end
 			KeyBindingFrame_Update();
 			return;
@@ -309,47 +504,124 @@ function KeyBindingButton_OnClick(self,
 			KeyBindingFrame.buttonPressed:UnlockHighlight();
 		end
 		KeyBindingFrame.buttonPressed = self;
-		KeyBindingFrame_SetSelected(self.commandName);
+		KeyBindingFrame_SetSelected(self.commandName, self);
 		KeyBindingFrame.keyID = self:GetID();
-		KeyBindingFrameOutputText:SetFormattedText(BIND_KEY_TO_COMMAND, GetBindingText(self.commandName, "BINDING_NAME_"));
+		KeyBindingFrame.outputText:SetFormattedText(BIND_KEY_TO_COMMAND, GetBindingName(self.commandName));
 		KeyBindingFrame_Update();
 	end
 	KeyBindingFrame_UpdateUnbindKey();
 end
 
-function KeyBindingFrame_SetBinding(key, selectedBinding, oldKey)
-	if ( SetBinding(key, selectedBinding, KeyBindingFrame.mode) ) then
-		return;
+function KeybindingsCategoryListButton_OnClick(self, button)
+	PlaySound("igMainMenuOptionCheckBoxOn");
+	OptionsList_ClearSelection(KeyBindingFrame.categoryList, KeyBindingFrame.categoryList.buttons);
+	OptionsList_SelectButton(self:GetParent(), self);
+	
+	KeyBindingFrame.cntCategory = self.element.category;
+	KeyBindingFrame_SetSelected(nil);
+	KeyBindingFrame.outputText:SetText("");
+	KeyBindingFrameScrollFrame.ScrollBar:SetValue(0);
+	KeyBindingFrame_Update();
+end
+
+function CharacterSpecificButton_OnLoad(self)
+	self.text:SetText(HIGHLIGHT_FONT_COLOR_CODE..CHARACTER_SPECIFIC_KEYBINDINGS..FONT_COLOR_CODE_CLOSE);
+end
+
+function CharacterSpecificButton_OnClick(self)
+	if (self.enabled) then
+		PlaySound("igMainMenuOptionCheckBoxOn");
 	else
-		if ( oldKey ) then
-			SetBinding(oldKey, selectedBinding, KeyBindingFrame.mode);
-		end
-		--Error message
-		KeyBindingFrameOutputText:SetText(KEYBINDINGFRAME_MOUSEWHEEL_ERROR);
+		PlaySound("igMainMenuOptionCheckBoxOff");
+	end
+	if ( KeyBindingFrame.bindingsChanged ) then
+		StaticPopup_Show("CONFIRM_LOSE_BINDING_CHANGES");
+	else
+		KeyBindingFrame_ChangeBindingProfile();
 	end
 end
 
-function KeyBindingFrame_UpdateUnbindKey()
-	if ( KeyBindingFrame.selected ) then
-		KeyBindingFrameUnbindButton:Enable();
+function CharacterSpecificButton_OnEnter(self)
+	GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
+	GameTooltip:SetText(CHARACTER_SPECIFIC_KEYBINDING_TOOLTIP, nil, nil, nil, nil, true);
+end
+
+function CharacterSpecificButton_OnHide(self)
+	GameTooltip_Hide();
+end
+
+function UnbindButton_OnClick(self)
+	PlaySound("igMainMenuOptionCheckBoxOn");
+	local key1, key2 = GetBindingKey(KeyBindingFrame.selected, KeyBindingFrame.mode);
+	if ( key1 ) then
+		SetBinding(key1, nil, KeyBindingFrame.mode);
+	end
+	if ( key2 ) then
+		SetBinding(key2, nil, KeyBindingFrame.mode);
+	end
+	if ( key1 and KeyBindingFrame.keyID == 1 ) then
+		KeyBindingFrame_SetBinding(key1, nil, key1);
+		if ( key2 ) then
+			SetBinding(key2, KeyBindingFrame.selected, KeyBindingFrame.mode);
+		end
 	else
-		KeyBindingFrameUnbindButton:Disable();
+		if ( key1 ) then
+			KeyBindingFrame_SetBinding(key1, KeyBindingFrame.selected);
+		end
+		if ( key2 ) then
+			KeyBindingFrame_SetBinding(key2, nil, key2);
+		end
 	end
+	KeyBindingFrame_Update();
+	-- Button highlighting stuff
+	KeyBindingFrame_SetSelected(nil);
+	KeyBindingFrame.buttonPressed:UnlockHighlight();
+	KeyBindingFrame_UpdateUnbindKey();
+	KeyBindingFrame.outputText:SetText();
 end
 
-function KeyBindingFrame_ChangeBindingProfile()
-	if ( KeyBindingFrameCharacterButton:GetChecked() ) then
-		LoadBindings(CHARACTER_BINDINGS);
-		KeyBindingFrameHeaderText:SetFormattedText(CHARACTER_KEY_BINDINGS, UnitName("player"));
+function OkayButton_OnClick(self)
+	if ( KeyBindingFrame.characterSpecificButton:GetChecked() ) then
+		KeyBindingFrame.which = CHARACTER_BINDINGS;
 	else
-		LoadBindings(ACCOUNT_BINDINGS);
-		KeyBindingFrameHeaderText:SetText(KEY_BINDINGS);
+		KeyBindingFrame.which = ACCOUNT_BINDINGS;
+		if ( GetCurrentBindingSet() == CHARACTER_BINDINGS ) then
+			if ( not CONFIRMED_DELETING_CHARACTER_SPECIFIC_BINDINGS ) then
+				StaticPopup_Show("CONFIRM_DELETING_CHARACTER_SPECIFIC_BINDINGS");
+				return;
+			end
+		end
 	end
-	KeyBindingFrameOutputText:SetText("");
+	SaveBindings(KeyBindingFrame.which);
+	KeyBindingFrame.outputText:SetText("");
+	KeyBindingFrame_SetSelected(nil);
+	HideUIPanel(KeyBindingFrame);
+end
+
+function CancelButton_OnClick(self)
+	LoadBindings(GetCurrentBindingSet());
+	KeyBindingFrame.outputText:SetText("");
+	KeyBindingFrame_SetSelected(nil);
+	HideUIPanel(KeyBindingFrame);
+end
+
+function DefaultsButton_OnClick(self)
+	StaticPopup_Show("CONFIRM_RESET_TO_DEFAULT_KEYBINDINGS");
+end
+
+function KeyBindingFrame_ResetBindingsToDefault()
+	PlaySound("igMainMenuOptionCheckBoxOn");
+	LoadBindings(DEFAULT_BINDINGS);
+	KeyBindingFrame.outputText:SetText("");
 	KeyBindingFrame_SetSelected(nil);
 	KeyBindingFrame_Update();
 end
 
-function KeyBindingFrame_SetSelected(value)
-	KeyBindingFrame.selected = value;
+function GetBindingName(binding)
+	local bindingName = _G["BINDING_NAME_"..binding];
+	if ( bindingName ) then
+		return bindingName;
+	end
+	
+	return binding;
 end
\ No newline at end of file