---------------------------------[ SFSkins v. 1.0 ]------------------------------------
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------

SFSkins = LibStub("AceAddon-3.0"):NewAddon("SFSkins", "AceConsole-3.0", "AceEvent-3.0")

local movethem = false;

StaticPopupDialogs["SFSKINS_RELOADUI"] = {
  text = "You must reload your UI for changes to take effect. Reload UI now?",
  button1 = "Yes",
  button2 = "No",
  OnAccept = function()
    ReloadUI();
  end,
  timeout = 0,
  whileDead = true,
  hideOnEscape = true,
}

-------------------------------------------------------------------------------------
-----------------------------[ Option Panel's Values ]-------------------------------
-------------------------------------------------------------------------------------

local options = {
    name = "SFSkins 1.0",
    handler = SFSkins,
    type = "group",
    args = {
        AddPanel = {
            type = "description",
			name = "\n".."SFSkins v1.0 Description".."\n",
			order = 1,
			cmdHidden = true
        },
	},
}

-------------------------[ Horizontal Bar Option Sets, etc. ]----------------------------

--[ hbar Skin Texture definitions ]--

local SFSkinTextures = { {a = 0.0, b = 1.0, c = 0.9023437, d = 0.9824218},{a = 0.0, b = 1.0, c = 0.8203125, d = 0.9003906},
{a = 0.0, b = 1.0, c = 0.7382812, d = 0.8183593},{a = 0.0, b = 1.0, c = 0.65625, d = 0.7363218},
{a = 0.0, b = 1.0, c = 0.5742187, d = 0.6542968},{a = 0.0, b = 1.0, c = 0.4921875, d = 0.5722656},
{a = 0.0, b = 1.0, c = 0.4101562, d = 0.4902343},{a = 0.0, b = 1.0, c = 0.328125, d = 0.4082031},
{a = 0.0, b = 1.0, c = 0.2460937, d = 0.3261718},{a = 0.0, b = 1.0, c = 0.1640625, d = 0.2441406},
{a = 0.0, b = 1.0, c = 0.0820312, d = 0.1621093},{a = 0.0, b = 1.0, c = 0.0, d = 0.0800781}
};

local HbarDropStart = 1;

local Hbars = {[1] = "Bar 1",[2] = "Bar 2",[3] = "Bar 3",
			  [4] = "Bar 4",[5] = "Bar 5",[6] = "Bar 6",
			  [7] = "Bar 7",[8] = "Bar 8",[9] = "Bar 9",
			  [10] = "Bar 10"};
	
local Horizontal_Bars_Options = {
    name = "Horizontal Bars",
    handler = SFSkins,
    type = "group",
    args = {
        Horizontal = {
            type = "select",
			order = 1,
            name = "Select Horizontal Panel",
            desc = "Select a Bar to Configure",
			values = Hbars ,
            get = "Get_Hbar_Dropdown",
            set = "Set_Hbar_Dropdown",
        },
		visible = {
            type = "toggle",
			order = 2,
            name = "Visible",
            desc = "Toggle the selected bar's visibility. Check to see bar on screen - off to remove from screen",
            get = "Get_Hbar_Visible",
            set = "Set_Hbar_Visible",
        },
		buttons = {
            type = "range",
			order = 3,
			min = 1,
			max = 12,
			step = 1,
            name = "Buttons",
            desc = "You can have up to 12 buttons on one bar. Slide to select the number of buttons for the selected bar",
            get = "Get_Hbar_Buttons",
            set = "Set_Hbar_Buttons",
        },
		scale = {
            type = "range",
			order = 4,
			min = .5,
			max = 1.5,
			step = .01,
			isPercent = true,
            name = "Scale",
            desc = "Reduce or increase the scale of the selected bar",
            get = "Get_Hbar_Scale",
            set = "Set_Hbar_Scale",
        },
		
		Location_Desc = {
			type = "description",
			name = "\n".."|cFFFFFF00X,Y Location|r".."\n",
			fontSize = "medium",
			order = 5,
			cmdHidden = true,			
		},
		
		x = {
			type = "input",
			name = "Horizontal x",
			order = 6,
			width = "half",
			desc = "Horizontal x Position",
			usage = "Set your horizontal position of the bar. Coordinates are from left to right, increasing the number will move the bar to the right",
			get = "Get_Hbar_X",
			set = "Set_Hbar_X",
		},
		y = {
			type = "input",
			name = "Vertical y",
			order = 7,
			width = "half",			
			desc = "Vertical y Position",
			usage = "Set your horizontal position of the bar. Coordinates are from bottom to top, increasing the number will move the bar up",
			get = "Get_Hbar_Y",
			set = "Set_Hbar_Y",
		},	
		move = {
            type = "toggle",
			order = 8,
            name = "Move",
			disabled = false,
            desc = "Toggles on-screen dragging of bars with your mouse off/on",
            get = "Get_Hbar_Move",
            set = "Set_Hbar_Move",
        },
		moreopts = {
			name = "Bar Nudger",
			type = "group",
			inline = true,
			args = {
				Location_Desc = {
					type = "description",
					name = "|cFFFFFF00Usage:|r".."\n\n".." Use the nudger buttons below to move the selected bar in small increments on the screen,".."\n",
					order = 9,
					cmdHidden = true,			
				},
				moverup = {
					type = "execute",
					order = 10,
					name = "<Up>",
					width = "half",
					func = function() SFSkins:MoveUp("HBARS") end,
				},			
				moverdn = {
					type = "execute",
					order = 11,
					name = "<Down>",
					width = "half",
					func = function() SFSkins:MoveDn("HBARS") end,
				},
				moverlt = {
					type = "execute",
					order = 12,
					name = "<Left>",
					width = "half",
					func = function() SFSkins:MoveLt("HBARS") end,
				},
				moverrt = {
					type = "execute",
					order = 13,
					name = "<Right>",
					width = "half",
					func = function() SFSkins:MoveRt("HBARS") end,
				},
				Desc = {
					type = "description",
					name = "\n",
					order = 14,
					cmdHidden = true,			
				},
			},
		},
	},
};

-------------------------[ Vertical Bar Option Sets, etc. ]----------------------------

--[ vbar Configuration Variables ]------------------------------------

local SFSkinVBarTextures = {{a = 0.9121093, b = 0.9921875, c = 0.0, d = 1.0},{a = 0.8300781, b = 0.9082031, c = 0.0, d = 1.0},
{a = 0.7480468, b = 0.8261718, c = 0.0, d = 1.0}, {a = 0.6660156, b = 0.7441406, c = 0.0, d = 1.0},
{a = 0.5839843, b = 0.6621093, c = 0.0, d = 1.0}, {a = 0.5019531, b = 0.5800781, c = 0.0, d = 1.0},
{a = 0.4199218, b = 0.4980468, c = 0.0, d = 1.0}, {a = 0.3378906, b = 0.4160156, c = 0.0, d = 1.0},
{a = 0.2558593, b = 0.3339843, c = 0.0, d = 1.0}, {a = 0.1738281, b = 0.2519531, c = 0.0, d = 1.0},
{a = 0.0917968, b = 0.1699218, c = 0.0, d = 1.0}, {a = 0.0097656, b = 0.0878906, c = 0.0, d = 1.0}, 
};

local VbarDropStart = 1;

local Vbars = {[1] = "Bar 1",[2] = "Bar 2",[3] = "Bar 3",
			  [4] = "Bar 4",[5] = "Bar 5",[6] = "Bar 6",
			  [7] = "Bar 7",[8] = "Bar 8",[9] = "Bar 9",
			  [10] = "Bar 10"};
	
local Vertical_Bars_Options = {
    name = "Vertical Bars",
    handler = SFSkins,
    type = "group",
    args = {
        Horizontal = {
            type = "select",
			order = 1,
            name = "Select Vertical Bar",
            desc = "Select a Bar to Configure",
			values = Hbars ,
            get = "Get_Vbar_Dropdown",
            set = "Set_Vbar_Dropdown",
        },
		visible = {
            type = "toggle",
			order = 2,
            name = "Visible",
            desc = "Toggle the selected bar's visibility. Check to see bar on screen - off to remove from screen",
            get = "Get_Vbar_Visible",
            set = "Set_Vbar_Visible",
        },
		buttons = {
            type = "range",
			order = 3,
			min = 1,
			max = 12,
			step = 1,
            name = "Buttons",
            desc = "You can have up to 12 buttons on one bar. Slide to select the number of buttons for the selected bar",
            get = "Get_Vbar_Buttons",
            set = "Set_Vbar_Buttons",
        },
		scale = {
            type = "range",
			order = 4,
			min = .5,
			max = 1.5,
			step = .01,
			isPercent = true,
            name = "Scale",
            desc = "Reduce or increase the scale of the selected bar",
            get = "Get_Vbar_Scale",
            set = "Set_Vbar_Scale",
        },
		
		Location_Desc = {
			type = "description",
			name = "\n".."|cFFFFFF00X,Y Location|r".."\n",
			order = 5,
			fontSize = "medium",
			cmdHidden = true,			
		},
		
		x = {
			type = "input",
			name = "Horizontal x",
			order = 6,
			width = "half",
			desc = "Horizontal x Position",
			usage = "Set your horizontal position of the bar. Coordinates are from left to right, increasing the number will move the bar to the right",
			get = "Get_Vbar_X",
			set = "Set_Vbar_X",
		},
		y = {
			type = "input",
			name = "Vertical y",
			order = 7,
			width = "half",			
			desc = "Vertical y Position",
			usage = "Set your horizontal position of the bar. Coordinates are from bottom to top, increasing the number will move the bar up",
			get = "Get_Vbar_Y",
			set = "Set_Vbar_Y",
		},	
		move = {
            type = "toggle",
			order = 8,
            name = "Move",
            desc = "Toggles on-screen dragging of all SFSkins graphics with your mouse off/on",
            get = "Get_Vbar_Move",
            set = "Set_Vbar_Move",
        },
		moreopts = {
			name = "Bar Nudger",
			type = "group",
			inline = true,
			args = {
				Location_Desc = {
					type = "description",
					name = "|cFFFFFF00Usage:|r".."\n\n".." Use the nudger buttons below to move the selected bar in small increments on the screen,".."\n",
					order = 9,
					cmdHidden = true,			
				},
				moverup = {
					type = "execute",
					order = 10,
					name = "<Up>",
					width = "half",
					func = function() SFSkins:MoveUp("VBARS") end,
				},			
				moverdn = {
					type = "execute",
					order = 11,
					name = "<Down>",
					width = "half",
					func = function() SFSkins:MoveDn("VBARS") end,
				},
				moverlt = {
					type = "execute",
					order = 12,
					name = "<Left>",
					width = "half",
					func = function() SFSkins:MoveLt("VBARS") end,
				},
				moverrt = {
					type = "execute",
					order = 13,
					name = "<Right>",
					width = "half",
					func = function() SFSkins:MoveRt("VBARS") end,
				},
				Desc = {
					type = "description",
					name = "\n",
					order = 14,
					cmdHidden = true,			
				},
			},
		},
	},
};

-------------------------[ End Caps Option Sets, etc. ]--------------------------

--[ Endcap Configuration Variables ]---------------------------------------------

local SFSkinCapTextures = {
{e = 0.0, f = 0.25, g = 0.0, h = 0.25},{e = 0.25, f = 0.0, g = 0.0, h = 0.25},{e = 0.25, f = 0.5, g = 0.0, h = 0.25},
{e= 0.5, f = 0.25, g = 0.0, h = 0.25},{e = 0.5, f = 0.75, g = 0.0, h = 0.25},{e = 0.75, f = 0.5, g = 0.0, h = 0.25},
{e = 0.75, f = 1.0, g = 0.0, h = 0.25},{e = 1.0, f = 0.75, g = 0.0, h = 0.25},{e = 0.0, f = 0.25, g = 0.25, h = 0.5},
{e = 0.25, f = 0.0, g = 0.25, h = 0.5},{e = 0.25, f = 0.5, g = 0.25, h = 0.5},{e = 0.5, f = 0.25, g = 0.25, h = 0.5},
{e = 0.5, f = 0.75, g = 0.25, h = 0.5},{e = 0.75, f = 0.5, g = 0.25, h = 0.5},{e = 0.75, f = 1.0, g = 0.25, h = 0.5},
{e = 1.0, f = 0.75, g = 0.25, h = 0.5},{e = 0.0, f = 0.25, g = 0.5, h = 0.75},{e = 0.25, f = 0.0, g = 0.5, h = 0.75},
{e = 0.25, f = 0.5, g = 0.5, h = 0.75},{e = 0.5, f = 0.25, g = 0.5, h = 0.75},{e = 0.5, f = 0.75, g = 0.5, h = 0.75},
{e = 0.75, f = 0.5, g = 0.5, h = 0.75},{e = 0.75, f = 1.0, g = 0.5, h = 0.75},{e = 1.0, f = 0.75, g = 0.5, h = 0.75},
{e = 0.0, f = 0.25, g = 0.75, h = 1.0},{e = 0.25, f = 0.0, g = 0.75, h = 1.0},{e = 0.25, f = 0.5, g = 0.75, h = 1.0},
{e = 0.5, f = 0.25, g = 0.75, h = 1.0},{e = 0.5, f = 0.75, g = 0.75, h = 1.0},{e = 0.75, f = 0.5, g = 0.75, h = 1.0},
{e = 0.75, f = 1.0, g = 0.75, h = 1.0},{e = 1.0, f = 0.75, g = 0.75, h = 1.0}
};

local CapDropStart = 1;

local Caps = {[1] = "Cap 1",[2] = "Cap 2",[3] = "Cap 3",
			  [4] = "Cap 4",[5] = "Cap 5",[6] = "Cap 6",
			  [7] = "Cap 7",[8] = "Cap 8",[9] = "Cap 9",
			  [10] = "Cap 10"};
		
local Cap_Options = {
    name = "End Caps",
    handler = SFSkins,
    type = "group",
    args = {
        Caps = {
            type = "select",
			order = 1,
            name = "Select End Cap",
            desc = "Select a End Cap to Configure",
			values = Caps,
            get = "Get_Cap_Dropdown",
            set = "Set_Cap_Dropdown",
        },
		visible = {
            type = "toggle",
			order = 2,
            name = "Visible",
            desc = "Toggle the selected end cap's visibility. Check to see the end cap on the screen - off to remove from screen",
            get = "Get_Cap_Visible",
            set = "Set_Cap_Visible",
        },
		EndCap = {
            type = "range",
			order = 3,
			min = 1,
			max = 32,
			step = 1,
            name = "End Caps",
            desc = "You can select 1 of 32 different end caps to display. Slide to select the end cap to display",
            get = "Get_Cap",
            set = "Set_Cap",
        },
		scale = {
            type = "range",
			order = 4,
			min = .5,
			max = 1.5,
			step = .01,
			isPercent = true,
            name = "Scale",
            desc = "Reduce or increase the scale of the selected end cap",
            get = "Get_Cap_Scale",
            set = "Set_Cap_Scale",
        },
		
		Location_Desc = {
			type = "description",
			name = "\n".."|cFFFFFF00X,Y Location|r".."\n",
			order = 5,
			fontSize = "medium",
			cmdHidden = true,			
		},
		
		x = {
			type = "input",
			name = "Horizontal x",
			order = 6,
			width = "half",
			desc = "Horizontal x Position",
			usage = "Set your horizontal position of the end cap. Coordinates are from left to right, increasing the number will move the end cap to the right",
			get = "Get_Cap_X",
			set = "Set_Cap_X",
		},
		y = {
			type = "input",
			name = "Vertical y",
			order = 7,
			width = "half",			
			desc = "Vertical y Position",
			usage = "Set your vertical position of the end cap. Coordinates are from bottom to top, increasing the number will move the end cap up",
			get = "Get_Cap_Y",
			set = "Set_Cap_Y",
		},	
		move = {
            type = "toggle",
			order = 8,
            name = "Move",
            desc = "Toggles on-screen dragging of all SFSkins graphics with your mouse off/on",
            get = "Get_Cap_Move",
            set = "Set_Cap_Move",
        },
		moreopts = {
			name = "Bar Nudger",
			type = "group",
			inline = true,
			args = {
				Location_Desc = {
					type = "description",
					name = "|cFFFFFF00Usage:|r".."\n\n".." Use the nudger buttons below to move the selected end cap in small increments on the screen,".."\n",
					order = 9,
					cmdHidden = true,			
				},
				moverup = {
					type = "execute",
					order = 10,
					name = "<Up>",
					width = "half",
					func = function() SFSkins:MoveUp("CAPS") end,
				},			
				moverdn = {
					type = "execute",
					order = 11,
					name = "<Down>",
					width = "half",
					func = function() SFSkins:MoveDn("CAPS") end,
				},
				moverlt = {
					type = "execute",
					order = 12,
					name = "<Left>",
					width = "half",
					func = function() SFSkins:MoveLt("CAPS") end,
				},
				moverrt = {
					type = "execute",
					order = 13,
					name = "<Right>",
					width = "half",
					func = function() SFSkins:MoveRt("CAPS") end,
				},
				Desc = {
					type = "description",
					name = "\n",
					order = 14,
					cmdHidden = true,			
				},
			},
		},
	},
}

-------------------------[ Bits Option Sets, etc. ]--------------------------

--[ Bits Configuration Variables ]---------------------------------------------

 local SFSkinBitTextures = {
{e = 0.0, f = 0.25, g = 0.0, h = 0.25},{e = 0.25, f = 0.0, g = 0.0, h = 0.25},{e = 0.25, f = 0.5, g = 0.0, h = 0.25},
{e= 0.5, f = 0.25, g = 0.0, h = 0.25},{e = 0.5, f = 0.75, g = 0.0, h = 0.25},{e = 0.75, f = 0.5, g = 0.0, h = 0.25},
{e = 0.75, f = 1.0, g = 0.0, h = 0.25},{e = 1.0, f = 0.75, g = 0.0, h = 0.25},{e = 0.0, f = 0.25, g = 0.25, h = 0.5},
{e = 0.25, f = 0.0, g = 0.25, h = 0.5},{e = 0.25, f = 0.5, g = 0.25, h = 0.5},{e = 0.25, f = 0.5, g = 0.5, h = 0.25},
{e = 0.5, f = 0.75, g = 0.25, h = 0.5},{e = 0.75, f = 0.5, g = 0.25, h = 0.5},{e = 0.75, f = 0.5, g = 0.5, h = 0.25},
{e = 0.5, f = 0.75, g = 0.5, h = 0.25},{e = 0.75, f = 1.0, g = 0.25, h = 0.5},{e = 1.0, f = 0.75, g = 0.25, h = 0.5},
{e = 1.0, f = 0.75, g = 0.5, h = 0.25},{e = 0.75, f = 1.0, g = 0.5, h = 0.25},{e = 0.0, f = 0.25, g = 0.5, h = 0.75},
{e = 0.25, f = 0.5, g = 0.5, h = 0.75},{e = 0.5, f = 0.75, g = 0.5, h = 0.75},{e= 0.75, f = 1.0, g = 0.5, h = 0.75},
{e = 0.0, f = 0.25, g = 0.75, h = 1.0},{e = 0.25, f = 0.0, g = 0.75, h = 1.0},{e = 0.25, f = 0.5, g = 0.75, h = 1.0},
{e = 0.5, f = 0.25, g = 0.75, h = 1.0},{e = 0.5, f = 0.75, g = 0.75, h = 1.0},{e = 0.75, f = 1.0, g = 0.75, h = 1.0},
};

local BitDropStart = 1;

local Bits = {[1] = "Misc Bit 1",[2] = "Misc Bit 2",[3] = "Misc Bit 3",
			  [4] = "Misc Bit 4",[5] = "Misc Bit 5",[6] = "Misc Bit 6",
			  [7] = "Misc Bit 7",[8] = "Misc Bit 8",[9] = "Misc Bit 9",
			  [10] = "Misc Bit 10"};
	

	
local Bit_Options = {
    name = "Misc Bits",
    handler = SFSkins,
    type = "group",
    args = {
        Bits = {
            type = "select",
			order = 1,
            name = "Select Misc Bit",
            desc = "Select a Misc Bit to Configure",
			values = Bits,
            get = "Get_Bit_Dropdown",
            set = "Set_Bit_Dropdown",
        },
		visible = {
            type = "toggle",
			order = 2,
            name = "Visible",
            desc = "Toggle the selected misc bit's visibility. Check to see the misc bit on the screen - off to remove from screen",
            get = "Get_Bit_Visible",
            set = "Set_Bit_Visible",
        },
		MiscBit = {
            type = "range",
			order = 3,
			min = 1,
			max = 30,
			step = 1,
            name = "Misc Bits",
            desc = "You can select 1 of 32 different misc bits to display. Slide to select the misc bit to display",
            get = "Get_Bit",
            set = "Set_Bit",
        },
		scale = {
            type = "range",
			order = 4,
			min = .5,
			max = 1.5,
			step = .01,
			isPercent = true,
            name = "Scale",
            desc = "Reduce or increase the scale of the selected misc bit",
            get = "Get_Bit_Scale",
            set = "Set_Bit_Scale",
        },
		
		Location_Desc = {
			type = "description",
			name = "\n".."|cFFFFFF00X,Y Location|r".."\n",
			order = 5,
			fontSize = "medium",
			cmdHidden = true,			
		},
		
		x = {
			type = "input",
			name = "Horizontal x",
			order = 6,
			width = "half",
			desc = "Horizontal x Position",
			usage = "Set your horizontal position of the misc bit. Coordinates are from left to right, increasing the number will move the misc bit to the right",
			get = "Get_Bit_X",
			set = "Set_Bit_X",
		},
		y = {
			type = "input",
			name = "Vertical y",
			order = 7,
			width = "half",			
			desc = "Vertical y Position",
			usage = "Set your vertical position of the misc bit. Coordinates are from bottom to top, increasing the number will move the misc bit up",
			get = "Get_Bit_Y",
			set = "Set_Bit_Y",
		},	
		move = {
            type = "toggle",
			order = 8,
            name = "Move",
            desc = "Toggles on-screen dragging of all SFSkins graphics with your mouse off/on",
            get = "Get_Bit_Move",
            set = "Set_Bit_Move",
        },
		moreopts = {
			name = "Bar Nudger",
			type = "group",
			inline = true,
			args = {
				Location_Desc = {
					type = "description",
					name = "|cFFFFFF00Usage:|r".."\n\n".." Use the nudger buttons below to move the selected misc bit in small increments on the screen,".."\n",
					order = 9,
					cmdHidden = true,			
				},
				moverup = {
					type = "execute",
					order = 10,
					name = "<Up>",
					width = "half",
					func = function() SFSkins:MoveUp("BITS") end,
				},			
				moverdn = {
					type = "execute",
					order = 11,
					name = "<Down>",
					width = "half",
					func = function() SFSkins:MoveDn("BITS") end,
				},
				moverlt = {
					type = "execute",
					order = 12,
					name = "<Left>",
					width = "half",
					func = function() SFSkins:MoveLt("BITS") end,
				},
				moverrt = {
					type = "execute",
					order = 13,
					name = "<Right>",
					width = "half",
					func = function() SFSkins:MoveRt("BITS") end,
				},
				Desc = {
					type = "description",
					name = "\n",
					order = 14,
					cmdHidden = true,			
				},
			},
		},
	},
};

-------------------------------------------------------------------------------------
------------------------------[ Default Panel Values ]-------------------------------
-------------------------------------------------------------------------------------

local defaultPanelOptions = {
	parent = "UIParent",
	relativepoint = "BOTTOMLEFT",
	point = "BOTTOMLEFT",
	buttons = 1,
	scale = 1,
	x = 300,
	y = 100,
	level = 0,
	strata = "BACKGROUND",
	visible = false,
};
	
-------------------------------------------------------------------------------------
-----------------------------[ ACE3 Profile Defaults ]-------------------------------
-------------------------------------------------------------------------------------
	
local dbDefaults = {
	profile = {
		AddPanel = "",
		defaultPanel = defaultPanelOptions,
		Hbars = { 	{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },

				},
		Vbars = { 	{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },

				},	

		Caps = { 	{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
			  },

		Bits = { 	{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
					{
					options = defaultPanelOptions,
				  },
				  
				},	
				
	},
}

-------------------------------------------------------------------------------------
-----------------------------[ Misc Functions ]--------------------------------------
-------------------------------------------------------------------------------------

function NameStartsWith(String,Start)
   return string.sub(String,1,string.len(Start))
end

local function round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

local function DeepCopy(t, lookup_table)
	local copy = {}
	if type(t) ~= "table" then return t end
	for i,v in pairs(t) do
		if type(v) ~= "table" then
			copy[i] = v
		else
			lookup_table = lookup_table or {}
			lookup_table[t] = copy
			if lookup_table[v] then
				copy[i] = lookup_table[v] -- we already copied this table. reuse the copy.
			else
				copy[i] = DeepCopy(v,lookup_table) -- not yet copied. copy it.
			end
		end
	end
	return copy
end

-------------------------------------------------------------------------------------
-------------------------[ Initial Addon Control & Setup ]---------------------------
-------------------------------------------------------------------------------------

local ProfileOptions = DeepCopy(options)

function SFSkins:OnInitialize()
	self.db = LibStub("AceDB-3.0"):New("SFSkinsDB", dbDefaults)
    
	ProfileOptions.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
	
	--[ Root Menu "SFSkins" ]--
	LibStub("AceConfig-3.0"):RegisterOptionsTable("SFSkins 1.0", options)
	self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("SFSkins 1.0", "SFSkins 1.0")
	
	--[ Sub Menu "Horizontal Bars" ]-- 
	LibStub("AceConfig-3.0"):RegisterOptionsTable("Horizontal Bars", Horizontal_Bars_Options)
 	LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Horizontal Bars", "Horizontal Bars","SFSkins 1.0")

	--[ Sub Menu "Vertical Bars" ]-- 
	LibStub("AceConfig-3.0"):RegisterOptionsTable("Vertical Bars", Vertical_Bars_Options)
 	LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Vertical Bars", "Vertical Bars","SFSkins 1.0")

	--[ Sub Menu "End Caps" ]-- 
	LibStub("AceConfig-3.0"):RegisterOptionsTable("End Caps", Cap_Options)
 	LibStub("AceConfigDialog-3.0"):AddToBlizOptions("End Caps", "End Caps","SFSkins 1.0")

	--[ Sub Menu "Bits" ]-- 
	LibStub("AceConfig-3.0"):RegisterOptionsTable("Misc Bits", Bit_Options)
 	LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Misc Bits", "Misc Bits","SFSkins 1.0")
	
	--[ Sub Menu "Profile" ]-- 	
	LibStub("AceConfig-3.0"):RegisterOptionsTable("SFSkins Profiles", ProfileOptions.args.profile)	
	LibStub("AceConfigDialog-3.0"):AddToBlizOptions("SFSkins Profiles", "Profile","SFSkins 1.0")
	
	--[ Profile Callback Handlers ]--
	self.db.RegisterCallback(self, "OnProfileChanged", "RefreshProfile")
	self.db.RegisterCallback(self, "OnProfileCopied", "RefreshProfile")
	self.db.RegisterCallback(self, "OnProfileReset", "RefreshProfile")
	
	--[ Slash Command Handler ]--
	self:RegisterChatCommand("sfs", "ChatCommand")
    self:RegisterChatCommand("sfskins", "ChatCommand")	
	
end

--------------------------------------------------------------
---------------[ Frame Movement Functions ]-------------------
--------------------------------------------------------------

function SFSkins:FrameLocation(f)

local Type = ""

	if (NameStartsWith(f:GetName(),1) == "h") then
		Type = "HBAR"
	elseif (NameStartsWith(f:GetName(),1) =="v") then
		Type = "VBAR"
	elseif (NameStartsWith(f:GetName(),1) =="C") then
		Type = "CAPS"		
	elseif (NameStartsWith(f:GetName(),1) == "B") then
		Type = "BITS"			
	end

	if (Type == "HBAR") then
		registryname = "Horizontal Bars"
		bartype = self.db.profile.Hbars[f:GetID()].options
	elseif (Type == "VBAR") then
		registryname = "Vertical Bars"
		bartype = self.db.profile.Vbars[f:GetID()].options
	elseif  (Type == "CAPS") then
		registryname = "End Caps"
		bartype = self.db.profile.Caps[f:GetID()].options
	elseif (Type == "BITS") then
		registryname = "Misc Bits"
		bartype = self.db.profile.Bits[f:GetID()].options
	end
	
	bartype.x =round(_G[f:GetName()]:GetLeft(),2)
	bartype.y = round(_G[f:GetName()]:GetBottom(),2)
	
	LibStub("AceConfigRegistry-3.0"):NotifyChange(registryname)	
end

function SFSkins:FrameIdentifier(Type)
local AllTables = {}

	for k,v in pairs(self.db.profile.Hbars) do
		if (v.options.visible == true) then
			tinsert(AllTables,_G["hBarFrame"..k])
		end
	end
	
	for k,v in pairs(self.db.profile.Vbars) do
		if (v.options.visible == true) then
			tinsert(AllTables,_G["vBarFrame"..k])
		end
	end	

	for k,v in pairs(self.db.profile.Caps) do
		if (v.options.visible == true) then
			tinsert(AllTables,_G["CapFrame"..k])
		end
	end		

	for k,v in pairs(self.db.profile.Bits) do
		if (v.options.visible == true) then
			tinsert(AllTables,_G["BitFrame"..k])
		end
	end	
	
	return AllTables
end

function SFSkins:SetMoveFrames(tables, onoff)

	if onoff == "ON" then		
		for k,v in pairs(tables) do

			v:SetMovable(true)
			v:EnableMouse(true)
			
			v:SetScript("OnMouseDown", function(self)  self:StartMoving(); end)
			v:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing();  SFSkins:FrameLocation(self); end)	
			
			tex = _G[v:GetName().."_MoveTexture"]
			tex:SetAlpha(0.3);

			if (NameStartsWith(v:GetName(),1) == "h") then
				Type = "HBAR"
			elseif (NameStartsWith(v:GetName(),1) =="v") then
				Type = "VBAR"
			elseif (NameStartsWith(v:GetName(),1) =="C") then
				Type = "CAPS"		
			elseif (NameStartsWith(v:GetName(),1) == "B") then
				Type = "BITS"			
			end

			if (Type == "HBAR") then
					barName =  _G[v:GetName().."_MoveBarNum"]
					barName:SetText( "hBar "..v:GetID())	
				elseif (Type == "VBAR") then
					barName =  _G[v:GetName().."_MoveBarNum"]
					barName:SetText( "vBar "..v:GetID())	
				elseif  (Type == "CAPS") then
					barName =  _G[v:GetName().."_MoveBarNum"]
					barName:SetText( "Cap "..v:GetID())	
				elseif (Type == "BITS") then
					barName =  _G[v:GetName().."_MoveBarNum"]
					barName:SetText( "Bit "..v:GetID())	
			end

		end
	else
		for k,v in pairs(tables) do

			v:SetMovable(false)
			v:EnableMouse(false)
			
			v:SetScript("OnMouseDown", function(self) end)
			v:SetScript("OnMouseUp", function(self) end)	
		
			tex = _G[v:GetName().."_MoveTexture"]
			tex:SetAlpha(0.0);	

			barName =  _G[v:GetName().."_MoveBarNum"]
			barName:SetText("")
		end
	end
end

----------------------------------------------------------------------------
----------------------[ Create & Update Frames ]----------------------------
----------------------------------------------------------------------------

function SFSkins:CreateFrame(hbar,type, num)
	local f
	if (type == "HBAR") then
		f = CreateFrame("Frame","hBarFrame"..num,UIParent)	
		f:SetFrameStrata("BACKGROUND")
		
		f:SetWidth(512) -- Set these to whatever height/width is needed 
		f:SetHeight(41) -- for your Texture
		f:SetScale(hbar.scale)
		local var = SFSkinTextures[hbar.buttons]
		local t = f:CreateTexture(nil,"BACKGROUND")
		t:SetTexture("Interface\\AddOns\\SFSkins\\Graphics\\SFSkins_00")
		t:SetTexCoord(var.a, var.b,var.c,var.d)

		t:SetAllPoints(f)
		f.texture = t
		
		local tex = f:CreateTexture(f:GetName().."_MoveTexture","ARTWORK");
		tex:SetAllPoints();
					
		BarNum = f:CreateFontString(f:GetName().."_MoveBarNum", "OVERLAY")
	
		BarNum:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
		BarNum:SetPoint("CENTER")
	
		BarNum:SetText("")
		
		if movethem then
			f:SetMovable(true)
			f:EnableMouse(true)	
			tex:SetTexture(1.0, 1.0, 1.0); tex:SetAlpha(0.3);	
			f:SetScript("OnMouseDown", function(self)  self:StartMoving(); end)
			f:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing();  SFSkins:FrameLocation(self,"HBAR"); end)
			BarNum:SetText( "hBar"..num)
		else
			f:SetMovable(false)
			f:EnableMouse(false)	
			tex:SetTexture(1.0, 1.0, 1.0); tex:SetAlpha(0.0);	
			f:SetScript("OnMouseDown", function(self) end)
			f:SetScript("OnMouseUp", function(self) end)
		
		end
		
		f:SetPoint("BOTTOMLEFT",UIParent,"BOTTOMLEFT",hbar.x,hbar.y) --[Change this for all types of frames VBsr, etc.
		if hbar.visible then		
			f:Show()
		else 
			f:Hide()
		end
		
	end
	
	if (type == "VBAR") then
		f = CreateFrame("Frame","vBarFrame"..num,UIParent)
		f:SetFrameStrata("BACKGROUND")
		f:SetWidth(43) -- Set these to whatever height/width is needed 
		f:SetHeight(512) -- for your Texture
		f:SetScale(hbar.scale)
		local var = SFSkinVBarTextures[hbar.buttons]
		local t = f:CreateTexture(nil,"BACKGROUND")
		t:SetTexture("Interface\\AddOns\\SFSkins\\Graphics\\SFSkins_00")
		t:SetTexCoord(var.a, var.b,var.c,var.d)

		t:SetAllPoints(f)
		f.texture = t
		
		local tex = f:CreateTexture(f:GetName().."_MoveTexture","ARTWORK");
		tex:SetAllPoints();
		
		BarNum = f:CreateFontString(f:GetName().."_MoveBarNum", "OVERLAY")
	
		BarNum:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
		BarNum:SetPoint("CENTER")
	
		BarNum:SetText( "")
		
		if movethem then
			f:SetMovable(true)
			f:EnableMouse(true)	
			tex:SetTexture(1.0, 1.0, 1.0); tex:SetAlpha(0.3);	
			f:SetScript("OnMouseDown", function(self)  self:StartMoving(); end)
			f:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing();  SFSkins:FrameLocation(self,"VBAR"); end)
			BarNum:SetText( "vBar"..num)
		else
			f:SetMovable(false)
			f:EnableMouse(false)	
			tex:SetTexture(1.0, 1.0, 1.0); tex:SetAlpha(0.0);	
			f:SetScript("OnMouseDown", function(self) end)
			f:SetScript("OnMouseUp", function(self) end)	
			BarNum:SetText("")	
		end		
		
		f:SetPoint("BOTTOMLEFT",UIParent,"BOTTOMLEFT",hbar.x,hbar.y)
		
		if hbar.visible then		
			f:Show()
		else 
			f:Hide()
		end
	end

	if (type == "CAPS") then
		f = CreateFrame("Frame","CapFrame"..num,UIParent)
		f:SetFrameStrata("BACKGROUND")
		f:SetWidth(128) -- Set these to whatever height/width is needed 
		f:SetHeight(128) -- for your Texture
		f:SetScale(hbar.scale)
		var = SFSkinCapTextures[hbar.buttons]
		local t = f:CreateTexture(nil,"BACKGROUND")
		t:SetTexture("Interface\\AddOns\\SFSkins\\Graphics\\SFSkins_01")
		t:SetTexCoord(var.e, var.f,var.g,var.h)

		t:SetAllPoints(f)
		f.texture = t
		
		local tex = f:CreateTexture(f:GetName().."_MoveTexture","ARTWORK");
		tex:SetAllPoints();	
		
		BarNum = f:CreateFontString(f:GetName().."_MoveBarNum", "OVERLAY")
	
		BarNum:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
		BarNum:SetPoint("CENTER")
	
		BarNum:SetText( "")
		
		if movethem then
			f:SetMovable(true)
			f:EnableMouse(true)	
			tex:SetTexture(1.0, 1.0, 1.0); tex:SetAlpha(0.3);	
			f:SetScript("OnMouseDown", function(self)  self:StartMoving(); end)
			f:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing();  SFSkins:FrameLocation(self,"CAPS"); end)
			BarNum:SetText( "Cap "..num)
		else
			f:SetMovable(false)
			f:EnableMouse(false)	
			tex:SetTexture(1.0, 1.0, 1.0); tex:SetAlpha(0.0);	
			f:SetScript("OnMouseDown", function(self) end)
			f:SetScript("OnMouseUp", function(self) end)
			BarNum:SetText("")	
		end
		
		f:SetPoint("BOTTOMLEFT",UIParent,"BOTTOMLEFT",hbar.x,hbar.y)
		
		if hbar.visible then		
			f:Show()
		else 
			f:Hide()
		end
	end

   if (type == "BITS") then
		f = CreateFrame("Frame","BitFrame"..num,UIParent)
		f:SetFrameStrata("BACKGROUND")
		f:SetWidth(128) -- Set these to whatever height/width is needed 
		f:SetHeight(128) -- for your Texture
		f:SetScale(hbar.scale)
		var = SFSkinBitTextures[hbar.buttons]
		local t = f:CreateTexture(nil,"BACKGROUND")
		t:SetTexture("Interface\\AddOns\\SFSkins\\Graphics\\SFSkins_02")
		t:SetTexCoord(var.e, var.f,var.g,var.h)

		t:SetAllPoints(f)
		f.texture = t

		local tex = f:CreateTexture(f:GetName().."_MoveTexture","ARTWORK");
		tex:SetAllPoints();
		
		BarNum = f:CreateFontString(f:GetName().."_MoveBarNum", "OVERLAY")
	
		BarNum:SetFont("Fonts\\FRIZQT__.TTF", 10, nil)
		BarNum:SetPoint("CENTER")
	
		BarNum:SetText( "")

		if movethem then
			f:SetMovable(true)
			f:EnableMouse(true)	
			tex:SetTexture(1.0, 1.0, 1.0); tex:SetAlpha(0.3);	
			f:SetScript("OnMouseDown", function(self)  self:StartMoving(); end)
			f:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing();  SFSkins:FrameLocation(self,"BITS"); end)
			BarNum:SetText("Bit "..num)
			else
			f:SetMovable(false)
			f:EnableMouse(false)	
			tex:SetTexture(1.0, 1.0, 1.0); tex:SetAlpha(0.0);	
			f:SetScript("OnMouseDown", function(self) end)
			f:SetScript("OnMouseUp", function(self) end)
			BarNum:SetText("")
		end
		
		f:SetPoint("BOTTOMLEFT",UIParent,"BOTTOMLEFT",hbar.x,hbar.y)
		
		if hbar.visible then		
			f:Show()
		else 
			f:Hide()
		end
	end
	
	return f
