function ToggleImage(ImageLocation)
{
	var Source = document.getElementById(ImageLocation).src;
	var StringEnd = Source.lastIndexOf("_") + 1;
	if(Source.substr(StringEnd) == "inactive.gif")
	{
		document.getElementById(ImageLocation).src = Source.substr(0, StringEnd) + "active.gif";
	}
	else
	{
		document.getElementById(ImageLocation).src = Source.substr(0, StringEnd) + "inactive.gif";
	}
}



var Location = new Array(); // ID of the Expanding/Collapsing Div
var Path = new Array(); // Direction of Expansion
var IsMoving= new Array(); // If item is moving
var Dimension = new Array(); // Original Dimension
var TimerStart = new Array();
var TimerID = new Array();
var Elapsed = new Array();

var MoveSpeed = 10; // How many pixels to move per interval
var TimerLength = 0; // Interval

function ExpandCollapse(LocationName, Direction)
{
	if(document.getElementById(LocationName).style.display != "none")
	// if expanded
	{
		Collapse(LocationName, Direction);
	}
	// if not expanded
	else
	{
		Expand(LocationName, Direction);
	}
}

function Expand(LocationName, Direction)
{
	if(IsMoving[LocationName])
	{
		return;
	}
	if(document.getElementById(LocationName).style.display != "none")
	{
    	return; // Redundant check in case called directly.
	}
	Location[LocationName] = document.getElementById(LocationName);
	IsMoving[LocationName] = true;
    Path[LocationName] = Direction;
	if(Path[LocationName] == "down")
	{
		Dimension[LocationName] = parseInt(Location[LocationName].style.height);
		Location[LocationName].style.height = "0px";
	}
	if(Path[LocationName] == "up")
	{
		Dimension[LocationName] = parseInt(Location[LocationName].style.height);
		Location[LocationName].style.height = "0px";
	}
	if(Path[LocationName] == "left")
	{
		Dimension[LocationName] = parseInt(Location[LocationName].style.width);
		Location[LocationName].style.width = "0px";
	}
	if(Path[LocationName] == "right")
	{
		Dimension[LocationName] = parseInt(Location[LocationName].style.width);
		Location[LocationName].style.width = "0px";
	}
	TimerStart[LocationName] = (new Date()).getTime();
	Location[LocationName].style.display = "block";
	TimerID[LocationName] = setInterval('Expanding(\'' + LocationName + '\');',TimerLength);
}

function Collapse(LocationName, Direction)
{
	if(IsMoving[LocationName])
	{
		return;
	}
	if(document.getElementById(LocationName).style.display != "block")
	{
    	return; // Redundant check in case called directly.
	}
	Location[LocationName] = document.getElementById(LocationName);
    IsMoving[LocationName] = true;
    Path[LocationName] = Direction;
	if(Path[LocationName] == "down")
	{
		Dimension[LocationName] = parseInt(Location[LocationName].style.height);
	}
	if(Path[LocationName] == "up")
	{
		Dimension[LocationName] = parseInt(Location[LocationName].style.height);
	}
	if(Path[LocationName] == "left")
	{
		Dimension[LocationName] = parseInt(Location[LocationName].style.width);
	}
	if(Path[LocationName] == "right")
	{
		Dimension[LocationName] = parseInt(Location[LocationName].style.width);
	}

	TimerStart[LocationName] = (new Date()).getTime();
	Location[LocationName].style.display = "block";
	TimerID[LocationName] = setInterval('Collapsing(\'' + LocationName + '\');',TimerLength);
}

