/******************************************
 * The CMS Collapsible List Class
 *
 * For showing/hiding FAQ answers & other lists.
 ******************************************/

if (typeof provident == "undefined" || !provident) {
    var provident = {};
}

provident.CollapsibleList = function () {
	return {
		/**
		 * Constructor
		 *
		 * @param string containerId: the ID of the container element
		 */
		initialize: function (container) {
			var items = $J(container).find("dl dt");
			for (var i = 0; i < items.length; i++) {
				$J(items.get(i)).bind("click", this.showHideItem);
			}
		},

		/**
		 * Shows or hides the adjacent dd of the click dl.
		 */
		showHideItem: function () {
			var parent = $(this.parentNode);
			if (parent.hasClass("open"))
				parent.removeClass("open");
			else
				parent.addClass("open");
			
			//Adjust the height as the page grows
			try { screenManager.adjustColumnHeights(); } catch(err) { }
			
		},

		/**
		 * Shows or hides the adjacent dd of the click dl.
		 */
		showHideAll: function (parentId) {
			if(parentId && typeof parentId == 'string') {
				var items = $J('#' + parentId + ' dl dt');
			} else {
				var items = $J('dl dt');
			}
			
			if(items.length) {
				var isOpen = $(items.get(0).parentNode).hasClass("open") ? true : false;
				for (var i = 0; i < items.length; i++) {
					isOpen ? $(items.get(i).parentNode).removeClass("open") : $(items.get(i).parentNode).addClass("open");
				}
			
				//Adjust the height as the page grows
				try { screenManager.adjustColumnHeights(); } catch(err) { }
			}
		}
	};
}();

/** 
 * Corresponding CSS
 ************************************************
.collapsible-list {}
	.collapsible-list dl {
		border-bottom: 1px solid #c1c1c1;
		padding: 20px 0;
		color: #666766;
	}
		.collapsible-list dl dt {
			display: inline;
			cursor: pointer;
			font-weight: bold;
			padding-right: 13px;
			background: transparent url(../images/icons/green-arrow.gif) right center no-repeat;
		}
			.collapsible-list dl.open dt { background-image: url(../images/icons/green-arrow_down.gif); }
		.collapsible-list dl dd { 
			padding-top: 10px;
			display: none; 
		}
			.collapsible-list dl.open dd { display: block; }

 *************************************************/
