+ if window.location.hash? and window.location.hash.length > 0
+ me = window.location.hash.substr 1
+ winloc = "#{window.location}"
+ server_url = winloc.substr 0, winloc.length - window.location.hash.length
+ else
+ me = 'p1'
+ server_url = window.location
+
+ state = window.game_model.new me
+ state.on 'move', (agent, card, x, y) ->
+ # FIXME add/handle pile argument
+ if agent is me
+ tell_server ['move', agent, card, x, y]
+ else
+ state.cards[card].view.animate { left: "#{x}px", top: "#{y}px"}, 800
+ state.on 'mark', (agent, card, state) ->
+ @cards[card].view.toggleClass 'marked', state
+ if agent is me
+ tell_server ['mark', agent, card, state]
+ state.on 'flip', (agent, card, state) ->
+ @cards[card].view.toggleClass 'flipped', state
+ if agent is me
+ tell_server ['flip', agent, card, state]
+ state.on 'set_cards', (agent, cards) ->
+ # FIXME add agent arg and tell server if it's not us
+ $('.card').remove()
+ for card in cards
+ instantiate_card card
+ if agent is me
+ tell_server ['set_cards', agent, cards]
+
+ # timeout so browser will stop showing that we're loading
+ timeout 1, poll_for_updates
+ timeout 2, ->
+ # ask for initial state
+ tell_server ['send_state', state.agent]