function Expanding(LocationName)
{
	if((Path[LocationName] == "down" || Path[LocationName] == "up")&&(parseInt(Location[LocationName].style.height) >= Dimension[LocationName]))
	{
		ExpandCollapseCleanup(LocationName, "Expand");
	}
	else if((Path[LocationName] == "left" || Path[LocationName] == "right")&&(parseInt(Location[LocationName].style.width) >= Dimension[LocationName]))
	{
		ExpandCollapseCleanup(LocationName, "Expand");
	}
	else
	{
		if(Path[LocationName] == "down")
		{
			Location[LocationName].style.height = parseInt(Location[LocationName].style.height) + MoveSpeed + "px";
		}
		if(Path[LocationName] == "up") //repositions if needed
		{
			Location[LocationName].style.height = parseInt(Location[LocationName].style.height) + MoveSpeed + "px";
			Location[LocationName].parentNode.style.top = parseInt(Location[LocationName].parentNode.style.top) - MoveSpeed + "px";
		}
		if(Path[LocationName] == "left")
		{
			Location[LocationName].style.width = parseInt(Location[LocationName].style.width) + MoveSpeed + "px";
		}
		if(Path[LocationName] == "right")
		{
			Location[LocationName].style.width = parseInt(Location[LocationName].style.width) + MoveSpeed + "px";
			Location[LocationName].parentNode.style.left = parseInt(Location[LocationName].parentNode.style.left) - MoveSpeed + "px";
		}
	}
	return;
}

function Collapsing(LocationName)
{
	if((Path[LocationName] == "down" || Path[LocationName] == "up")&&(parseInt(Location[LocationName].style.height) <= 0))
	{
		ExpandCollapseCleanup(LocationName, "Collapse");
	}
	else if((Path[LocationName] == "left" || Path[LocationName] == "right")&&(parseInt(Location[LocationName].style.width) <= 0))
	{
		ExpandCollapseCleanup(LocationName, "Collapse");
	}
	else 
	{
		if(Path[LocationName] == "down")
		{
			Location[LocationName].style.height = parseInt(Location[LocationName].style.height) - MoveSpeed + "px";
		}
		if(Path[LocationName] == "up") //repositions as needed
		{
			Location[LocationName].style.height = parseInt(Location[LocationName].style.height) - MoveSpeed + "px";
			Location[LocationName].parentNode.style.top = parseInt(Location[LocationName].parentNode.style.top) + MoveSpeed + "px";
		}
		if(Path[LocationName] == "left")
		{
			Location[LocationName].style.width = parseInt(Location[LocationName].style.width) - MoveSpeed + "px";
		}
		if(Path[LocationName] == "right") // repositions as needed
		{
			Location[LocationName].style.width = parseInt(Location[LocationName].style.width) - MoveSpeed + "px";
			Location[LocationName].parentNode.style.left = parseInt(Location[LocationName].parentNode.style.left) + MoveSpeed + "px";
		}
	}
	return;
}

function ExpandCollapseCleanup(LocationName, Status)
{
	if(Status == "Expand")
	{
		if(Path[LocationName] == "down")
		{
			Location[LocationName].style.height = Dimension[LocationName] + "px";
		}
		if(Path[LocationName] == "up")
		{
			Location[LocationName].style.height = Dimension[LocationName] + "px";
		}
		if(Path[LocationName] == "left")
		{
			Location[LocationName].style.width = Dimension[LocationName] + "px";
		}
		if(Path[LocationName] == "right")
		{
			Location[LocationName].style.width = Dimension[LocationName] + "px";
		}
	}
	else
	{
		if(Path[LocationName] == "down")
		{
			Location[LocationName].style.height = Dimension[LocationName] + "px";
		}
		if(Path[LocationName] == "up")
		{
			Location[LocationName].parentNode.style.top = parseInt(Location[LocationName].parentNode.style.top) - parseInt(Location[LocationName].style.height) + "px";
			Location[LocationName].style.height = Dimension[LocationName] + "px";
		}
		if(Path[LocationName] == "left")
		{
			Location[LocationName].style.width = Dimension[LocationName] + "px";
		}
		if(Path[LocationName] == "right")
		{
			Location[LocationName].parentNode.style.left = parseInt(Location[LocationName].parentNode.style.left) + parseInt(Location[LocationName].style.width) + "px";
			Location[LocationName].style.width = Dimension[LocationName] + "px";
		}
		Location[LocationName].style.display = "none";
	}
	clearInterval(TimerID[LocationName]);
	delete(Location[LocationName]);
	delete(Path[LocationName]);
	delete(IsMoving[LocationName]);
	delete(Dimension[LocationName]);
	delete(TimerStart[LocationName]);
	delete(TimerID[LocationName]);
	delete(Elapsed[LocationName]);
	return;
}
