 # globally accessible method for getting the URL of a user's avatar
 window.avatarUrl = (user, img_size) -> 
   user = fetch(user)
-  (fetch('/application').asset_host or '') + \
-        "/system/avatars/" + \
-        "#{user.key.split('/')[2]}/#{img_size}/#{user.avatar_file_name}"  
-
+  if !!user.avatar_file_name
+    (fetch('/application').asset_host or '') + \
+          "/system/avatars/" + \
+          "#{user.key.split('/')[2]}/#{img_size}/#{user.avatar_file_name}"  
+  else 
+    null
 
 
 user_name = (user, anon) -> 

    # the broken text ugliness by using img { text-indent: -10000px } to 
    # hide the alt text / broken image
    attrs.alt = ""
  
  tag attrs,
    if add_initials
      fontsize = style.width / 2
      ff = 'monaco,Consolas,"Lucida Console",monospace'
      if name == 'Anonymous'
        name = '?'

      if name.length == 2
        name = "#{name[0][0]}#{name[1][0]}"
      else 
        name = "#{name[0][0]}"

      DIV
        style: 
          color: 'white'
          pointerEvents: 'none'
          fontSize: fontsize
          position: 'relative'
          fontFamily: ff
          top: .3 * fontsize #style.height / 2 - heightWhenRendered(name, {fontSize: fontsize, fontFamily: ff}) / 2
          overflow: 'hidden'
        name

        DIV 
          className: 'hidden'
          tooltip




      fetch user
      return SPAN null

  attrs.style ||= {}
  style = attrs.style

  # Setting avatar image
  #   Don't show one if it should be anonymous or the user doesn't have one
  #   Default to small size if the width is small  
  anonymous = attrs.anonymous? && attrs.anonymous 
  src = null
  if !anonymous && user.avatar_file_name 
    if style?.width >= 50 && !browser.is_ie9
      img_size = 'large'
    else 
      img_size = attrs.img_size or 'small'

    src = avatarUrl user, img_size

    # Override the gray default avatar color if we're showing an image. 
    # In most cases the white will allow for a transparent look. It 
    # isn't set to transparent because a transparent icon in many cases
    # will reveal content behind it that is undesirable to show.  
    style.backgroundColor = 'white'

  id = if anonymous 
         "avatar-hidden" 
       else 
         "avatar-#{user.key.split('/')[2]}"

  name = user_name user, anonymous

  if attrs.alt 
    alt = attrs.alt.replace('<user>', name) 
    delete attrs.alt
  else 
    alt = name 

  attrs = _.extend attrs,
    key: user.key
    className: "avatar #{props.className or ''}"
    'data-user': user.key
    'data-tooltip': if !props.hide_tooltip then alt 
    'data-anon': anonymous  
    tabIndex: if props.focusable then 0 else -1

  if src
    # attrs.alt = if props.hide_tooltip then '' else tooltip 
    # the above fails too much on broken images, and 
    # screenreaders would probably be overwhelmed with saying all these stances.
