-------------------------------------------------------------------------------
--
--  Mod Name : BlinkWhoAreYou v2.0
--  Author   : Blink
--  Date     : 2006/??/??
--  LastUpdate : 2007/11/16
--
-------------------------------------------------------------------------------

local loAF_ToolTip_OnMouseOver = nil;
local loTooltipsBase_UnitHandler = nil;
local memoColor = {r=0.8, g=0.8, b=0.8};
local currentShowing = nil;


BINDING_HEADER_BLINKWHOAREYOU	= "블링크의 누구냐넌?";
BINDING_NAME_BWAY_EDIT			= "대상 메모창 열기/닫기";

BWAY_TITLE_NAME = "이름";
BWAY_TITLE_MEMO = "메모";
BWAY_TITLE_ALLIANCE = "얼라이언스";
BWAY_TITLE_HORDE = "호드";
BWAY_TITLE_NPC = "몹/NPC";

function BlinkWhoAreYou_OnLoad()
	BlinkWhoAreYouDB = {};
	BWAY_Hooks();
	BWAY_Register();
end

function BWAY_Hooks()
	--ChatFrame1:AddMessage("BWAY_Hooks Load.");

	-- 2.0.3 버전 이상에서 작동
--	hooksecurefunc(GameTooltip,"OnTooltipSetUnit",function ()
--		local name = this:GetUnit();
--		if ( name and BlinkWhoAreYouDB[name] ) then
--			local bway = BlinkWhoAreYouDB[name];
--			GameTooltip:AddLine(bway.memo, bway.r, bway.g, bway.b, 1);
--			currentShowing = name;
--		end
--	end);
	GameTooltip:HookScript("OnTooltipSetUnit",function ()
		local name = this:GetUnit();
		if ( name and BlinkWhoAreYouDB[name] ) then
			local bway = BWAY_GetWhoAreYou(name);
			if (bway.memo and bway.memo~="") then
				GameTooltip:AddLine(bway.memo, bway.r, bway.g, bway.b, 1);
				currentShowing = name;
			end
		end
	end);

	hooksecurefunc("UnitFrame_OnEnter", function (self)
		if ( UnitExists(self.unit) ) then
			local name = UnitName(self.unit);
			local bway = BWAY_GetWhoAreYou(name);
			if ( bway.memo and bway.memo~="" and name ~= currentShowing ) then
				GameTooltip:AddLine(bway.memo, bway.r, bway.g, bway.b, 1);
				GameTooltip:Show();
			end
		end
	end);

	hooksecurefunc("UnitFrame_OnLeave", function ()
		currentShowing = nil;
	end);

--	BWAY_Original_TargetFrameHealthBar_OnEnter = TargetFrameHealthBar:GetScript("OnEnter");
--	TargetFrameHealthBar:SetScript("OnEnter",function ()
--		BWAY_Original_TargetFrameHealthBar_OnEnter();
--		if ( this:GetParent() == TargetFrame ) then
--			if ( UnitExists(TargetFrame.unit) ) then
--				local name = UnitName(TargetFrame.unit);
--				if ( BlinkWhoAreYouDB[name] ) then
--					GameTooltip:AddLine(BlinkWhoAreYouDB[name], memoColor.r, memoColor.g, memoColor.b, 1);
--					GameTooltip:Show();
--				end
--			end
--		end
--	end);
--	BWAY_Original_TargetFrameManaBar_OnEnter = TargetFrameManaBar:GetScript("OnEnter");
--	TargetFrameManaBar:SetScript("OnEnter",function ()
--		BWAY_Original_TargetFrameManaBar_OnEnter();
--		if ( this:GetParent() == TargetFrame ) then
--			if ( UnitExists(TargetFrame.unit) ) then
--				local name = UnitName(TargetFrame.unit);
--				if ( BlinkWhoAreYouDB[name] ) then
--					GameTooltip:AddLine(BlinkWhoAreYouDB[name], memoColor.r, memoColor.g, memoColor.b, 1);
--					GameTooltip:Show();
--				end
--			end
--		end
--	end);

	for i=1, 10 do
		getglobal("FriendsFrameFriendButton"..i):SetScript("OnEnter",BWAY_FriendButton_OnEnter);
		getglobal("FriendsFrameFriendButton"..i):SetScript("OnLeave",BWAY_Button_OnLeave);
	end
	for i=1, 20 do
		getglobal("FriendsFrameIgnoreButton"..i):SetScript("OnEnter",BWAY_FriendIgnoreButton_OnEnter);
		getglobal("FriendsFrameIgnoreButton"..i):SetScript("OnLeave",BWAY_Button_OnLeave);
	end
	for i=1, 17 do
		getglobal("WhoFrameButton"..i):SetScript("OnEnter",BWAY_WhoFrameButton_OnEnter);
		getglobal("WhoFrameButton"..i):SetScript("OnLeave",BWAY_Button_OnLeave);
	end
	for i=1, 17 do
		getglobal("FriendsFrameMutedButton"..i):SetScript("OnEnter",BWAY_FriendsFrameMutedButton_OnEnter);
		getglobal("FriendsFrameMutedButton"..i):SetScript("OnLeave",BWAY_Button_OnLeave);
	end

	for i=1, 13 do
		local prev_onenter = getglobal("GuildFrameButton"..i):GetScript("OnEnter");
		getglobal("GuildFrameButton"..i):SetScript("OnEnter",function ()
			prev_onenter();
			BWAY_GuildFrameButton_OnEnter();
		end);
	end

