function homePageLoaded(evt) {
  var list = $ul();

  Event.observe($(document), 'click', showOrHideList);
  setTimeout(function () {list.show()}, 1500);

  function showOrHideList(evt) {
    var child = Event.element(evt);
    if (
      child.ancestors().detect(function(el){return el.id=='pathChooserArea'})
    ) {
      list.toggle();
    }	else if (list.visible()) {
      list.hide();
    }
  }

  Event.addBehavior({
    'div#pathChooserArea':function() {
      var defaultText = ""; // initialise
      var div = this;
      
      // Extract values from select list to form links
      $$('div#pathChooserArea select option').each(function(element) {
        if(element.value != "") {
          var listItem = $li();
          var listLink = $a({'href':element.value},element.text);
          listLink.onclick = function () {div.down('div').update(element.text);}
          listItem.appendChild(listLink);
          list.appendChild(listItem);
        } else {
          defaultText = element.text;
        }	    
      });
      
      div.update('<div>'+defaultText+'</div>');
      div.appendChild(list);
      list.hide();
    },
    
    'div#pathChooserArea li:mouseover':function() {
       this.addClassName('hover');
    },
    
    'div#pathChooserArea li:mouseout':function() {
      this.removeClassName('hover');
    }	
  });
}

function addCurrentTick(element) {
  var tick = $div({'class':'tickCurrent'});
  element.addBefore(tick);
  element.addClassName('active');  
}

function replaceAllCurrentWithVisited() {
  $$('dt.active').first().removeClassName('active');
  $$('div.tickCurrent').each(function(e) {
    e.removeClassName('tickCurrent');
    e.addClassName('tickVisited');
  });
}

Event.addBehavior({
  'dd':function() { 
    this.hide();
    $$('dd').first().show();
  },
  
  'dt': function() {
    if(this == ($$('dt').first())) {
      addCurrentTick(this);
    };
  },
  
  'dt:click': function() {
    $$('dd').invoke('hide');
    this.next('dd').show();
    replaceAllCurrentWithVisited();
    if(this.previous().getAttribute("class") != 'tickCurrent') {
      // Remove tickVisited if exists before adding current
      if(this.previous().getAttribute("class") == 'tickVisited'){
        this.previous().remove();
      }
      // Add currentTick
      addCurrentTick(this);  
    };
  }
});
