/* global gon */
$(document).ready(function() {
  // Bind both change() and keyup() in the icon keyword dropdown because Firefox doesn't
  // respect up/down key selections in a dropdown as a valid change() trigger
  $("#icon_dropdown").change(function() { setIconFromId($(this).val()); });
  $("#icon_dropdown").keyup(function() { setIconFromId($(this).val()); });

  $('.gallery-minmax').click(function() {
    var elem = $(this);
    var id = elem.data('id');
    if (elem.html().trim() === '-') {
      $('#gallery' + id).hide();
      $('#gallery-tags-' + id).hide();
      elem.html('+');
    } else {
      $('#gallery' + id).show();
      $('#gallery-tags-' + id).show();
      elem.html('-');
    }
  });
});

function setIconFromId(id) {
  $("#new_icon").attr('src', gon.gallery[id].url);
  $("#new_icon").attr('alt', gon.gallery[id].keyword);
  $("#new_icon").attr('title', gon.gallery[id].keyword);
  if (typeof gon.gallery[id].aliases !== "undefined") {
    var aliases = gon.gallery[id].aliases;
    if (aliases.length > 0) {
      $("#alias_dropdown").show().empty().append('<option value="">— No alias —</option>');
      for (var i = 0; i < aliases.length; i++) {
        $("#alias_dropdown").append($("<option>").attr({value: aliases[i].id}).append(aliases[i].name));
      }
    } else {
      $("#alias_dropdown").hide().val('');
    }
  }
}

@@ -362,356 +362,8 @@
  %7D);
-%0A%0A  $('.gallery-minmax').click(function() %7B%0A    var elem = $(this);%0A    var id = elem.data('id');%0A    if (elem.html().trim() === '-') %7B%0A      $('#gallery' + id).hide();%0A      $('#gallery-tags-' + id).hide();%0A      elem.html('+');%0A    %7D else %7B%0A      $('#gallery' + id).show();%0A      $('#gallery-tags-' + id).show();%0A      elem.html('-');%0A    %7D%0A  %7D);
 %0A%7D);

Remove dead duplicate code for gallery minmax