end

function SFSkins:UpdateFrame(hbar,type)
	local exist = true
	local frame = {}
	--[ Horizontal Bar ]--
	
	if (type == "HBAR") then
		if (_G["hBarFrame"..HbarDropStart] == nil) then
			exist = false
		end
		
		if exist then
			if hbar.visible == true then
				local var = SFSkinTextures[hbar.buttons]
				local framehold  = _G["hBarFrame"..HbarDropStart]
				framehold:SetPoint("BOTTOMLEFT",UIParent,"BOTTOMLEFT",hbar.x,hbar.y)
				framehold.texture:SetTexCoord(var.a, var.b,var.c,var.d)
				framehold:SetScale(hbar.scale)
				if framehold:IsShown() then
				else
					framehold:Show()
				end
			else
				local framehold  = _G["hBarFrame"..HbarDropStart]
				framehold:Hide()
			end
		else		
			frame = SFSkins:CreateFrame(hbar,type,HbarDropStart)
			frame:SetID(HbarDropStart)
		end
	end
	
	--[ Vertical Bar ]--
	
	if (type == "VBAR") then
		if (_G["vBarFrame"..VbarDropStart] == nil) then
			exist = false
		end
		
		if exist then
			if hbar.visible == true then
				local var = SFSkinVBarTextures[hbar.buttons]
				local framehold  = _G["vBarFrame"..VbarDropStart]
				framehold:SetPoint("BOTTOMLEFT",UIParent,"BOTTOMLEFT",hbar.x,hbar.y)
				framehold.texture:SetTexCoord(var.a, var.b,var.c,var.d)
				framehold:SetScale(hbar.scale)
				if framehold:IsShown() then
				else
					framehold:Show()
				end
			else
				local framehold  = _G["vBarFrame"..VbarDropStart]
				framehold:Hide()
			end
		else
			frame = SFSkins:CreateFrame(hbar,type,VbarDropStart)
			frame:SetID(VbarDropStart)
		end
	end
	
