var lastControllerLocation = "#index!1"; controllers.index = function(search, sort, sortDirection) { var _this = this; function sortFor(type) { if(!type) type = "publishedOn"; if(type == "publishedOn") return function(story) { return story.publishedOn; }; if(type == "wordCount") return function(story) { return story.wordCount; }; if(type == "title") return function(story) { return story.title.toLowerCase(); }; } var storys = store; if(search && search != "") { var words = search.split(/\s+/); _.each(words, function(word) { regex = RegExp(word, "i"); storys = _.filter(storys, function(story) { return story.title.match(regex); }); }); } if(!sort) sort = "publishedOn"; storys = _.sortBy(storys, sortFor(sort)); if(!sortDirection) sortDirection = "desc"; if(sortDirection == "desc") storys = storys.reverse(); storys = _.first(storys, 500); function addStorys(storys) { if($("#stories > li").length) return; _.each(storys, function(story) { var item = $("