/*
	Expandable Item

	last updated 2007-11-24
*/

function ExpandClass() {

	this.lastShownExpandableItemIDNames = [];
	
	// expand the given item, collapsing the previously-expanded item in the same group
	this.expandItem = function(groupName,itemIDSuffix,doNotCollapseShown) {
		var lastShownExpandableItemIDName = this.lastShownExpandableItemIDNames[groupName];
		if (lastShownExpandableItemIDName!=groupName+itemIDSuffix) {
			// collapse current item, expand new item,
			if (lastShownExpandableItemIDName) Browser.setStyleProperty(lastShownExpandableItemIDName,"display","none");
			lastShownExpandableItemIDName = groupName+itemIDSuffix;
			Browser.setStyleProperty(lastShownExpandableItemIDName,"display","block");
			this.lastShownExpandableItemIDNames[groupName] = lastShownExpandableItemIDName;
		} else {
			// collapse or expand the item that was previously expanded or collapsed
			// i.e. the user has clicked on the same item twice in a row
			var currentState = Browser.getStyleProperty(lastShownExpandableItemIDName,"display");
			if (currentState==null || currentState=="none") {
				Browser.setStyleProperty(lastShownExpandableItemIDName,"display","block");
			} else if (!doNotCollapseShown) {
				Browser.setStyleProperty(lastShownExpandableItemIDName,"display","none");
			}
		}
	}
	
	// mark this item has started in a expanded state
	this.itemStartsExpanded = function(groupName,itemIDSuffix) {
		var expandableItemIDName = groupName+itemIDSuffix;
		Browser.setStyleProperty(expandableItemIDName,"display","block");
		this.lastShownExpandableItemIDNames[groupName] = expandableItemIDName;
	}
	
	// collapse all items in a group
	this.collapseItems = function(groupName) {
		var lastShownExpandableItemIDName = this.lastShownExpandableItemIDNames[groupName];
		if (lastShownExpandableItemIDName) {
			Browser.setStyleProperty(lastShownExpandableItemIDName,"display","none");
			this.lastShownExpandableItemIDNames[groupName] = null;
		}
	}
	
	return(this);
}

var Expand = new ExpandClass();