--[ End Caps ]--
	
	if (type == "CAPS") then
		if (_G["CapFrame"..CapDropStart] == nil) then
			exist = false
		end
		
		if exist then
			if hbar.visible == true then
				local var = SFSkinCapTextures[hbar.buttons]
				local framehold  = _G["CapFrame"..CapDropStart]
				framehold:SetPoint("BOTTOMLEFT",UIParent,"BOTTOMLEFT",hbar.x,hbar.y)
				framehold.texture:SetTexCoord(var.e, var.f,var.g,var.h)
				framehold:SetScale(hbar.scale)
				if framehold:IsShown() then
				else
					framehold:Show()
				end
			else
				local framehold  = _G["CapFrame"..CapDropStart]
				framehold:Hide()
			end
		else
			frame = SFSkins:CreateFrame(hbar,type,CapDropStart)
			frame:SetID(CapDropStart)
		end
	end
	
--[ Misc Bits ]--

	if (type == "BITS") then
		if (_G["BitFrame"..BitDropStart] == nil) then
			exist = false
		end
		
		if exist then
			if hbar.visible == true then
				local var = SFSkinBitTextures[hbar.buttons]
				local framehold  = _G["BitFrame"..BitDropStart]
				framehold:SetPoint("BOTTOMLEFT",UIParent,"BOTTOMLEFT",hbar.x,hbar.y)
				framehold.texture:SetTexCoord(var.e, var.f,var.g,var.h)
				framehold:SetScale(hbar.scale)
				if framehold:IsShown() then
				else
					framehold:Show()
				end
			else
				local framehold  = _G["BitFrame"..BitDropStart]
				framehold:Hide()
			end
		else
			frame = SFSkins:CreateFrame(hbar,type,BitDropStart)
			frame:SetID(BitDropStart)
		end
	end	
