document.observe("dom:loaded", function() {
  /*
  * ADD A CLASS TO RELEVANT NAVIGATION ITEMS
  */

  // Create an array of slugs from the location
  var slugs = location.href.split("/").without("");

  // Loop through the links and test the slug
  $$(".navigation a").each(function(a) {
    var slug = a.href.split("/").without("");
    
    // Ignore http and the domain
    if (slug.length > 2) {
      slug = slug.pop();
    }
    
    if (slugs.indexOf(slug) != -1) {
      a.addClassName("selected");
    }
  });
  
  
  /*
  * HANDLE THE FORM
  */
  
  $("keywords").observe("focus", function(e) {
    this.addClassName("focus");
    this.value = "";
  });

  $("keywords").observe("blur", function(e) {
    this.removeClassName("focus");
    
    if (this.value == "") {
      this.value = "SEARCH";
    }
  });
  
  $("keywords").observe("keypress", function(e){
      if(e.keyCode == Event.KEY_RETURN) {
        console.log("submit the form");
        Event.stop(e);
      }
  });
});