--	-- for AF_Tooltip1.7 Addon
--	if ( AF_ToolTip_OnMouseOver ) then
--		loAF_ToolTip_OnMouseOver = AF_ToolTip_OnMouseOver;
--		AF_ToolTip_OnMouseOver = function ()
--			loAF_ToolTip_OnMouseOver();
--			if BlinkWhoAreYouDB[UnitName("mouseover")] then
--				GameTooltip:AddLine(BlinkWhoAreYouDB[UnitName("mouseover")], memoColor.r, memoColor.g, memoColor.b, 1);
--				GameTooltip:Show();
--			end
--		end
--	-- for AF_Tooltip5.8x Addon
--	elseif ( aftt_format ) then
--		loaftt_format = aftt_format;
--		aftt_format = function (unit)
--			loaftt_format(unit);
--			if BlinkWhoAreYouDB[UnitName(unit)] then
--				GameTooltip:AddLine(BlinkWhoAreYouDB[UnitName(unit)], memoColor.r, memoColor.g, memoColor.b, 1);
--				GameTooltip:Show();
--			end
--		end
--	end
--
--	-- for Hanulari_TooltipsBase Addon
--	if ( TooltipsBase_UnitHandler ) then
--		loTooltipsBase_UnitHandler = TooltipsBase_UnitHandler;
--		TooltipsBase_UnitHandler = function (type)
--			loTooltipsBase_UnitHandler(type);
--			if BlinkWhoAreYouDB[UnitName("mouseover")] then
--				GameTooltip:AddLine(BlinkWhoAreYouDB[UnitName("mouseover")], memoColor.r, memoColor.g, memoColor.b, 1);
--				GameTooltip:Show();
--			end
--		end
--	end
--
--	-- for bRaid Addon
--	if ( bRaid_OnEnter ) then
--		lobRaid_OnEnter = bRaid_OnEnter;
--		bRaid_OnEnter = function (self)
--			lobRaid_OnEnter(self);
--			if BlinkWhoAreYouDB[UnitName(self.unit)] then
--				GameTooltip:AddLine(BlinkWhoAreYouDB[UnitName(self.unit)], memoColor.r, memoColor.g, memoColor.b, 1);
--				GameTooltip:Show();
--			end
--		end
--	end
--
--	-- for BlinkToT Addon
--	if ( BlinkToT_OnEnter ) then
--		loBlinkToT_OnEnter = BlinkToT_OnEnter;
--		BlinkToT_OnEnter = function ()
--			loBlinkToT_OnEnter();
--			if BlinkWhoAreYouDB[UnitName("targettarget")] then
--				GameTooltip:AddLine(BlinkWhoAreYouDB[UnitName("targettarget")], memoColor.r, memoColor.g, memoColor.b, 1);
--				GameTooltip:Show();
--			end
--		end
--	end
end

function BWAY_Button_OnLeave()
	GameTooltip:Hide();
end

