/******************************************
 * The CMS Collapsible List Class
 *
 * For showing/hiding FAQ answers & other lists.
 ******************************************/

onepica.CollapsibleList = Class.create({
	/**
	 * Constructor
	 *
	 * @param string listId: the ID of the DL element
	 */
	initialize: function (listId) {
		this.list = $(listId);

		this.list.select('dt').each(function (el) {
			el.observe('click', this.showHideItem.bindAsEventListener(this));
		}.bind(this));

		this.list.select('dd').each(function (el) {
			el.hide();
		});
	},

	/**
	 * Shows or hides the item.
	 *
	 * @param Event event
	 */
	showHideItem: function (event) {
		var dt = event.findElement('dt');
		if (dt.hasClassName('open')) {
			dt.removeClassName('open');
		}
		else {
			dt.addClassName('open');
		}
		dt.next('dd').toggle();
	}
});