	// Animation class library Copyright (c) 2004 by Third Dimension Limited.
	
	// Animations
	var animationTime = 500;
	var animation1, animation2;
	var openElement;
	
	function Animation(objectName, animatingElement, startSize, finishSize)
	{
		// Record member variables
		this.objectName = objectName;
		this.animatingElement = animatingElement;
		this.startSize = startSize;
		this.finishSize = finishSize;

		// Record start time and start interval
		this.startTime = new Date();
		this.PerformAnimate = m_PerformAnimate;
		this.timerID = window.setInterval(this.objectName + ".PerformAnimate()", 20);
	}
	
	function BeginAnimateOpen(elm)
	{
		// Record this element as being the new open element
		openElement = elm;
		
		// Record the start time and get the fully-opened size of this element
		startTime = new Date();
		elm.style.display = "block";
		startSize = 1;
		finishSize = elm.offsetHeight;
		elm.style.overflow = "hidden";
		elm.style.height = startSize + "px";
		
		animation2 = new Animation("animation2", elm, startSize, finishSize);
	}
	
	function m_PerformAnimate()
	{
		var degtorad = 0.01745;
		
		// Get the number of elapsed milliseconds and divide in to the total animation time
		var now = new Date();
		var elapsedTime = now - this.startTime;
		var elapsed = elapsedTime / animationTime;
		if (elapsed > 1)
			elapsed = 1;
		
		// Convert to degrees, then radians, then get cosine for smooth animation
		elapsed *= 90;
		elapsed *= degtorad;
		elapsed = Math.cos(elapsed);
		elapsed = 1 - elapsed;
		
		// Apply animation height
		var currentSize = this.startSize + (this.finishSize - this.startSize) * elapsed;
		this.animatingElement.style.height = currentSize + "px";
		
		// Stop animation if we're done
		if (elapsedTime >= animationTime)
		{
			window.clearInterval(this.timerID);
			if (this.finishSize == 1)
			{
				// Completely hide the element after restoring its size
				this.animatingElement.style.height = this.startSize + "px";
				this.animatingElement.style.display = "none";
			}
			else
			{
				// Restore the element to its full size
				this.animatingElement.style.height = finishSize + "px";
			}
		}
	}
	
	function AnimateVisibility(el)
	{
		// If we're on a legacy browser, fall back to old style toggling
		if (!document.getElementById)
		{
			var elm;
			if (document.all)
				elm = document.all[el];
			else if (document.layers)
				elm = document.layers[el];
			if (elm.style.display == "none")
				elm.style.display = "block";
			else
				elm.style.display = "none";
			return;
		}
		
		// Turn the id of the element in to the element itself
		var elm = document.getElementById(el);
		
		// If there is already an element open, start its close animation
		if (openElement)
		{
			var currentSize = openElement.offsetHeight;
			animation1 = new Animation("animation1", openElement, currentSize, 1);
		}
		
		// Start opening animation
		if (openElement != elm)
			BeginAnimateOpen(elm);
		else
			openElement = null;
	}
