(function() {
  $(function() {
    var uploader;
    $.getJSON('/uploads', function(images) {
      var image, _i, _len, _results;
      _results = [];
      for (_i = 0, _len = images.length; _i < _len; _i++) {
        image = images[_i];
        _results.push($('#imageGrid').append($("<img class='image' src='" + image['preview'] + "' width='200' data-url='" + image['url'] + "' onclick='loadURL($(this));' style='cursor:pointer;' />")));
      }
      return _results;
    });
    $('#twitter').click(function() {
      return $.post('/auth', function(url) {
        return window.location.href = url;
      });
    });
    $('.load').click(function() {
      return $('#imageGrid').fadeIn().isotope({
        itemSelector: '.image'
      });
    });
    return uploader = new qq.FileUploader({
      element: $('#upload')[0],
      action: '/submit',
      allowedExtensions: ['jpg', 'jpeg'],
      sizeLimit: 10000000,
      debug: false,
      onComplete: function(id, fileName, response) {
        var _item;
        if (!response.error) {
          _item = $("<img class='image' src='" + response.preview + "' width='200' data-url='" + response.url + "' onclick='loadURL($(this));' />").css('cursor', 'pointer');
          $('#imageGrid').prepend(_item).isotope('reloadItems');
          return setTimeout((function() {
            return $('#imageGrid').isotope('reLayout').isotope({
              sortBy: 'original-order'
            });
          }), 500);
        }
      }
    });
  });
  window.loadURL = function($img) {
    return $('#imageURL').fadeOut().fadeIn(function() {
      return $(this).find('input').val($img.attr('data-url')).focus().select();
    });
  };
}).call(this);

