function handle_secondary_menu_opening(target_id) {
  // Close all open secondary menus
  $$('div#secondary div').each(function(el) {
    if(target_id != el.id && $(el.id).visible()) {
      Effect.SlideUp(el.id, { duration: 0.2 });
    }
  });
  
  // Open target secondary menu if it's not visible already
  Effect.toggle(target_id, 'slide', { duration: 0.4 });
}

/* Behaviour rules */

var rules = {
	'div#top_nav div#primary ul li a.target_secondary' : function(el) {
		el.onclick = function() {
			target_id = this.innerHTML.underscore();
			handle_secondary_menu_opening(target_id);
			return false;
		}
	},
	'.hover_highlightable' : function(element) {
		element.onmouseover = function() {
			element.className = element.className.replace(/hover_highlightable/, 'hover_highlightable hover_active');
		}

		element.onmouseout = function() {
			element.className = element.className.replace(/hover_highlightable hover_active/, 'hover_highlightable');
		}
	}
};

Behaviour.register(rules);