local function SetAutoRoles()
	local index = 0
	local upper,unitstring,unitID
	if IsInRaid() then
		upper = 40
		unitstring = "raid"		
	else
		upper = 5
		unitstring = "party"
	end
	
	while index <= upper do			
		unitID 	= unitstring..index
		local name 		= UnitName(unitID)
		local _,class 	= UnitClass(unitID)
		local level 	= UnitLevel(unitID)
		local spec 		= nil
		local currentRole = UnitGroupRolesAssigned(unitID)			
		if name and class and level then
			if level < 10 or class == "ROGUE" or class == "HUNTER" or class == "MAGE" or class == "WARLOCK" then
				spec = "DAMAGER"
			elseif currentRole and currentRole ~= "NONE" then
				spec = currentRole
			end
			if spec then
				UnitSetRole(unitID, spec)
			end
		end			
		index 	= index +1
		unitID 	= unitstring..index
	end
	local _,class = UnitClass("player")
	if class == "ROGUE" or class == "HUNTER" or class == "MAGE" or class == "WARLOCK" then
		UnitSetRole("player", "DAMAGER")
	else
		local specIndex = GetSpecialization()
		if specIndex then
			local role = select(6,GetSpecializationInfo(specIndex))
			UnitSetRole("player",role)
		end
	end
end


function osROLE()
	if UnitIsGroupLeader("player") or UnitIsRaidOfficer("player") then
		SetAutoRoles()
		InitiateRolePoll()
	end
end

SLASH_ROLE1 = "/role";
SLASH_ROLE2 = "/rolecheck";
SlashCmdList["ROLE"] = osROLE