     self =
       channels: ->
         channels.copy()
-        
+
       r: (val) ->
         if val?
           channels[0] = val
           return self
         else
           channels[0]
-        
+
       g: (val) ->
         if val?
           channels[1] = val
           return self
         else
           channels[1]
-          
+
       b: (val) ->
         if val?
           channels[2] = val
           return self
         else
           channels[2]
-          
+
       a: (val) ->
         if val?
           channels[3] = val

        return [
          parseInt(hexString.substr(0, 2), 16)
          parseInt(hexString.substr(2, 2), 16)
          parseInt(hexString.substr(4, 2), 16)  
          if hexString.substr(6, 2).length then parseInt(hexString.substr(6, 2), 16) / 255.0 else 1.0
        ]
      else
        undefined
       
  parseRGB = (colorString) ->
    return unless bits = rgbParser.exec(colorString) 
    
    return [
      parseInt(bits[1])
      parseInt(bits[2])
      parseInt(bits[3])
      if bits[4]? then parseFloat(bits[4]) else 1.0
    ]
    
  normalizeKey = (key) ->
    key.toLowerCase().replace(/ /g, "")
    
  window.Color = (color) ->
    color ||= "rgba(0, 0, 0, 0)"
    
    parsedColor = null
    
    if arguments.length == 2
      c = arguments[0]
      a = arguments[1]
      if Object.prototype.toString.call(c) == '[object Array]' 
        parsedColor = [parseInt(c[0]), parseInt(c[1]), parseInt(c[2]), parseFloat(a)]
      else if Object.prototype.toString.call(c) != '[object Array]'
        parsedColor = lookup[normalizeKey(c)] || parseHex(c) || parseRGB(c)
        parsedColor[3] = a
    else if arguments.length > 2
      alpha = if arguments[3]? then arguments[3] else 1
      parsedColor = [parseInt(arguments[0]), parseInt(arguments[1]), parseInt(arguments[2]), parseFloat(alpha)] 
    else if color.length > 2 && Object.prototype.toString.call(color) == '[object Array]' 
      alpha = if color[3]? then color[3] else 1
      parsedColor = [
        parseInt(color[0]), 
        parseInt(color[1]), 
        parseInt(color[2]), 
        parseFloat(alpha)
      ]
    else
      parsedColor = lookup[normalizeKey(color)] || parseHex(color) || parseRGB(color)
   
    return unless parsedColor   
    
    alpha = parsedColor[3]

    channels = [
      parsedColor[0] 
      parsedColor[1]
      parsedColor[2]
      if alpha? then parseFloat(alpha) else 0.0


  parseHex = (hexString) ->
    hexString = hexString.replace(/#/, '')

    switch hexString.length
      when 3, 4
        return [
