function expandObject(type, delay, step, direction)
{
	this.divList = new Array();
	this.openList = new Array();
	this.reexpand = new Array();
	this.toHeight = 0;
	this.currentHeight = 0;
	this.toWidth = 0;
    this.maxWidth = 0;
    this.maxHeight = 0;
	this.currentWidth = 0;
	this.activeDivName;
	this.openImage = '';
	this.closeImage = '';
	this.images = false;
	this.type = type;
	this.delay = (delay == null) ? 5 : delay;
	this.step = (step == null) ? 5 : step;
	this.direction = (direction == null) ? 'vertical' : direction;

	this.activateTimed = function ()
	{
		this.getDimensions(document.getElementById(this.activeDivName));
		this.expander();
	}
	
	this.addImages = function(openImage, closeImage)
	{
		this.openImage = openImage;
		this.closeImage = closeImage;
		this.images = true;
	}
	
	this.addObject = function(div, trigger)
	{
		this.divList.push(div);
		this.openList.push(false);
		if (this.type == 'timed')
		{
			this.activeDivName = div;
		}
		else
		{
			var thisEventDiv = document.getElementById(div + "Trigger");
			var f = this;
			if (thisEventDiv.addEventListener)
			{
				if (this.type == 'click')
				{
					thisEventDiv.addEventListener('click',function (e) {f.mouseEvent(e, div);}, false);
				}
				else
				{
					thisEventDiv.addEventListener('mouseover',function (e) {f.mouseEvent(e, div);}, false);
					thisEventDiv.addEventListener('mouseout',function (e) {f.mouseEvent(e, div);}, false);
				}
			}
			else if (thisEventDiv.attachEvent)
			{
				if (this.type == 'click')
				{
					thisEventDiv.attachEvent('onclick',function (e) {f.mouseEvent(e, div);});
				}
				else
				{
					thisEventDiv.attachEvent('onmouseover',function (e) {f.mouseEvent(e, div);});
					thisEventDiv.attachEvent('onmouseout',function (e) {f.mouseEvent(e, div);});
				}
			}
		}
	}
	
	this.closeOthers = function()
	{
		this.unexpander();
		if (this.images == true)
		{
			for (var i=0; i<this.divList.length; i++)
			{
				if (this.divList[i] != this.activeDivName)
				{
					document.getElementById(this.divList[i]+'Image').src = this.closeImage;
				}
			}
		}
	}

	this.unexpander = function ()
	{
		var continueTest = false;
		for (var i=0; i < this.divList.length; i++)
		{
			if (this.divList[i] != this.activeDivName && this.openList[i] == true)
			{
				var unexpandDiv = document.getElementById(this.divList[i]);
				if (unexpandDiv.offsetHeight > 0)
				{
					continueTest = true;
					var newHeight = unexpandDiv.offsetHeight - this.step;
					if (newHeight <= 0)
					{
						newHeight = 0;
						unexpandDiv.style.display = 'none';
						this.openList[i] = false;
					}
					unexpandDiv.style.height = newHeight + 'px';
				}
			}
		}
		if (continueTest == true)
		{
			var f = this;
			var unexpand = setTimeout(function () { f.unexpander();},this.delay);
		}
	}

	this.expander = function() {
	    if (this.activeDivName != '') {
	        var expandDiv = document.getElementById(this.activeDivName);
	        if (this.direction == 'vertical') {
	            if (this.currentHeight < this.toHeight) {
	                this.currentHeight += this.step;
	                expandDiv.style.height = this.currentHeight + 'px';
	                expandDiv.style.width = this.toWidth + 'px';
	                var f = this;
	                clearTimeout(this.reexpand[expandDiv]);
	                this.reexpand[expandDiv] = setTimeout(function() { f.expander(); }, this.delay);
	            }
	        }
	        else {
	            if (this.currentWidth < this.toWidth) {
	                this.currentWidth += this.step;
	                expandDiv.style.width = this.currentWidth + 'px';
	                expandDiv.style.height = this.toHeight + 'px';
	                var f = this;
	                clearTimeout(this.reexpand[expandDiv]);
	                this.reexpand[expandDiv] = setTimeout(function() { f.expander(); }, this.delay);
	            }
	        }
	    }
	}
	
	this.isMouseLeaveOrEnter = function (e, handler)
	{
		if (e.type != 'mouseout' && e.type != 'mouseover') return false;
		var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;
		while (reltg && reltg != handler) reltg = reltg.parentNode;
		return (reltg != handler);
	}
	
	this.getDimensions = function (expandDiv)
	{
		this.toHeight = 0;
		this.toWidth = 0;
		this.currentHeight = 0;
		this.currentWidth = 0;
		expandDiv.style.display = 'block';
        expandDiv.style.overflow = 'auto';
		if (this.direction == 'vertical')
		{
			expandDiv.style.height = 'auto';
		}
		else
		{
			expandDiv.style.width = 'auto';
		}
		if (this.maxHeight > 0 && expandDiv.offsetHeight > this.maxHeight)
        {
            this.toHeight = this.maxHeight;
        }
        else
        {
            this.toHeight = expandDiv.offsetHeight;
        }
		if (this.maxWidth > 0 && expandDiv.offsetWidth > this.maxWidth)
        {
            this.toWidth = this.maxWidth;
        }
        else
        {
            this.toWidth = expandDiv.offsetWidth;
        }
        expandDiv.style.visibility = 'hidden';
		expandDiv.style.display = 'none';
		if (this.direction == 'vertical')
		{
			expandDiv.style.height = '0px';
		}
		else
		{
			expandDiv.style.width = '0px';
		}
		expandDiv.style.visibility = 'visible';
		expandDiv.style.display = 'block';
		expandDiv.style.overflow = 'hidden';
	}
	
	this.mouseEvent = function (e, div)
	{
		var objectDiv = false;
		for (var i=0; i<this.divList.length; i++)
		{
			if (this.divList[i] == div)
			{
				objectDiv = true;
			}
		}
		if (objectDiv == true)
		{
			var expandDiv = document.getElementById(div);
			if (e.type == 'mouseout')
			{
				if (this.isMouseLeaveOrEnter(e, document.getElementById(div)))
				{
					this.activeDivName = '';
					this.closeOthers();
				}
			}
			else
			{
				if (expandDiv.style.display == 'block' && this.type == 'click')
				{
					this.activeDivName = '';
					this.closeOthers();
				}
				else
				{
					if (this.activeDivName != div)
					{
						this.activeDivName = div;
						for (var i=0; i < this.divList.length; i++)
						{
							if (this.divList[i] == div)
							{
								this.openList[i] = true;
							}
						}
						this.closeOthers();
						this.getDimensions(expandDiv);

						if (this.images == true)
						{
							document.getElementById(div+'Image').src = this.openImage;
						}
						this.expander();
					}
				}
			}
		}
	}
}