WindActionShiftSize = {
	{231, 51},
	{195, 87},
	{87, 195},
	{51, 231}
}

function WindActionShift_OnLoad()
	for i=1, 10 do 
		getglobal("ShapeshiftButton"..i):SetParent(WindActionShift);
	end
	WindCommon_setPoint(ShapeshiftButton1, "TOPLEFT", WindActionShift, "TOPLEFT", 11, -10);
	WindCommon_setSize(ShapeshiftBarFrame, 1, 1);
	WindActionShift_update();
	this:RegisterEvent("PLAYER_ENTERING_WORLD");
	this:RegisterEvent("UPDATE_SHAPESHIFT_FORMS");
	this:RegisterEvent("ACTIONBAR_PAGE_CHANGED");
	this:RegisterEvent("VARIABLES_LOADED");
end

function WindActionShiftButton_OnUpdate()
	local start, duration, enable = GetShapeshiftFormCooldown(this:GetID());
	local text = getglobal(this:GetName().."RCCCount");
	if (start>0 and duration>0 and enable>0) then
		if ( WindActionBodyConfig[1] and duration > 2.0 ) then
			text:SetText(WindActionButton_getColldownText(start, duration, GetTime()));
			text:Show();
		else
			text:Hide();
		end
	else
		this.needUpdate	= false;
		text:Hide();
	end
end

function WindActionShift_update()
	WindActionShift_initConfig();
	if (GetNumShapeshiftForms() > 0 and WindActionShiftConfig[8]) then 
		WindActionShift:Show();
		WindActionShiftBorder_setSize();
	else 
		WindActionShift:Hide();
	end
	ShapeshiftBar_UpdateState();
end

function WindActionShift_OnEvent()
	if (event == "PLAYER_ENTERING_WORLD" or event == "UPDATE_SHAPESHIFT_FORMS") then WindActionShift_update();
	elseif (event == "ACTIONBAR_PAGE_CHANGED") then
		if ( GetBonusBarOffset() > 0 ) then ShowBonusActionBar();
		else HideBonusActionBar() end
	elseif (event == "VARIABLES_LOADED") then
		WindActionShift_initConfig();
		WindActionShift_setPoint();
		WindActionShift_setScale();
		WindActionShift_setSize();
		WindActionShift_setBorder();
	else ShapeshiftBar_UpdateState(); end
end

function WindActionShift_initConfig()
	if (not WindActionShiftConfig) then WindActionShiftConfig = WindActionDefault["Shift"]; end

	if (IsAddOnLoaded("WindConfig")) then 
		WindActionConfigShift_show();
		WindActionConfigShift_setColor(color); 
	end
end

function WindActionShift_setPoint()
	WindCommon_setPoint(WindActionShift, WindActionShiftConfig[1], UIParent, WindActionShiftConfig[1], WindActionShiftConfig[2], WindActionShiftConfig[3]);
end

function WindActionShift_setScale()
	WindActionShift:SetScale(WindActionShiftConfig[4]);
end

function WindActionShift_setSize()
	local index = WindActionShiftConfig[5];
	WindActionShiftBorder_setSize();
	WindCommon_setSize(WindActionShift, WindActionShiftSize[index][1], WindActionShiftSize[index][2]);
	WindActionShift_setAnchor(index);
end

function WindActionShiftBorder_setSize()
	local index = WindActionShiftConfig[5];
	local blanksize = 15;
	local buttonsize = 36;
	if (GetNumShapeshiftForms() == 1) then
		UIPARENT_MANAGED_FRAME_POSITIONS["ShapeshiftBarFrame"].baseY = 6 * WindActionShiftConfig[4];
		UIPARENT_MANAGED_FRAME_POSITIONS["ShapeshiftBarFrame"].anchorTo="WindActionShift";
		UIPARENT_MANAGED_FRAME_POSITIONS["ShapeshiftBarFrame"].point="BOTTOMLEFT";
		UIPARENT_MANAGED_FRAME_POSITIONS["ShapeshiftBarFrame"].rpoint="BOTTOMLEFT";
		WindCommon_setSize(WindActionShift, blanksize + buttonsize, blanksize + buttonsize);
	else
		for i=2, 10 do
			if (GetNumShapeshiftForms() == i) then
				if (index == 1) then
					WindCommon_setSize(WindActionShift, blanksize + buttonsize*i, blanksize + buttonsize);
				elseif (index == 2) then
					WindCommon_setSize(WindActionShift, blanksize + buttonsize*floor((i*0.5)+0.5), blanksize + buttonsize*2);
				elseif (index == 3) then
					WindCommon_setSize(WindActionShift, blanksize + buttonsize*2, blanksize + buttonsize*floor((i*0.5)+0.5));
				elseif (index == 4) then
					WindCommon_setSize(WindActionShift, blanksize + buttonsize, blanksize + buttonsize*i);
				end
			end
		end
	end
