﻿/** @fileoverview
  * This file provides the pop-out effect for the T1 left-side menus within
  * the public interface for the Reading Employment Communications Module.
  *
  * This script is designed to be included in the body of the page, right
  * after the menu's parent tag is closed. This ensures that the menu is
  * available on the page.
  *
  * The goal here is that T1 menu items should go to nowhere in particular.
  * Instead, if the user clicks on one, the T2 menu will appear out of
  * nowhere.
  *
  * If the user is already on a T2+ item, then the parent T1 item will not
  * exhibit this effect (though they may, of course, click on the sibling
  * T1 items).
  *
  * 2009-09-23: Change of behaviour:  When a new tier opens, all other open
  *             tiers should close, even the "Active" one, so there is only
  *             one open tier at a time.
  *             Also: Pages in OTHG00604 should be exempt from this.
  * 2009-09-17: First revision
  */

/*global Event, YAHOO, Dom */


Event.addListener(
	YAHOO.util.Selector.query('#layout_LeftMenu li.T1 > a'),
	'click',
	function (e) {

		if (Dom.hasClass(document.body, 'OTHG00604')) {
			return;
		}

		Event.preventDefault(e);

		var target = Event.getTarget(e).parentNode,
		lists, x;

		// Get the child items that we want to expand.
		target = YAHOO.util.Selector.query('ul.T2', target, true);
		if (!target) {
			return;
		}

		// We also want to turn off any other items which are expanded.
		lists = YAHOO.util.Selector.query('#layout_LeftMenu ul.T2');

		for (x = 0; x < lists.length; x++) {
			lists[x].style.display =
			(lists[x] === target) ? 'block' : 'none';
		}
	});