function BWAY_FriendButton_OnEnter(self)
	local name = GetFriendInfo(this:GetID()+FauxScrollFrame_GetOffset(FriendsFrameFriendsScrollFrame));
	local bway = BWAY_GetWhoAreYou(name);
	if ( bway.memo and bway.memo~="" ) then
		GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT");
		GameTooltip:SetText("누구냐넌", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
		GameTooltip:AddLine(bway.memo, bway.r, bway.g, bway.b);
		GameTooltip:Show();
	end
end

function BWAY_FriendIgnoreButton_OnEnter(self)
	local name = GetIgnoreName(this:GetID()+FauxScrollFrame_GetOffset(FriendsFrameIgnoreScrollFrame));
	local bway = BWAY_GetWhoAreYou(name);
	if ( bway.memo and bway.memo~="" ) then
		GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT");
		GameTooltip:SetText("누구냐넌", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
		GameTooltip:AddLine(bway.memo, bway.r, bway.g, bway.b);
		GameTooltip:Show();
	end
end

function BWAY_FriendsFrameMutedButton_OnEnter(self)
	local name = GetMuteName(this:GetID()+FauxScrollFrame_GetOffset(FriendsFrameMutedScrollFrame));
	local bway = BWAY_GetWhoAreYou(name);
	if ( bway.memo and bway.memo~="" ) then
		GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT");
		GameTooltip:SetText("누구냐넌", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
		GameTooltip:AddLine(bway.memo, bway.r, bway.g, bway.b);
		GameTooltip:Show();
	end
end

function BWAY_WhoFrameButton_OnEnter(self)
	local name = getglobal("WhoFrameButton"..this:GetID().."Name"):GetText();
	local bway = BWAY_GetWhoAreYou(name);
	if ( bway.memo and bway.memo~="" ) then
		GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT");
		GameTooltip:SetText("누구냐넌", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
		GameTooltip:AddLine(bway.memo, bway.r, bway.g, bway.b);
		GameTooltip:Show();
	end
end

function BWAY_GuildFrameButton_OnEnter(self)
	local name = getglobal(this:GetName().."Name"):GetText();
	local bway = BWAY_GetWhoAreYou(name);
	if ( bway.memo and bway.memo~="" ) then
		GameTooltip:AddLine(bway.memo, bway.r, bway.g, bway.b);
		GameTooltip:Show();
	end
end

function BWAY_Register()
	if ( not BlinkMod_RegisterMenu ) then
		return;
	end

	local info;

	-- parent = PARTY
	info = {};
	info.parentkey = "PARTY";
	info.key = "BWAYMEMOPARTY";
	info.text = "누구냐넌";
	info.tooltipTitle = "누구냐넌"
	info.tooltipText = "해당플레이어에 메모를 해둘수있습니다. 메모는 툴팁에 표시됩니다.";
	info.notCheckable = 1;
	info.ClickFunction = BWAY_BM_MemoClick;
	info.GetNameFunction = BWAY_BM_MemoName;
	BlinkMod_RegisterMenu( info, 1 );

	-- parent = FRIEND
	info = {};
	info.parentkey = "FRIEND";
	info.key = "BWAYMEMOFRIEND";
	info.text = "누구냐넌";
	info.tooltipTitle = "누구냐넌"
	info.tooltipText = "해당플레이어에 메모를 해둘수있습니다. 메모는 툴팁에 표시됩니다.";
	info.notCheckable = 1;
	info.ClickFunction = BWAY_BM_MemoClick;
	info.GetNameFunction = BWAY_BM_MemoName;
	BlinkMod_RegisterMenu( info, 1 );

	-- parent = RAID_PLAYER
	info = {};
	info.parentkey = "RAID_PLAYER";
	info.key = "BWAYMEMORAID";
	info.text = "누구냐넌";
	info.tooltipTitle = "누구냐넌"
	info.tooltipText = "해당플레이어에 메모를 해둘수있습니다. 메모는 툴팁에 표시됩니다.";
	info.notCheckable = 1;
	info.ClickFunction = BWAY_BM_MemoClick;
	info.GetNameFunction = BWAY_BM_MemoName;
	BlinkMod_RegisterMenu( info, 1 );

	-- parent = PLAYER
	info = {};
	info.parentkey = "PLAYER";
	info.key = "BWAYMEMOPLAYER";
	info.text = "누구냐넌";
	info.tooltipTitle = "누구냐넌"
	info.tooltipText = "해당플레이어에 메모를 해둘수있습니다. 메모는 툴팁에 표시됩니다.";
	info.notCheckable = 1;
	info.ClickFunction = BWAY_BM_MemoClick;
	info.GetNameFunction = BWAY_BM_MemoName;
	BlinkMod_RegisterMenu( info, 1 );

	-- parent = NPC enemy
	info = {};
	info.parentkey = "NPC";
	info.key = "BWAYMEMONPC";
	info.text = "누구냐넌";
	info.tooltipTitle = "누구냐넌"
	info.tooltipText = "NPC 메모를 해둘수있습니다. 메모는 툴팁에 표시됩니다.";
	info.notCheckable = 1;
	info.ClickFunction = BWAY_BM_MemoClick;
	info.GetNameFunction = BWAY_BM_MemoName;
	BlinkMod_RegisterMenu( info, 1 );

	-- parent = ENEMY player
	info = {};
	info.parentkey = "ENEMY";
	info.key = "BWAYMEMOENEMY";
	info.text = "누구냐넌";
	info.tooltipTitle = "누구냐넌"
	info.tooltipText = "적플레이어에 메모를 해둘수있습니다. 메모는 툴팁에 표시됩니다.";
	info.notCheckable = 1;
	info.ClickFunction = BWAY_BM_MemoClick;
	info.GetNameFunction = BWAY_BM_MemoName;
	BlinkMod_RegisterMenu( info, 1 );

end

function BWAY_BM_MemoClick( dropdownFrame )
	local name;
	local faction = "N";
	if ( dropdownFrame.unit ) then
		name = UnitName(dropdownFrame.unit);
		if UnitIsPlayer("target") and UnitFactionGroup(dropdownFrame.unit)=="Alliance" then
			faction = "A";
		elseif UnitIsPlayer("target") and UnitFactionGroup(dropdownFrame.unit)=="Horde" then
			faction = "H";
		end
	elseif ( dropdownFrame.name ) then
		name = dropdownFrame.name;
	end
	BlinkWhoAreYouFrame.name = name;
	BlinkWhoAreYouFrame.faction = faction;
	BlinkWhoAreYouFrame:Show();
end

function BWAY_BM_MemoName(txt,dropdownMenu)
	local bway;
	if ( dropdownMenu.unit ) then
		bway = BWAY_GetWhoAreYou(UnitName(dropdownMenu.unit));
	elseif ( dropdownMenu.name ) then
		bway = BWAY_GetWhoAreYou(dropdownMenu.unit);
	end
	if ( bway.memo ~= "" ) then
		return "누구냐넌 : 편집";
	end
	return "누구냐넌";
end

function BWAY_SetWhoAreYou(name,memo,r,g,b,faction)
	if ( not BlinkWhoAreYouDB ) then
		BlinkWhoAreYouDB = {};
	end
	if ( not name or name == "" ) then
		return;
	end
	if ( not memo or memo == "" ) then
		BlinkWhoAreYouDB[name] = {
			memo = nil,
			r = nil,
			g = nil,
			b = nil,
			faction = nil
		};
		BlinkWhoAreYouDB[name] = nil;
	else
		BlinkWhoAreYouDB[name] = {
			memo = memo,
			r = r,
			g = g,
			b = b,
			faction = faction
		};
	end
end

function BWAY_GetWhoAreYou(name)
	if ( not BlinkWhoAreYouDB ) then
		return {memo="",r=0.8,g=0.8,b=0.8};
	end
	if ( not name or name == "" ) then
		return {memo="",r=0.8,g=0.8,b=0.8};
	end
	if BlinkWhoAreYouDB[name] and type(BlinkWhoAreYouDB[name])=='string' then
		local memo = BlinkWhoAreYouDB[name];
		BlinkWhoAreYouDB[name] = {
			memo = memo,
			r=0.8,
			g=0.8,
			b=0.8,
			faction = "N"
		};
	end
	return BlinkWhoAreYouDB[name] or {memo="",r=0.8,g=0.8,b=0.8};
end

-------------------------------------------------------------------------------
-- BlinkWhoAreYouFrame_OnFoo
-------------------------------------------------------------------------------

function BlinkWhoAreYouFrame_OnShow()
	local faction = "N";
	if ( not this.name or this.name=="" ) then
		getglobal(this:GetName().."TitleTitle"):SetText("누구냐넌");
		BWAYDeleteButton:Disable();
		faction = this.faction or faction;
		if faction == "A" then
			BWAYFactionAlliance:SetChecked(true);
			BWAYFactionHorde:SetChecked(false);
			BWAYFactionNPC:SetChecked(false);
		elseif faction == "H" then
			BWAYFactionAlliance:SetChecked(false);
			BWAYFactionHorde:SetChecked(true);
			BWAYFactionNPC:SetChecked(false);
		else
			BWAYFactionAlliance:SetChecked(false);
			BWAYFactionHorde:SetChecked(false);
			BWAYFactionNPC:SetChecked(true);
		end
		BWAYNameBox:SetFocus();
		BWAYNameBox:SetText("");
		BWAYMemoBox:SetTextColor(0.8, 0.8, 0.8);
		BWAYMemoBox:SetText("");
		BWAYColorSwatchNormalTexture:SetVertexColor(0.8, 0.8, 0.8);
	else
		getglobal(this:GetName().."TitleTitle"):SetText(this.name.."님의 메모");
		local memo = BWAY_GetWhoAreYou(this.name);
		if ( memo.memo:len()>0 ) then
			BWAYDeleteButton:Enable();
		else
			BWAYDeleteButton:Disable();
		end
		faction = memo.faction or this.faction or faction;
		if faction == "A" then
			BWAYFactionAlliance:SetChecked(true);
			BWAYFactionHorde:SetChecked(false);
			BWAYFactionNPC:SetChecked(false);
		elseif faction == "H" then
			BWAYFactionAlliance:SetChecked(false);
			BWAYFactionHorde:SetChecked(true);
			BWAYFactionNPC:SetChecked(false);
		else
			BWAYFactionAlliance:SetChecked(false);
			BWAYFactionHorde:SetChecked(false);
			BWAYFactionNPC:SetChecked(true);
		end
		BWAYMemoBox:SetFocus();
		BWAYNameBox:SetText(this.name or "");
		BWAYMemoBox:SetTextColor(memo.r, memo.g, memo.b);
		BWAYMemoBox:SetText(memo.memo);
		BWAYColorSwatchNormalTexture:SetVertexColor(memo.r or 0.8, memo.g or 0.8, memo.b or 0.8);
	end
	BWAYOkayButton_Update();
end

function BlinkWhoAreYouFrame_OnHide()
	BWAYNameBox:SetText("");
	BWAYMemoBox:SetText("");
	this.name = nil;
end

function BWAYOkayButton_OnClick()
	local name = BWAYNameBox:GetText();
	local memo = BWAYMemoBox:GetText();
	local r, g, b = BWAYMemoBox:GetTextColor();
	local f = BWAYFactionAlliance:GetChecked() and "A";
	f = BWAYFactionHorde:GetChecked() and "H" or f;
	f = BWAYFactionNPC:GetChecked() and "N" or f;
	BWAY_SetWhoAreYou(name,memo,r,g,b,f);
	BWAYOkayButton_Update();
	BlinkWhoAreYouFrame:Hide();
end

function BWAYOkayButton_Update()
	if ( strlen(BWAYNameBox:GetText()) > 0 and strlen(BWAYMemoBox:GetText()) > 0 ) then
		BWAYOkayButton:Enable();
	else
		BWAYOkayButton:Disable();
	end
end

function BWAYDeleteButton_OnClick()
	BWAY_SetWhoAreYou(BlinkWhoAreYouFrame.name,nil);
	BlinkWhoAreYouFrame:Hide();
end

function BWAYColorSwatch_OpenColorPicker()
	local r, g, b = BWAYMemoBox:GetTextColor();
	CloseMenus();
	ColorPickerFrame.func = function ()
		local r, g, b = ColorPickerFrame:GetColorRGB();
		BWAYMemoBox:SetTextColor(r, g, b);
		BWAYColorSwatchNormalTexture:SetVertexColor(r, g, b);
	end;
	ColorPickerFrame:SetColorRGB(r, g, b);
	ColorPickerFrame.previousValues = {r = r, g = g, b = b};
	ColorPickerFrame.cancelFunc = function (previousValues)
		if ( previousValues.r ) then
			BWAYMemoBox:SetTextColor(previousValues.r, previousValues.g, previousValues.b);
			BWAYColorSwatchNormalTexture:SetVertexColor(previousValues.r, previousValues.g, previousValues.b);
		end
	end;
	ShowUIPanel(ColorPickerFrame);
end

function BWAYFaction_OnClick(faction)
	if faction == "Alliance" then
		BWAYFactionAlliance:SetChecked(true);
		BWAYFactionHorde:SetChecked(false);
		BWAYFactionNPC:SetChecked(false);
	elseif faction == "Horde" then
		BWAYFactionAlliance:SetChecked(false);
		BWAYFactionHorde:SetChecked(true);
		BWAYFactionNPC:SetChecked(false);
	elseif faction == "NPC" then
		BWAYFactionAlliance:SetChecked(false);
		BWAYFactionHorde:SetChecked(false);
		BWAYFactionNPC:SetChecked(true);
	end
end

function BWAYNameBox_SendeeAutocomplete()
	local text = this:GetText();
	local textlen = strlen(text);

	if ( BlinkWhoAreYouDB ) then
		for name, bway in pairs(BlinkWhoAreYouDB) do
			if ( name and text and textlen>0 and (strfind(strupper(name), strupper(text), 1, 1) == 1) ) then
				this:SetText(name);
				if ( this:IsInIMECompositionMode() ) then
					this:HighlightText(textlen - strlen(arg1), -1);
				else
					this:HighlightText(textlen, -1);
				end
				BlinkWhoAreYouFrame_Fill(name);
				return;
			end
		end
	end
	BlinkWhoAreYouFrame_Clear();
end

function BlinkWhoAreYouFrame_Fill(name)
	if name and name~="" and BlinkWhoAreYouDB and BlinkWhoAreYouDB[name] then
		BlinkWhoAreYouFrame.name = name;
		BlinkWhoAreYouFrameTitleTitle:SetText(name.."님의 메모");
		local memo = BWAY_GetWhoAreYou(name);
		if ( memo.memo:len()>0 ) then
			BWAYDeleteButton:Enable();
		else
			BWAYDeleteButton:Disable();
		end
		BWAYMemoBox:SetTextColor(memo.r, memo.g, memo.b);
		BWAYMemoBox:SetText(memo.memo);
		BWAYColorSwatchNormalTexture:SetVertexColor(memo.r or 0.8, memo.g or 0.8, memo.b or 0.8);
		faction = memo.faction or BlinkWhoAreYouFrame.faction or faction;
		if faction == "A" then
			BWAYFactionAlliance:SetChecked(true);
			BWAYFactionHorde:SetChecked(false);
			BWAYFactionNPC:SetChecked(false);
		elseif faction == "H" then
			BWAYFactionAlliance:SetChecked(false);
			BWAYFactionHorde:SetChecked(true);
			BWAYFactionNPC:SetChecked(false);
		else
			BWAYFactionAlliance:SetChecked(false);
			BWAYFactionHorde:SetChecked(false);
			BWAYFactionNPC:SetChecked(true);
		end
	end
end
function BlinkWhoAreYouFrame_Clear()
	BlinkWhoAreYouFrame.name = nil;
	BlinkWhoAreYouFrameTitleTitle:SetText("누구냐넌");
	BWAYDeleteButton:Disable();
	BWAYMemoBox:SetTextColor(0.8, 0.8, 0.8);
	BWAYMemoBox:SetText("");
	BWAYColorSwatchNormalTexture:SetVertexColor(0.8, 0.8, 0.8);
	faction = BlinkWhoAreYouFrame.faction or faction;
	if faction == "A" then
		BWAYFactionAlliance:SetChecked(true);
		BWAYFactionHorde:SetChecked(false);
		BWAYFactionNPC:SetChecked(false);
	elseif faction == "H" then
		BWAYFactionAlliance:SetChecked(false);
		BWAYFactionHorde:SetChecked(true);
		BWAYFactionNPC:SetChecked(false);
	else
		BWAYFactionAlliance:SetChecked(false);
		BWAYFactionHorde:SetChecked(false);
		BWAYFactionNPC:SetChecked(true);
	end
	--BWAYNameBox:SetFocus();
end

-------------------------------------------------------------------------------
-- binding function
-------------------------------------------------------------------------------

function BWAY_Open()
	local name = nil;
	local faction = "N";
	if ( BlinkWhoAreYouFrame:IsShown() ) then
		BlinkWhoAreYouFrame:Hide();
		return;
	end
	if ( UnitExists("target") ) then
		name = UnitName("target");
		if UnitIsPlayer("target") and UnitFactionGroup("target")=="Alliance" then
			faction = "A";
		elseif UnitIsPlayer("target") and UnitFactionGroup("target")=="Horde" then
			faction = "H";
		end
	end
	BlinkWhoAreYouFrame.name = name;
	BlinkWhoAreYouFrame.faction = faction;
	BlinkWhoAreYouFrame:Show();
end
