--[[         
Name: Prat_Fading
Developed by: Curney of Uther
Inspired by: idChat2_DisableFade by Industrial
Thanks to: Wubin for helping me understand hooking better.
Website: http://wiki.wowace.com/index.php/Prat_Fade
SVN: http://svn.wowace.com/root/trunk/Prat_Fade
Description: Module for Prat that toggles the fading in chat windows on and off (default=off).
Dependencies: Prat
]]

Prat_Fading = Prat:NewModule('fading')

function Prat_Fading:OnInitialize()

    self.db = Prat:AcquireDBNamespace('Fading')

    Prat:RegisterDefaults('Fading', 'profile', {
        on = true,
        normal = true,
        menu = false,
        chatframe = {false, false, false, false, false, false, false}
    })

    Prat.Options.args.fading = {
        name = "Fading",
        desc = "Toggles the fading in chat windows on and off (default=off)",
        type = "group",
        args = {
            toggle = {
                name = "Toggle",
                desc = "Toggle the module on and off",
                type = "toggle",
                get = function() return self.db.profile.on end,
                set = function(v)
                    if v then
                        self:OnEnable()
                    else
                        self:OnDisable()
                    end
                    self.db.profile.on = v
                end
            },
        		chat1 = {
        			 name = "Chat1Fading",
        	    	 type = "toggle",
        	    	 desc = "Toggles fading on and off for chat window 1",
        	    	 get = function() return self.db.profile.chatframe[1] end,
                set = function(v)
                    self.db.profile.chatframe[1] = v
                    self:Fade(1,v)
                end
        		},
        		chat2 = {
        			 name = "Chat2Fading",
        	    	 type = "toggle",
        	    	 desc = "Toggles fading on and off for chat window 2",
        	    	 get = function() return self.db.profile.chatframe[2] end,
                set = function(v)
                    self.db.profile.chatframe[2] = v
                    self:Fade(2,v)
                end
        		},
        		chat3 = {
        			 name = "Chat3Fading",
        	    	 type = "toggle",
        	    	 desc = "Toggles fading on and off for chat window 3",
        	    	 get = function() return self.db.profile.chatframe[3] end,
                set = function(v)
                    self.db.profile.chatframe[3] = v
                    self:Fade(3,v)
                end
        		},
        		chat4 = {
        			 name = "Chat4Fading",
        	    	 type = "toggle",
        	    	 desc = "Toggles fading on and off for chat window 4",
        	    	 get = function() return self.db.profile.chatframe[4] end,
                set = function(v)
                    self.db.profile.chatframe[4] = v
                    self:Fade(4,v)
                end
        		},
        		chat5 = {
        			 name = "Chat5Fading",
        	    	 type = "toggle",
        	    	 desc = "Toggles fading on and off for chat window 5",
        	    	 get = function() return self.db.profile.chatframe[5] end,
                set = function(v)
                    self.db.profile.chatframe[5] = v
                    self:Fade(5,v)
                end
        		},
        		chat6 = {
        			 name = "Chat6Fading",
        	    	 type = "toggle",
        	    	 desc = "Toggles fading on and off for chat window 6",
        	    	 get = function() return self.db.profile.chatframe[6] end,
                set = function(v)
                    self.db.profile.chatframe[6] = v
                    self:Fade(6,v)
                end
        		},
        		chat7 = {
        		    name = "Chat7Fading",
        	    	 type = "toggle",
        	    	 desc = "Toggles fading on and off for chat window 7",
        	    	 get = function() return self.db.profile.chatframe[7] end,
                set = function(v)
                    self.db.profile.chatframe[7] = v
                    self:Fade(7,v)
                end
        		}
        }
    }
end

function Prat_Fading:OnEnable()
    for i=1,7 do
        self:Fade(i,self.db.profile.chatframe[i])
    end
end

function Prat_Fading:OnDisable()
    for i=1,7 do
        self:Fade(i,self.db.profile.normal)
    end
end

function Prat_Fading:Fade(frame,fade)
    if fade then
        getglobal('ChatFrame'..frame):SetFading(1)
    else
        getglobal('ChatFrame'..frame):SetFading(nil)
    end
end
