 contextController = null
 
 $(document).ready ->
-  contextController = new ContextController('#contextPanel .profile')
+  contextController = new ContextController('#contextPanel')
 
 class ContextController
   constructor: (containerSelector) ->
-    @$container = $(containerSelector)
+    @$container = $(containerSelector + ' .profile')
     
     @contextView = new ContextView(containerSelector)
     

    @$container.find('.cancel').click (event) =>
      @contextView.showProfile()
    
    $('form#update_profile').bind 'ajax:beforeSend', (xhr, settings)->
      @contextView.showProfile()
    
    $('form#update_profile').bind 'ajax:success', (data, xhr, status)->
      $('p.notice').text('Profile has been updated')


class ContextView
  constructor: (containerSelector) ->
    @$container = $(containerSelector  + ' .profile')
    @$viewPanel = @$container.find('.view')
    @$editPanel = @$container.find('.edit')
    @$namePanel = @$container.find('.name')
    @$detailsPanel = @$container.find('.details')
  profileState: ->
    @$namePanel.css('display')
  showEditProfile: ->
    @$viewPanel.hide()
    @$editPanel.show()
  showProfile: ->
    @$viewPanel.show()
    @$editPanel.hide()
  expandProfile: ->
    @$namePanel.slideDown()
    @$detailsPanel.slideDown()
  contractProfile: ->
    @$namePanel.slideUp()
    @$detailsPanel.slideUp()