/*
  boss search by Christian Heilmann
  Version: 1.0
  Homepage: http://ydntest.com/ydnblogsearch
  Copyright (c) 2008, Christian Heilmann
  Code licensed under the BSD License:
  http://wait-till-i.com/license.txt
*/

// get the YUI 3:)
YUI({combine: true, timeout: 10000}).use("node",
function(Y){

// add a class to the results list to trigger the different style
  Y.get('#results').addClass('js');

// inject links into the keyword labels
  Y.all('#results .kw').set('innerHTML',
                            '<a href="show keywords">Keywords</a>');

// on clicking the results list
  Y.get('#results').on('click',function(e){ 

// get the parent node
    var parent = e.target.get('parentNode');

// make sure it was the keyword label 
    if(parent.hasClass('kw')){

// don't follow the link
      e.preventDefault();

// get the target and the next sibling of the parent (the link and the nested 
// list of keywords)
      var current = e.target;
      var next = parent.next();

// if the class show exists, remove it and change the link and parent class 
// accordingly 
      if(next.hasClass('show')){
        current.set('href','show keywords');
        next.removeClass('show');
        parent.removeClass('open');

// otherwise do the opposite
      } else {
        current.set('href','hide keywords');
        next.addClass('show');
        parent.addClass('open');
      }
    } 
  });
});
