       @goto(@current)
 
   get_pages: (tpl = 'page') ->
-    ref = this
     html = ''
-    $.each @options.pages, (idx,el) -> 
-      html += Mustache.to_html ref.tpl(tpl), el
+    $.each @options.pages, (idx,el) => 
+      html += Mustache.to_html @tpl(tpl), el
     html
 
   toggle: ->
-    ref = this
     el = $("##{@options.id}")
     if @options.expanded 
       @options.expanded = false
-      el.animate {height: @options.collapsed_height}, "fast", ->
-        ref.collapse()
-        ref.options.onCollapse()
+      el.animate {height: @options.collapsed_height}, "fast", =>
+        @collapse()
+        @options.onCollapse()
     else
       @options.expanded = true
-      el.animate {height: @options.expanded_height}, "fast", ->
-        ref.expand()
-        ref.options.onExpand()
-        ref.goto(0)
+      el.animate {height: @options.expanded_height}, "fast", =>
+        @expand()
+        @options.onExpand()
+        @goto(0)
 
   load: (i) ->
     ref = this

  events: ->
    @modal_events()
    @field_events()
    ref = this
    $("a.asset-remove").live 'click', ->
      ref.remove(this)
      false
    $("##{@options.id}-handle").live 'click', ->
      ref.toggle()
      false
    @key_down()
    tabs = $("##{@options.id} a.tab")
    $.each tabs, (idx, el) ->
      $(this).addClass('on') if idx == 0
      $(el).click ->


  load_results: (response) ->
    @log "load_results()"
    $.each response, (j,el) =>
      link = @build(el)
      li = $('<li class="file"></li>').append(link)
      $("#asset-results ul").amplePanels('append', li)
      @load_img(link, el.sizes.tn)

  build: (el) ->
    ref = this
