var slideInUse = new Array();

function Slide(objId, options) {
	this.obj = document.getElementById(objId);
	this.duration = 1;
	this.width = parseInt(this.obj.style.width);
	var element = document.getElementById(objId);
	var currentDisplay = element.style.width;

		if(typeof options != 'undefined') { this.options = options; } else { this.options = {}; }
		if(this.options.duration) { this.duration = this.options.duration; }
			
		this.up = function() {
			if(this.width > 800)
			{
				this.curHeight = this.width;
				this.newHeight = this.width-200;
				if(slideInUse[objId] != true) {
					var finishTime = this.slide();
					window.setTimeout("Slide('"+objId+"').finishup("+this.width+");",finishTime);
				}
			} else {
			alert('Cannot make content area any thinner than it currently is.');
			}
		}
		
		this.down = function() {
			if(this.width < 3000)
			{
				this.newHeight = this.width+200;
				this.curHeight = this.width;
				if(slideInUse[objId] != true) {
					this.obj.style.width = this.width+'px';
					this.obj.style.display = 'block';
					this.slide();
				}
			} else {
			alert('Content area has reached the maximum allowable width.');
			}
		}
		
		this.slide = function() {
			slideInUse[objId] = true;
			var frames = 30 * duration; // Running at 30 fps
	
			var tIncrement = (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++) {
				//alert(this.curHeight);
				this.curHeight = this.curHeight - frameSizes[i];
				window.setTimeout("document.getElementById('"+objId+"').style.width='"+Math.round(this.curHeight)+"px';",tIncrement * i);
			}
			
			window.setTimeout("delete(slideInUse['"+objId+"']);",tIncrement * i);
			
			if(this.options.onComplete) {
				window.setTimeout(this.options.onComplete, tIncrement * (i-2));
			}
			
			return tIncrement * i;
		}
		
		return this;
}