Updated autocomplete to work in a more understandable way.

Change-Id: I2c4db0e90a46671eb83c7f8b829f57c11f98c323
diff --git a/client/catalog/autocomplete.js b/client/catalog/autocomplete.js
index b160dcb..2cda884 100644
--- a/client/catalog/autocomplete.js
+++ b/client/catalog/autocomplete.js
@@ -28,12 +28,6 @@
         'top': this.parent().height()
       });
 
-//      this.focus(function(){
-//        element.slideDown();
-//      }).blur(function(){
-//        element.slideUp();
-//      }).before(element);
-
       this.after(element);
 
       var getSuggestions = function(current, callback){
@@ -45,7 +39,10 @@
         }, []));
       }
 
+      var lastList = [];
+
       var setAutoComplete = function(list){
+        lastList = list;
         element.empty();
 
         element.html(list.reduce(function(prev, current){
@@ -60,6 +57,17 @@
 
       var input = this;
 
+      var matcher = /^\/([-_\w]+\/)*/; //Returns only the absolute path.
+
+      var getValue = function(){
+        var res = matcher.exec(input.val());
+        if (res){
+          return res[0]; //Return the absolute match
+        } else {
+          throw new Error("Empty or incorrectly formatted path.");
+        }
+      }
+
       element.bind('click', 'a', function(){
         input.val($(this).text());
       });
@@ -101,15 +109,30 @@
           break;
 
           case 9: //Tab
-          getSuggestions(input.val(), setAutoComplete);
+          getSuggestions(getValue(), setAutoComplete);
           e.preventDefault(); //Don't print tab or select a different element.
           break;
+
+          default:
+          var val = input.val(); //Needs to be unfiltered, for filtering existing results.
+          setAutoComplete(lastList.reduce(function(prev, current){
+            if (current.indexOf(val) === 0){
+              prev.push(current);
+            }
+            return prev;
+          }, []));
+
         }
 
+      })
+      .keyup(function(e){
+        if (e.which === 191){
+          getSuggestions(getValue(), setAutoComplete);
+        }
       });
 
       this.on('autoComplete', function(){
-        getSuggestions(input.val(), setAutoComplete);
+        getSuggestions(getValue(), setAutoComplete);
       });
 
       return this;