end



function SFSkins:OnEnable()
--[Set up Horizontal Bars ]--
	for k,v in pairs(self.db.profile.Hbars) do
		if (v.options.visible == true) then
			newFrame = SFSkins:CreateFrame(v.options,"HBAR",k)
			newFrame:SetID(k)
		end
	end
	
	--[Set up Vertical Bars ]--
	for k,v in pairs(self.db.profile.Vbars) do
		if (v.options.visible == true) then
			newFrame = SFSkins:CreateFrame(v.options,"VBAR",k)
			newFrame:SetID(k)
		end
	end
	
	--[Set up End Caps ]--
	for k,v in pairs(self.db.profile.Caps) do
		
		if (v.options.visible == true) then
			newFrame = SFSkins:CreateFrame(v.options,"CAPS",k)
			newFrame:SetID(k)
		end
	end

	--[Set up Misc Bits ]--
	for k,v in pairs(self.db.profile.Bits) do
		
		if (v.options.visible == true) then
			newFrame = SFSkins:CreateFrame(v.options,"BITS",k)
			newFrame:SetID(k)
		end
	end
end

function SFSkins:ChatCommand(input)
    if not input or input:trim() == "" then
        InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
    else
        LibStub("AceConfigCmd-3.0").HandleCommand(SFSkins, "sfs", "sfskins", input)
    end
