<!--- 
 Filename: ColorFunctions.cfm
 Created by: Nate Weiss (NMW)
 Purpose: Creates a library of user-defined functions
 related to colors in the browser safety palette
--->


<!--- Function: ListGetRandom() --->
<!--- Returns a random element from any comma-separated list --->
<cffunction name="listGetRand" output="false" returnType="string">
 <!--- First argument: The comma-separated list --->
 <cfargument name="list" type="string" required="Yes">
 <!--- Second argument: List delimiter. Default to comma --->
 <cfargument name="delim" type="string" required="false" default=",">
 
 <cfreturn listGetAt(ARGUMENTS.list, 
 randRange(1, listLen(ARGUMENTS.list, ARGUMENTS.delim)), ARGUMENTS.delim)> 
</cffunction>


<!--- Function: GetRandColor() --->
<!--- Returns a random color in proper html color format --->
<cffunction name="getRandColor" output="false" returnType="string">
 <!--- 
 This is a list of hexidecimal values that can be used to specify colors
 for use on Web pages. Any three of these can be combined to make a color, 
 in the form RRGGBB. For instance, 9900CC is a nice shade of purple.
 --->
 <cfset var hexList = "00,11,22,33,44,55,66,77,88,99,AA,BB,CC,DD,EE,FF">
 
 <!--- Choose 3 of the Hex values randomly and return them all together --->
 <cfreturn listGetRand(hexList) & listGetRand(hexList) & listGetRand(hexList)>
</cffunction>

<!--- Function: MulticolorFormat() --->
<!--- Adds <font> tags to any text such that each word is colored randomly --->
<cffunction name="multicolorFormat" output="false" returnType="string">
 <!--- One argument: the text to make multicolored --->
 <cfargument name="text" type="string" required="Yes">
 
 <!--- This is what we will end up returning. Start with an empty string. --->
 <cfset var string = "">
 <cfset var word = "">
 
 <!--- Loop through the list of words, treating spaces as list delimiters --->
 <cfloop list="#ARGUMENTS.text#" index="word" delimiters=" ">
 <!--- Create a <font> tag for this word, using a random color --->
 <cfset string = string & ' <font color="#getRandColor()#">#word#</font>'>
 </cfloop>
 
 <!--- Return completed string ---> 
 <cfreturn string> 
</cffunction>
