var DCD_buffer=40;
var DCD_maxHeight;
var slideInUse = new Array();
var zippy = 0;

function DCD_showHide(obj,which){
	outer_div = document.getElementById('wrap_'+obj);
	inner_div = document.getElementById(obj);
	DCD_maxHeight = inner_div.offsetHeight+DCD_buffer;
	if(which==1){
		if(outer_div.style.visibility!='visible'){Slide('wrap_'+obj).down();}
	} else {
		if(outer_div.style.visibility=='visible'){Slide('wrap_'+obj).up();}
	}
}



function Slide(objId, options) {
	this.obj = document.getElementById(objId);
	this.duration = 1;
	this.height = DCD_maxHeight;//parseInt(this.obj.style.height);

	if(typeof options != 'undefined') { this.options = options; } else { this.options = {}; }
	if(this.options.duration) { this.duration = this.options.duration; }
		
	this.up = function() {
		this.curHeight = this.height;
		this.newHeight = '1';
		if(slideInUse[objId] != true) {
			var finishTime = this.slide();
			window.setTimeout("Slide('"+objId+"').finishup("+this.height+");",finishTime);
		}
	}
	
	this.down = function() {
		this.newHeight = this.height;
		this.curHeight = '1';
		if(slideInUse[objId] != true) {
			this.obj.style.height = '1px';
			this.obj.style.display = 'block';
			this.obj.style.visibility = 'visible';
			this.slide();
		}
	}
	
	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++) {
			this.curHeight = this.curHeight - frameSizes[i];
			window.setTimeout("document.getElementById('"+objId+"').style.height='"+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;
	}
	
	this.finishup = function(height) {
		this.obj.style.display = 'none';
		this.obj.style.visibility = 'hidden';
		this.obj.style.height = height + 'px';
	}
	
	return this;
}

function totop() {
	if (zippy != 0) {
		scrollTo(0,0);
	}  else  {
		var ts = 0;
		if (document.layers) {
			ts = window.pageYOffset;
		}  else if (document.body.scrollTop)  {
			ts = document.body.scrollTop;
		}  else  {
			ts = window.pageYOffset;
		}
		if (ts>0)  {
			var nv = (ts - 5) * 0.2;
			if (nv < 1) nv = 1;
			scrollBy(0,- nv);
			setTimeout("totop()",20);
		}else{
			scrollTo(0,0);
		}
	}
}