end

function SFSkins:RefreshProfile()
StaticPopup_Show ("SFSKINS_RELOADUI")
Movethem = false

end

------------------[ Added for Nudger ]--------------

function SFSkins:MoveUp(Type)
	if (Type == "HBARS") then
		if (self.db.profile.Hbars[HbarDropStart].options.visible) then
			self.db.profile.Hbars[HbarDropStart].options.y = self.db.profile.Hbars[HbarDropStart].options.y +  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Horizontal Bars")
			SFSkins:UpdateFrame(self.db.profile.Hbars[HbarDropStart].options,"HBAR")
		end
	elseif (Type == "VBARS") then
		if (self.db.profile.Vbars[VbarDropStart].options.visible) then
			self.db.profile.Vbars[VbarDropStart].options.y = self.db.profile.Vbars[VbarDropStart].options.y +  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Vertical Bars")
		SFSkins:UpdateFrame(self.db.profile.Vbars[VbarDropStart].options,"VBAR")
		end
	elseif (Type == "CAPS") then
		if (self.db.profile.Caps[CapDropStart].options.visible) then
			self.db.profile.Caps[CapDropStart].options.y = self.db.profile.Caps[CapDropStart].options.y +  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("End Caps")
			SFSkins:UpdateFrame(self.db.profile.Caps[CapDropStart].options,"CAPS")
		end
	elseif (Type == "BITS") then
		if (self.db.profile.Bits[BitDropStart].options.visible) then
			self.db.profile.Bits[BitDropStart].options.y = self.db.profile.Bits[BitDropStart].options.y +  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Misc Bits")
			SFSkins:UpdateFrame(self.db.profile.Bits[BitDropStart].options,"BITS")
		end
	end
