animationflag = new Array();

function animatedcollapse(divId, animatetime, persistexpand, initstate, im){
	if ((!animationflag[divId]||animationflag[divId]==false) && (typeof this.runtimer=="undefined" || this.runtimer==null)) {
	this.divId=divId
	this.divObj=document.getElementById(divId)
	this.timelength=animatetime
	this.im=im
	this.initstate=initstate
	this.contentheight=parseInt(this.divObj.style.height)
	var thisobj=this
	if (isNaN(this.contentheight)) thisobj._getheight();
	}
}
animatedcollapse.prototype._getheight=function(){
//	tmpn = this.divObj.cloneNode(true)
//	tmpn.style.visibility="hidden"
//	this.contentheight = parseInt(tmpn.offsetHeight)
//	tmpn = null
	this.contentheight = parseInt(this.divObj.offsetHeight)
}
animatedcollapse.prototype._slideengine=function(dirup,im) {
	var elapsed = new Date().getTime()-this.startTime //get time animation has run
	var thisobj = this
	if (elapsed<this.timelength) { //if time run is less than specified length
		var distancepercent= animatedcollapse.curveincrement(elapsed/this.timelength)
		if (dirup) distancepercent = 1 - distancepercent
		distancepercent = parseInt(distancepercent * this.contentheight)
		if (distancepercent < 1) {
			distancepercent = 1
		} else if ((distancepercent > 1) && (this.divObj.style.display == "none")) {
			this.divObj.style.display = ""
//			if (!dirup) this.im.src = "/images/arrow_open.png"
			if (!dirup) this.im.src = this.im.src.replace(/arrow_close.png/, "arrow_open.png")
		}
		this.divObj.style.height = distancepercent +"px"
		this.runtimer = setTimeout(function(){thisobj._slideengine(dirup)}, 10)
	}
	else { //if animation finished
		if (dirup) {
//			this.im.src = "/images/arrow_close.png"
			this.im.src = this.im.src.replace(/arrow_open.png/, "arrow_close.png")
			this.divObj.style.display = "none"
		}
		this.divObj.style.height = (dirup) ? "1px" : "auto"
		this.runtimer=null
		animationflag[this.divId] = false
	}
}
animatedcollapse.prototype.slidedown=function(im) {
	if ((!animationflag[this.divId]||animationflag[this.divId]==false) && (typeof this.runtimer=="undefined" || this.runtimer==null)) { //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) { //if content height not available yet (until window.onload)
//			alert("Please wait until document has fully loaded then click again")
		}
		else if (parseInt(this.divObj.style.height) == 1) { //if content is collapsed
			animationflag[this.divId] = true
			this.contentheight = parseInt(this.divObj.getAttribute('lastKnownHeight'))
			this.startTime=new Date().getTime() //Set animation start time
			this._slideengine(false,im)
		}
	}
}
animatedcollapse.prototype.slideup=function(im) {
	if ((!animationflag[this.divId]||animationflag[this.divId]==false) && (typeof this.runtimer=="undefined" || this.runtimer==null)) { //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) { //if content height not available yet (until window.onload)
//			alert("Please wait until document has fully loaded then click again")
		}
		else if (parseInt(this.divObj.style.height) != 0) { //if content is expanded
			animationflag[this.divId] = true
			this.divObj.style.overflow = 'hidden'
			if (isNaN(parseInt(this.divObj.style.height))) {
				this.divObj.style.height = this.contentheight + 'px'
			}
			this.divObj.setAttribute('lastKnownHeight',this.contentheight)
			this.startTime=new Date().getTime()
			this._slideengine(true,im)
		}
	}
}
animatedcollapse.curveincrement=function(percent) {
	return ((1-Math.cos(percent*Math.PI)) / 2) //return cos curve based value from a percentage input
}
function slideUpSlideDown(o,t) {
	img = o.getElementsByTagName('IMG')[0];
	var a = new animatedcollapse(t, 1000, false, 'block', img);
	if (img.src.indexOf('arrow_open.png') > 0) {
		a.slideup();
//		img.src = '/images/arrow_close.png';
	} else {
		a.slidedown();
//		img.src = '/images/arrow_open.png';
	}
	return false;
}
