 login = (jid, pw, opt) ->
 
   if opt?
-    connection_options.path = opt.path if opt.path
-    connection_options.port = opt.port if opt.port
-    connection_options.host = opt.host if opt.host
+    connection_options.path     = opt.path     if opt.path
+    connection_options.port     = opt.port     if opt.port
+    connection_options.host     = opt.host     if opt.host
+    connection_options.protocol = opt.protocol if opt.protocol
 
   connection = create_connection_obj()
   connection.connect jid, pw, on_connection_change

create_connection_obj = ->

  new Strophe.Connection get_bosh_url
    path: connection_options.path
    host: connection_options.host
    port: connection_options.port

key2cache   = (k) -> "#{CACHE_PREFIX}#{k}"



mediator = new scaleApp.Mediator

ID               = "xmpp"
DEFAULT_PATH     = "http-bind/"
DEFAULT_PROTOCOL = "http"
DEFAULT_PORT     = 5280
CACHE_PREFIX     = "scaleApp.#{ID}.cache."

# Variable that holds the Strophe connection object
connection = null

# Object that holds all connection sepecific options.
connection_options =
  host:     document.domain
  port:     DEFAULT_PORT
  path:     DEFAULT_PATH
  protocol: DEFAULT_PROTOCOL
  jid:      null
  sid:      null
  rid:      null

# Generates an appropriate bosh url for the connection.
#