end

function SFSkins:MoveDn(Type)
	if (Type == "HBARS") then
		if (self.db.profile.Hbars[HbarDropStart].options.visible) then
			self.db.profile.Hbars[HbarDropStart].options.y = self.db.profile.Hbars[HbarDropStart].options.y -  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Horizontal Bars")
			SFSkins:UpdateFrame(self.db.profile.Hbars[HbarDropStart].options,"HBAR")
		end
	elseif (Type == "VBARS") then
		if (self.db.profile.Vbars[VbarDropStart].options.visible) then
			self.db.profile.Vbars[VbarDropStart].options.y = self.db.profile.Vbars[VbarDropStart].options.y -  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Vertical Bars")
			SFSkins:UpdateFrame(self.db.profile.Vbars[VbarDropStart].options,"VBAR")
		end	
	elseif (Type == "CAPS") then
		if (self.db.profile.Caps[CapDropStart].options.visible) then
			self.db.profile.Caps[CapDropStart].options.y = self.db.profile.Caps[CapDropStart].options.y -  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("End Caps")
			SFSkins:UpdateFrame(self.db.profile.Caps[CapDropStart].options,"CAPS")
		end
	elseif (Type == "BITS") then
		if (self.db.profile.Bits[BitDropStart].options.visible) then
			self.db.profile.Bits[BitDropStart].options.y = self.db.profile.Bits[BitDropStart].options.y -  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Misc Bits")
			SFSkins:UpdateFrame(self.db.profile.Bits[BitDropStart].options,"BITS")
		end
	end
