Index: ag_UnitClass.lua
===================================================================
--- ag_UnitClass.lua	(revision 15628)
+++ ag_UnitClass.lua	(working copy)
@@ -232,6 +234,7 @@
 	self.frame:SetScript("OnClick",function() self:OnClick(arg1) end)
 	self.frame:SetScript("OnHide",function() this:StopMovingOrSizing() end)
 	
+	--[[
 	for i =1,20 do
 		self["Aura"..i] = getglobal(frameName.."_Aura"..i)
 		self["Aura"..i].Icon = getglobal(frameName.."_Aura"..i.."Icon")
@@ -245,6 +248,10 @@
 		
 		self["Aura"..i]:Hide()
 	end
+	]]
+	
+	self:SetAuraCount(3, 10)
+	assert(self["Aura1"], "No auras found");
 
 	if string.find(self.name,"player") then
 		self.XPBar_Rest = CreateFrame("StatusBar",frameName.."_XPBar_Rest",self.frame)
@@ -899,11 +906,12 @@
 -- AURAS
 
 function aUF.classes.aUFunit.prototype:AuraPosition()
-	local scale = (self.frame:GetWidth()/170)
+	local scale = (self.frame:GetWidth()/17/self.AuraColumns)
 	local style,position = self.database.AuraStyle,self.database.AuraPos	
 	local yadjust = 0
+	local count = self.AuraRows * self.AuraColumns
 
-	for i=1,20 do
+	for i=1,count do
 		self["Aura"..i]:SetScale(scale)
 	end
 	
@@ -924,22 +932,22 @@
 	end
 
 	if ( position == "Left" ) then
-		for i=2,20 do
+		for i=2,count do
 			self["Aura"..i]:ClearAllPoints()
-			if i == 11 then
-				self["Aura"..i]:SetPoint("TOP",self.Aura1,"BOTTOM",0,-1)
+			if (math.mod(i,self.AuraColumns) == 1) then
+				self["Aura"..i]:SetPoint("TOP",self["Aura"..i-self.AuraColumns],"BOTTOM",0,-1)
 			else
 				self["Aura"..i]:SetPoint("RIGHT",self["Aura"..i-1],"LEFT",1,0)
 			end
 		end
 	else
-		for i=2,20 do
+		for i=2,count do
 			self["Aura"..i]:ClearAllPoints()
-			if i == 11 then
+			if (math.mod(i,self.AuraColumns) == 1) then
 				if position == "Above" then
-					self["Aura"..i]:SetPoint("BOTTOM",self.Aura1,"TOP",0,1)
-				else
-					self["Aura"..i]:SetPoint("TOP",self.Aura1,"BOTTOM",0,-1)
+					self["Aura"..i]:SetPoint("BOTTOM",self["Aura"..i-self.AuraColumns],"TOP",0,1)
+ 				else
+					self["Aura"..i]:SetPoint("TOP",self["Aura"..i-self.AuraColumns],"BOTTOM",0,-1)
 				end
 			else
 				self["Aura"..i]:SetPoint("LEFT",self["Aura"..i-1],"RIGHT",1,0)
@@ -948,6 +956,36 @@
 	end
 end
 
+function aUF.classes.aUFunit.prototype:SetAuraCount(rows, columns)
+	assert(rows == 2 or rows == 3, "Rows must be 2 or 3");
+	assert(columns >= 8 and columns <= 12, "Columns must be between 8 and 12");
+	assert(rows * columns >= 20, "Total buff slots must be 20 or more");
+	
+	local count = rows * columns;
+	local frameName = self.frame:GetName();
+	local frame = self.frame;
+	
+	self.AuraRows = rows;
+	self.AuraColumns = columns;
+	
+	-- setup auras
+	for i = 1,count do
+		self["Aura"..i] = getglobal(frameName.."_Aura"..i) or CreateFrame("Button", frameName .. "_Aura" .. i, frame, "AGAuraTemplate");
+		
+		self["Aura"..i].Icon = getglobal(frameName.."_Aura"..i.."Icon")
+		self["Aura"..i].Overlay = getglobal(frameName.."_Aura"..i.."Overlay")
+		self["Aura"..i].Count = getglobal(frameName.."_Aura"..i.."Count")
+		self["Aura"..i]:SetScript("OnEnter",function() self:AuraOnEnter() end)
+		self["Aura"..i]:SetScript("OnLeave",function() GameTooltip:Hide() end)
+
+		aUF.hooks.hookShowHide(self["Aura"..i])
+		aUF.hooks.hookSetTexture(self["Aura"..i].Icon)
+
+		self["Aura"..i]:Hide()
+	end
+end
+
+
 function aUF.classes.aUFunit.prototype:UpdateAuras(byevent)
 	if type(byevent) == "string" and byevent ~= self.unit then return end
 	
@@ -964,11 +1002,12 @@
 	local filter,style,AuraDebuffC = self.database.AuraFilter,self.database.AuraStyle,self.database.AuraDebuffC
 	local dbcount,bcount,lastDebuff = 0,0,0
 	local buttons,dFound
+	local rows, cols, auracount = self.AuraRows, self.AuraColumns, self.AuraRows * self.AuraColumns;
 	
 	self.DebuffHighlight:Hide()
 	local hide = style == "Hide"
 	
-	for i=1,20 do
+	for i=1,auracount do
 		if (not self.hidden) then self["Aura"..i]:Hide() end
 		local debuff, _, t = aUF:UnitDebuff(self.unit,i,filter)
 		if debuff then
@@ -995,6 +1034,26 @@
 	
 	local position = self.database.AuraPos
 	
+	if (auracount < bcount + dbcount) then
+		dbcount = auracount - bcount
+	end
+	
+	local buff, count, class, index;
+	
+	for i=1,bcount do
+		buff, count = UnitBuff(self.unit,i,filter)
+		self:SetAura(i, false, i, buff, count, nil)
+	end
+	
+	rows = math.ceil((bcount+dbcount) / cols);
+	
+	for i=1,dbcount do
+		buff, count, class = aUF:UnitDebuff(self.unit,i,filter)
+		index = rows * cols - i + 1
+		self:SetAura(index, true, i, buff, count, class)
+	end
+	
+	--[[
 	if (position == "Above" or position == "Below") and bcount + dbcount <= 10 then
 		buttons = 10
 	elseif style == "OneLine" then
@@ -1058,8 +1117,37 @@
 			b = b + 1
 		end
 	end
+	]]
 end
 
+function aUF.classes.aUFunit.prototype:SetAura(index, isDebuff, id, buff, count, class)
+	local buffFrame = self["Aura" .. index];
+	buffFrame.Icon:SetTexture(buff)
+	buffFrame:Show()
+	buffFrame.id = id
+
+	if count > 1 then
+		buffFrame.Count:SetText(count)
+	else
+		buffFrame.Count:SetText("")
+	end
+
+	if (isDebuff) then
+		buffFrame.buffFilter = "HARMFUL"
+		local borderColor;
+		if class then
+			borderColor = DebuffTypeColor[class]
+		else
+			borderColor = DebuffTypeColor["none"]
+		end
+		buffFrame.Overlay:SetVertexColor(borderColor.r, borderColor.g, borderColor.b)
+	buffFrame.Overlay:Show()
+	else
+		buffFrame.buffFilter = "HELPFUL"
+		buffFrame.Overlay:Hide()
+	end
+end
+
 -- STATUSBAR STUFF
 
 function aUF.classes.aUFunit.prototype:UpdateHealth(byevent)
