     expires.setTime(expires.getTime() + options.expires*24*60*60*1000)
     options.expires = expires
 
-  options.path ?= '/'
-
   value  = (value + '').replace(/[^!#-+\--:<-\[\]-~]/g, encodeURIComponent)
   cookie = encodeURIComponent(name) + '=' + value
 
   cookie += ';expires=' + options.expires.toGMTString() if options.expires
   cookie += ';path=' + options.path if options.path
+  cookie += ';domain=' + options.domain if options.domain
   document.cookie = cookie
 
 getCookie = (name) ->

      @getVariantForName(name)

  getVariantCookie: =>
    getCookie("abbaVariant_#{@name}")

  setVariantCookie: (value) =>
    setCookie("abbaVariant_#{@name}", value, expires: 600)

  removeVariantCookie: =>
    setCookie("abbaVariant_#{@name}", '', expires: true)

  # Complete Cookie

  setPersistCompleteCookie: =>
    setCookie("abbaPersistComplete_#{@name}", '1', expires: 600)

  hasPersistCompleteCookie: =>
    !!getCookie("abbaPersistComplete_#{@name}")

  removePersistCompleteCookie: =>
    setCookie("abbaPersistComplete_#{@name}", '', expires: true)

do ->
  # Find Abba's endpoint from the script tag

    return value if key is name
  null

extend = (target, args...) ->
  for source in args
    for key, value of source when value?
      target[key] = value

# Public

class @Abba
  @endpoint: 'http://localhost:4567'
  @defaults:
    path: '/'

  constructor: (name, options = {}) ->
    unless name
