     @multiple       = @select.attr("multiple") == "multiple"
     @build_and_append_picker()
 
-  has_implicit_blanks: ->
-    (option for option in @picker_options when (option.is_blank() && !option.has_image())).length > 0
-
-  build_and_append_picker: ->
+  build_and_append_picker: () ->
     @select.hide() if @opts.hide_select
     @select.change {picker: this}, (event) ->
       event.data.picker.sync_picker_with_select()

    else
      @option.text()

  create_node: () ->
    @node = $("<li/>")
    image = $("<img class='image_picker_image'/>")
    image.attr("src", @option.data("img-src"))
    thumbnail = $("<div class='thumbnail'>")
    thumbnail.click {picker: @picker, option: this}, (event) ->
      picker  = event.data.picker
      option  = event.data.option
      if picker.multiple
        if $.inArray(option.value(), picker.select.val()) >= 0
          option.option.prop("selected", false)
        else
          option.option.prop("selected", true)
      else
        if picker.has_implicit_blanks() && option.is_selected()
          picker.select.val("")
        else
          picker.select.val(option.value())
      picker.sync_picker_with_select()
    thumbnail.append(image)
    thumbnail.append($("<p/>").html(@label())) if @opts.show_label
    @node.append( thumbnail )

#

jQuery.fn.extend({
  imagepicker: (opts = {}) ->
    this.each () ->
      select = $(this)
      select.next("ul.image_picker_selector").remove()
      select.data "picker", new ImagePicker(this, sanitized_options(opts))
      opts.initialized() if opts.initialized?
})

sanitized_options = (opts) ->
  default_options = {
    hide_select:  true,
    show_label:   false,
    initialized:  undefined,
    changed:      undefined,
    clicked:      undefined,
    selected:     undefined,
  }
  jQuery.extend(default_options, opts)

both_array_are_equal = (a,b) ->
  $(a).not(b).length == 0 && $(b).not(a).length == 0

class ImagePicker
  constructor: (select_element, @opts={}) ->
