var slideInUse = new Array();

function DivSlider(objId, options){
	this.obj = document.getElementById(objId);
	this.objId = objId;
	this.duration = 1;
	this.inUse = false;
	this.options = options ? options : new Object;
}

DivSlider.prototype.up = 
		function(){
			this.height = parseInt(this.obj.style.height);
			this.curHeight = this.height;
			this.newHeight = '1';
			if(!this.inUse) {
				var finishTime = this.slide();
				window.setTimeout(this.objId+".finishup("+this.height+");",finishTime);
			}
		};

DivSlider.prototype.down = 
		function() {
			if(this.options.startFunction){
				window.setTimeout(this.options.startFunction + '()',0);
			}
			this.height = parseInt(this.obj.style.height);
			this.newHeight = this.height;
			this.curHeight = '1';
			if(!this.inUse) {
				this.obj.style.height = '1px';
				this.obj.style.display = 'block';
				this.slide();
			}
		};


DivSlider.prototype.slide =
		function() {
			this.inUse = true;
			var frames = 30 * this.duration; // Running at 30 fps
			
			var tIncrement = (this.duration*1000) / frames;
			tIncrement = Math.round(tIncrement);
			var sIncrement = (this.curHeight-this.newHeight) / frames;
			
			var frameSizes = new Array();
			for(var i=0; i < frames; i++) {
				if(i < frames/2) {
					frameSizes[i] = (sIncrement * (i/frames))*4;
				} else {
					frameSizes[i] = (sIncrement * (1-(i/frames)))*4;
				}
			}
			
			for(var i=0; i < frames; i++) {
				this.curHeight = this.curHeight - frameSizes[i];
				window.setTimeout("document.getElementById('"+this.objId+"').style.height='"+Math.round(this.curHeight)+"px';",tIncrement * i);
			}
			
			window.setTimeout(this.objId+".inUse = false;",tIncrement * i);
			
			return tIncrement * i;
		};

	
DivSlider.prototype.finishup = 
		function(height) {
			this.obj.style.display = 'none';
			this.obj.style.height = height + 'px';
			if(this.options.endFunction){
				window.setTimeout(this.options.endFunction + '()',0);
			}
		};