end

function SFSkins:MoveRt(Type)
	if (Type == "HBARS") then
		if (self.db.profile.Hbars[HbarDropStart].options.visible) then
			self.db.profile.Hbars[HbarDropStart].options.x = self.db.profile.Hbars[HbarDropStart].options.x +  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Horizontal Bars")
			SFSkins:UpdateFrame(self.db.profile.Hbars[HbarDropStart].options,"HBAR")
		end
	elseif (Type == "VBARS") then
		if (self.db.profile.Vbars[VbarDropStart].options.visible) then
			self.db.profile.Vbars[VbarDropStart].options.x = self.db.profile.Vbars[VbarDropStart].options.x +  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Vertical Bars")
			SFSkins:UpdateFrame(self.db.profile.Vbars[VbarDropStart].options,"VBAR")
		end	
	elseif (Type == "CAPS") then
		if (self.db.profile.Caps[CapDropStart].options.visible) then
			self.db.profile.Caps[CapDropStart].options.x = self.db.profile.Caps[CapDropStart].options.x +  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("End Caps")
			SFSkins:UpdateFrame(self.db.profile.Caps[CapDropStart].options,"CAPS")
		end	
	elseif (Type == "BITS") then
		if (self.db.profile.Bits[BitDropStart].options.visible) then
			self.db.profile.Bits[BitDropStart].options.x = self.db.profile.Bits[BitDropStart].options.x +  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Misc Bits")
			SFSkins:UpdateFrame(self.db.profile.Bits[BitDropStart].options,"BITS")
		end	
	end
end

function SFSkins:MoveLt(Type)
	if (Type == "HBARS") then
		if (self.db.profile.Hbars[HbarDropStart].options.visible) then
			self.db.profile.Hbars[HbarDropStart].options.x = self.db.profile.Hbars[HbarDropStart].options.x - 1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Horizontal Bars")
			SFSkins:UpdateFrame(self.db.profile.Hbars[HbarDropStart].options,"HBAR")
		end
	elseif (Type == "VBARS") then
		if (self.db.profile.Vbars[VbarDropStart].options.visible) then
			self.db.profile.Vbars[VbarDropStart].options.x = self.db.profile.Vbars[VbarDropStart].options.x - 1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Vertical Bars")
			SFSkins:UpdateFrame(self.db.profile.Vbars[VbarDropStart].options,"VBAR")
		end	
	elseif (Type == "CAPS") then
		if (self.db.profile.Caps[CapDropStart].options.visible) then
			self.db.profile.Caps[CapDropStart].options.x = self.db.profile.Caps[CapDropStart].options.x -  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("End Caps")
			SFSkins:UpdateFrame(self.db.profile.Caps[CapDropStart].options,"CAPS")
		end
	elseif (Type == "BITS") then
		if (self.db.profile.Bits[BitDropStart].options.visible) then
			self.db.profile.Bits[BitDropStart].options.x = self.db.profile.Bits[BitDropStart].options.x -  1
			LibStub("AceConfigRegistry-3.0"):NotifyChange("Misc Bits")
			SFSkins:UpdateFrame(self.db.profile.Bits[BitDropStart].options,"BITS")
		end
	end
end
------------------------------------------------


-------------------------------------------------------------------------------------
---------------[ Horizontal Bar Option Table Control Functions ]---------------------
-------------------------------------------------------------------------------------


function SFSkins:Set_Hbar_Dropdown(info, Value)
	HbarDropStart = Value
end

function SFSkins:Get_Hbar_Dropdown(info)
	return HbarDropStart
end

function SFSkins:Set_Hbar_Visible(info, Value)
	self.db.profile.Hbars[HbarDropStart].options.visible = Value
	SFSkins:UpdateFrame(self.db.profile.Hbars[HbarDropStart].options,"HBAR")
end

function SFSkins:Get_Hbar_Visible(info)
	return self.db.profile.Hbars[HbarDropStart].options.visible
end

function SFSkins:Set_Hbar_Buttons(info, Value)
	self.db.profile.Hbars[HbarDropStart].options.buttons = Value
	SFSkins:UpdateFrame(self.db.profile.Hbars[HbarDropStart].options,"HBAR")
end

function SFSkins:Get_Hbar_Buttons(info)
	return self.db.profile.Hbars[HbarDropStart].options.buttons
end

function SFSkins:Set_Hbar_Scale(info, Value)
	self.db.profile.Hbars[HbarDropStart].options.scale = Value
	SFSkins:UpdateFrame(self.db.profile.Hbars[HbarDropStart].options,"HBAR")
end

function SFSkins:Get_Hbar_Scale(info)
	return self.db.profile.Hbars[HbarDropStart].options.scale
end

function SFSkins:Set_Hbar_X(info, Value)
	self.db.profile.Hbars[HbarDropStart].options.x = tonumber(Value)
	SFSkins:UpdateFrame(self.db.profile.Hbars[HbarDropStart].options,"HBAR")
end

function SFSkins:Get_Hbar_X(info)
	return tostring(self.db.profile.Hbars[HbarDropStart].options.x)
end

function SFSkins:Set_Hbar_Y(info, Value)
	self.db.profile.Hbars[HbarDropStart].options.y = tonumber(Value)
	SFSkins:UpdateFrame(self.db.profile.Hbars[HbarDropStart].options,"HBAR")
end

function SFSkins:Get_Hbar_Y(info)
	return tostring(self.db.profile.Hbars[HbarDropStart].options.y)
end

function SFSkins:Set_Hbar_Move(info, Value)
	movethem = Value	
	if movethem then
		SFSkins:SetMoveFrames(SFSkins:FrameIdentifier(),"ON")
	else
		SFSkins:SetMoveFrames(SFSkins:FrameIdentifier(),"OFF")
	end