end

function WindActionShift_setAnchor(index)
	if (index == 1) then
		WindCommon_setPoint(ShapeshiftButton2, "LEFT", ShapeshiftButton1, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton3, "LEFT", ShapeshiftButton2, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton4, "LEFT", ShapeshiftButton3, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton5, "LEFT", ShapeshiftButton4, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton6, "LEFT", ShapeshiftButton5, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton7, "LEFT", ShapeshiftButton6, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton8, "LEFT", ShapeshiftButton7, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton9, "LEFT", ShapeshiftButton8, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton10, "LEFT", ShapeshiftButton9, "RIGHT", 6, 0);
	elseif (index == 2) then
		WindCommon_setPoint(ShapeshiftButton2, "TOPLEFT", ShapeshiftButton1, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton3, "LEFT", ShapeshiftButton1, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton4, "TOPLEFT", ShapeshiftButton3, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton5, "LEFT", ShapeshiftButton3, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton6, "TOPLEFT", ShapeshiftButton5, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton7, "LEFT", ShapeshiftButton5, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton8, "TOPLEFT", ShapeshiftButton7, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton9, "LEFT", ShapeshiftButton7, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton10, "TOPLEFT", ShapeshiftButton9, "BOTTOMLEFT", 0, -6);
	elseif (index == 3) then
		WindCommon_setPoint(ShapeshiftButton2, "LEFT", ShapeshiftButton1, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton3, "TOPLEFT", ShapeshiftButton1, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton4, "LEFT", ShapeshiftButton3, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton5, "TOPLEFT", ShapeshiftButton3, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton6, "LEFT", ShapeshiftButton5, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton7, "TOPLEFT", ShapeshiftButton5, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton8, "LEFT", ShapeshiftButton7, "RIGHT", 6, 0);
		WindCommon_setPoint(ShapeshiftButton9, "TOPLEFT", ShapeshiftButton7, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton10, "LEFT", ShapeshiftButton9, "RIGHT", 6, 0);
	elseif (index == 4) then
		WindCommon_setPoint(ShapeshiftButton2, "TOPLEFT", ShapeshiftButton1, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton3, "TOPLEFT", ShapeshiftButton2, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton4, "TOPLEFT", ShapeshiftButton3, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton5, "TOPLEFT", ShapeshiftButton4, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton6, "TOPLEFT", ShapeshiftButton5, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton7, "TOPLEFT", ShapeshiftButton6, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton8, "TOPLEFT", ShapeshiftButton7, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton9, "TOPLEFT", ShapeshiftButton8, "BOTTOMLEFT", 0, -6);
		WindCommon_setPoint(ShapeshiftButton10, "TOPLEFT", ShapeshiftButton9, "BOTTOMLEFT", 0, -6);
	end
end

function WindActionShift_setBorder()
	if (WindActionShiftConfig[6]) then 
		WindActionShift:SetBackdrop(WindCommon_ColorBorder);
		WindActionShift_setColor();
	else 
		WindActionShift:SetBackdrop(nil); 
	end
end

function WindActionShift_setColor()
	WindActionShift:SetBackdropBorderColor(WindActionShiftConfig[7][1].r, WindActionShiftConfig[7][1].g, WindActionShiftConfig[7][1].b, WindActionShiftConfig[7][1].a);
	WindActionShift:SetBackdropColor(WindActionShiftConfig[7][2].r, WindActionShiftConfig[7][2].g, WindActionShiftConfig[7][2].b, WindActionShiftConfig[7][2].a);
end

function WindActionShift_resetColor()
	WindActionShiftConfig[7] = WindActionDefault["Shift"][7];
	WindActionShift_setColor();
end
