Maildog.Views.EmailFolders = Backbone.CompositeView.extend({
  template: JST['emailFolders'],
  tagName: "li",

  events: {
    "click .compose-button": "popUpComposeEmailBox",
    "click #inbox-folder": "routeToInbox",
    "click #starred-folder": "routeToStarred",
    "click #sent-folder": "routeToSent",
    "click #drafts-folder": "routeToDrafts",
    "click #trash-folder": "routeToTrash",
  },

  render: function() {
    this.$el.html(this.template());
    return this;
  },

  routeToInbox: function() {
    Backbone.history.loadUrl("#inbox");
  },

  routeToStarred: function() {
    Backbone.history.loadUrl("#starred");
  },

  routeToSent: function() {
    Backbone.history.loadUrl("#sent");
  },

  routeToDrafts: function() {
    Backbone.history.loadUrl("#drafts");
  },

  routeToTrash: function() {
    Backbone.history.loadUrl("#trash");
  },

  popUpComposeEmailBox: function() {
    Maildog.router.removeFlashes();
    var view = new Maildog.Views.ComposeEmailBox();
    this.addSubview('.compose-email-popup-container', view, true);
    $('.compose-email-popup-to').focus();
  }
});

Maildog.Views.EmailFolders = Backbone.CompositeView.extend({
  template: JST['emailFolders'],
  tagName: "li",

  events: {
    "click .compose-button": "popUpComposeEmailBox",
    "click #inbox-folder": "routeToInbox",
    "click #starred-folder": "routeToStarred",
    "click #sent-folder": "routeToSent",
    "click #drafts-folder": "routeToDrafts",
    "click #trash-folder": "routeToTrash",
  },

  render: function() {
    this.$el.html(this.template());
    return this;
  },

  routeToInbox: function() {
    if (Backbone.history.getFragment() === "inbox") {
      Backbone.history.loadUrl("#inbox");
    }
    else {
      Backbone.history.navigate("inbox", { trigger: true });
    }
  },

  routeToStarred: function() {
    if (Backbone.history.getFragment() === "starred") {
      Backbone.history.loadUrl("#starred");
    }
    else {
      Backbone.history.navigate("starred", { trigger: true });
    }
  },

  routeToSent: function() {
    if (Backbone.history.getFragment() === "sent") {
      Backbone.history.loadUrl("#sent");
    }
    else {
      Backbone.history.navigate("sent", { trigger: true });
    }
  },

  routeToDrafts: function() {
    if (Backbone.history.getFragment() === "drafts") {
      Backbone.history.loadUrl("#drafts");
    }
    else {
      Backbone.history.navigate("drafts", { trigger: true });
    }
  },

  routeToTrash: function() {
    if (Backbone.history.getFragment() === "trash") {
      Backbone.history.loadUrl("#trash");
    }
    else {
      Backbone.history.navigate("trash", { trigger: true });
    }
  },

  popUpComposeEmailBox: function() {
    Maildog.router.removeFlashes();
    var view = new Maildog.Views.ComposeEmailBox();
    this.addSubview('.compose-email-popup-container', view, true);
    $('.compose-email-popup-to').focus();
  }
});

fix routing from folder clicks