end
		
function SFSkins:Get_Hbar_Move(info)
	return movethem 
end

-------------------------------------------------------------------------------------
------------------[ Vertical Bar Option Table Control Functions ]--------------------
-------------------------------------------------------------------------------------

function SFSkins:Set_Vbar_Dropdown(info, Value)
	VbarDropStart = Value
end

function SFSkins:Get_Vbar_Dropdown(info)
	return VbarDropStart
end

function SFSkins:Set_Vbar_Visible(info, Value)
	self.db.profile.Vbars[VbarDropStart].options.visible = Value
	SFSkins:UpdateFrame(self.db.profile.Vbars[VbarDropStart].options,"VBAR")
end

function SFSkins:Get_Vbar_Visible(info)
	return self.db.profile.Vbars[VbarDropStart].options.visible
end

function SFSkins:Set_Vbar_Buttons(info, Value)
	self.db.profile.Vbars[VbarDropStart].options.buttons = Value
	SFSkins:UpdateFrame(self.db.profile.Vbars[VbarDropStart].options,"VBAR")
end

function SFSkins:Get_Vbar_Buttons(info)
	return self.db.profile.Vbars[VbarDropStart].options.buttons
end

function SFSkins:Set_Vbar_Scale(info, Value)
	self.db.profile.Vbars[VbarDropStart].options.scale = Value
	SFSkins:UpdateFrame(self.db.profile.Vbars[VbarDropStart].options,"VBAR")
end

function SFSkins:Get_Vbar_Scale(info)
	return self.db.profile.Vbars[VbarDropStart].options.scale
end

function SFSkins:Set_Vbar_X(info, Value)
	self.db.profile.Vbars[VbarDropStart].options.x = tonumber(Value)
	SFSkins:UpdateFrame(self.db.profile.Vbars[VbarDropStart].options,"VBAR")
end

function SFSkins:Get_Vbar_X(info)
	return tostring(self.db.profile.Vbars[VbarDropStart].options.x)
end

function SFSkins:Set_Vbar_Y(info, Value)
	self.db.profile.Vbars[VbarDropStart].options.y = tonumber(Value)
	SFSkins:UpdateFrame(self.db.profile.Vbars[VbarDropStart].options,"VBAR")
end

function SFSkins:Get_Vbar_Y(info)
	return tostring(self.db.profile.Vbars[VbarDropStart].options.y)
end

function SFSkins:Set_Vbar_Move(info, Value)
	movethem = Value
	if movethem then
		SFSkins:SetMoveFrames(SFSkins:FrameIdentifier(),"ON")
	else
		SFSkins:SetMoveFrames(SFSkins:FrameIdentifier(),"OFF")
	end
end

function SFSkins:Get_Vbar_Move(info)
	return movethem
end

-------------------------------------------------------------------------------------
--------------------[ End Cap Option Table Control Functions ]-----------------------
-------------------------------------------------------------------------------------

function SFSkins:Set_Cap_Dropdown(info, Value)
	CapDropStart = Value
end

function SFSkins:Get_Cap_Dropdown(info)
	return CapDropStart
end

function SFSkins:Set_Cap_Visible(info, Value)
	self.db.profile.Caps[CapDropStart].options.visible = Value
	SFSkins:UpdateFrame(self.db.profile.Caps[CapDropStart].options,"CAPS")
end

function SFSkins:Get_Cap_Visible(info)
	return self.db.profile.Caps[CapDropStart].options.visible
end

function SFSkins:Set_Cap(info, Value)
	self.db.profile.Caps[CapDropStart].options.buttons = Value
	SFSkins:UpdateFrame(self.db.profile.Caps[CapDropStart].options,"CAPS")
end

function SFSkins:Get_Cap(info)
	return self.db.profile.Caps[CapDropStart].options.buttons
end

function SFSkins:Set_Cap_Scale(info, Value)
	self.db.profile.Caps[CapDropStart].options.scale = Value
	SFSkins:UpdateFrame(self.db.profile.Caps[CapDropStart].options,"CAPS")
end

function SFSkins:Get_Cap_Scale(info)
	return self.db.profile.Caps[CapDropStart].options.scale
end

function SFSkins:Set_Cap_X(info, Value)
	self.db.profile.Caps[CapDropStart].options.x = tonumber(Value)
	SFSkins:UpdateFrame(self.db.profile.Caps[CapDropStart].options,"CAPS")	
end

function SFSkins:Get_Cap_X(info)
	return tostring(self.db.profile.Caps[CapDropStart].options.x)
end

function SFSkins:Set_Cap_Y(info, Value)
	self.db.profile.Caps[CapDropStart].options.y = tonumber(Value)
	SFSkins:UpdateFrame(self.db.profile.Caps[CapDropStart].options,"CAPS")
end

function SFSkins:Get_Cap_Y(info)
	return tostring(self.db.profile.Caps[CapDropStart].options.y)
end

function SFSkins:Set_Cap_Move(info, Value)
	movethem = Value
	if movethem then
		SFSkins:SetMoveFrames(SFSkins:FrameIdentifier(),"ON")
	else
		SFSkins:SetMoveFrames(SFSkins:FrameIdentifier(),"OFF")
	end	
end

function SFSkins:Get_Cap_Move(info)
	return movethem
end

-------------------------------------------------------------------------------------
--------------------[ Misc Bits Option Table Control Functions ]---------------------
-------------------------------------------------------------------------------------

function SFSkins:Set_Bit_Dropdown(info, Value)
	BitDropStart = Value
end

function SFSkins:Get_Bit_Dropdown(info)
	return BitDropStart
end

function SFSkins:Set_Bit_Visible(info, Value)
	self.db.profile.Bits[BitDropStart].options.visible = Value
	SFSkins:UpdateFrame(self.db.profile.Bits[BitDropStart].options,"BITS")
end

function SFSkins:Get_Bit_Visible(info)
	return self.db.profile.Bits[BitDropStart].options.visible
end

function SFSkins:Set_Bit(info, Value)
	self.db.profile.Bits[BitDropStart].options.buttons = Value
	SFSkins:UpdateFrame(self.db.profile.Bits[BitDropStart].options,"BITS")
end

function SFSkins:Get_Bit(info)
	return self.db.profile.Bits[BitDropStart].options.buttons
end

function SFSkins:Set_Bit_Scale(info, Value)
	self.db.profile.Bits[BitDropStart].options.scale = Value
    SFSkins:UpdateFrame(self.db.profile.Bits[BitDropStart].options,"BITS")
end

function SFSkins:Get_Bit_Scale(info)
	return self.db.profile.Bits[BitDropStart].options.scale
end

function SFSkins:Set_Bit_X(info, Value)
	self.db.profile.Bits[BitDropStart].options.x = tonumber(Value)
	SFSkins:UpdateFrame(self.db.profile.Bits[BitDropStart].options,"BITS")	
end

function SFSkins:Get_Bit_X(info)
	return tostring(self.db.profile.Bits[BitDropStart].options.x)
end

function SFSkins:Set_Bit_Y(info, Value)
	self.db.profile.Bits[BitDropStart].options.y = tonumber(Value)
	SFSkins:UpdateFrame(self.db.profile.Bits[BitDropStart].options,"BITS")
end

function SFSkins:Get_Bit_Y(info)
	return tostring(self.db.profile.Bits[BitDropStart].options.y)
end

function SFSkins:Set_Bit_Move(info, Value)
	movethem = Value
	if movethem then
		SFSkins:SetMoveFrames(SFSkins:FrameIdentifier(),"ON")
	else
		SFSkins:SetMoveFrames(SFSkins:FrameIdentifier(),"OFF")
	end	
end

function SFSkins:Get_Bit_Move(info)
	return movethem
end
