$(function() {
  var connect, local, localAddr, log, remote, slide, socket, titleArea, urlArea;
  localAddr = 'http://127.0.0.1:8080';
  local = ['/1', '/2', '/3', '/4', '/5', '/6', '/7', '/8', '/9', '/10'];
  remote = ['http://stackoverflow.com/questions/101268/hidden-features-of-python', 'http://stackoverflow.com/questions/81584/what-ide-to-use-for-python', 'http://stackoverflow.com/questions/228181/the-zen-of-python', 'http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained', 'http://stackoverflow.com/questions/2146383/https-connection-python', 'http://stackoverflow.com/questions/68645/static-class-variables-in-python', 'http://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python', 'http://stackoverflow.com/questions/36932/whats-the-best-way-to-implement-an-enum-in-python'];
  urlArea = $('<textarea rows="11" cols="90"></textarea>');
  titleArea = $('<textarea rows="11" cols="90"></textarea>');
  slide = $('.slide.msg-demo');
  slide.append(urlArea).append('<div><button id="local">Local</button><button id="remote">Remote</button><div>').append('<div><button id="fetch">Fetch</button><div>').append($('<div><div>').append(titleArea));
  socket = null;
  connect = function(f) {
    console.log('Connecting...');
    socket = io.connect(location.origin, {
      'force new connection': true
    });
    socket.on("connect", function() {
      return f(socket);
    });
    socket.on("message", function(data) {
      return log(data);
    });
    return socket.on('disconnect', function() {
      return console.log('Disconnected');
    });
  };
  log = function(msg) {
    return titleArea.val(titleArea.val() + msg + '\n');
  };
  $('#local').click(function() {
    var l;
    return urlArea.val(((function() {
      var _i, _len, _results;
      _results = [];
      for (_i = 0, _len = local.length; _i < _len; _i++) {
        l = local[_i];
        _results.push(localAddr + l);
      }
      return _results;
    })()).join('\n'));
  });
  $('#remote').click(function() {
    return urlArea.val(remote.join('\n'));
  });
  return $('#fetch').click(function() {
    if (socket && socket.socket.connected) {
      console.log('Disconnecting...');
      socket.disconnect();
    }
    return connect(function() {
      var u, urls, _i, _len, _results;
      console.log('Fetching...');
      titleArea.val('');
      urls = (function() {
        var _i, _len, _ref, _results;
        _ref = urlArea.val().split('\n');
        _results = [];
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          u = _ref[_i];
          if (u) {
            _results.push(u);
          }
        }
        return _results;
      })();
      console.log(urls);
      _results = [];
      for (_i = 0, _len = urls.length; _i < _len; _i++) {
        u = urls[_i];
        _results.push(socket.send(u));
      }
      return _results;
    });
  });
});