expandObj=new Array();
currentExpandWidth=0;
currentExpandHeight=0;
desiredExpandWidth=0;
desiredExpandHeight=0;
expandTimer=null;
expandInterval=2;
expandMaxVelocity=20;
collapseObj=new Array();
currentcollapseWidth=0;
currentcollapseHeight=0;
desiredcollapseWidth=0;
desiredcollapseHeight=0;
collapseTimer=null;
collapseInterval=expandInterval;
collapseMaxVelocity=expandMaxVelocity;

function toggleExpansion(src, expandTheWidth, expandTheHeight, collapseOthers) {
	if (src.style.display=="none") {
		expandThisObj(src, expandTheWidth, expandTheHeight);
		if (collapseOthers!="") {
			objs=collapseOthers.split(";");
			for (i=0;i<objs.length;i++) {
				vals=objs[i].split(":");
				col=document.getElementById(vals[0]);
				if (col.style.display!="none") collapseThisObj(col, vals[1], vals[2]);
			}
		}
	}else{
		collapseThisObj(src, expandTheWidth, expandTheWidth);
	}
}

function expandThisObj(src, expandTheWidth, expandTheHeight) {
	inlist=false;
	for (i=0;i<expandObj.length;i++) if (expandObj[i]==src) inlist=true;
	if (!inlist) {
		expandObj.push(new Array(src,expandTheWidth,expandTheHeight));
		//expandWidth.push(expandTheWidth);
		//expandHeight.push(expandTheHeight);
		if (expandTimer==null) startExpansion();
	}
}
function startExpansion() {
	currentExpandWidth=1;
	currentExpandHeight=1;
	expandObj[0][0].style.overflow='visible';
	expandObj[0][0].style.display='block';
	expandObj[0][0].style.height="";
	expandObj[0][0].style.width="";
	desiredExpandHeight=expandObj[0][0].offsetHeight;
	desiredExpandWidth=expandObj[0][0].offsetWidth;
	if (!expandObj[0][2]) currentExpandHeight=expandObj[0][0].offsetHeight;
	if (!expandObj[0][1]) currentExpandWidth=expandObj[0][0].offsetHeight;
	expandObj[0][0].style.overflow='hidden';
	expandObj[0][0].style.height=currentExpandHeight+"px";
	expandObj[0][0].style.width=currentExpandWidth+"px";
    expandTimer = setTimeout("doExpansion()",expandInterval);
}
function doExpansion() {
    thisObj=expandObj[0][0];
    dh=(desiredExpandHeight-currentExpandHeight)/2;
    if (dh>expandMaxVelocity) dh=expandMaxVelocity;
    if (dh<-expandMaxVelocity) dh=-expandMaxVelocity;
    dw=(desiredExpandWidth-currentExpandWidth)/2;
    if (dw>expandMaxVelocity) dw=expandMaxVelocity;
    if (dw<-expandMaxVelocity) dw=-expandMaxVelocity;
    if (dh<1 && dh>-1 && dw<1 && dw>-1) {
        currentExpandHeight=desiredExpandHeight;
        currentExpandWidth=desiredExpandWidth;
        expandObj[0][0].style.overflow='visible';
        clearTimeout(expandTimer);
        expandTimer=null;
        expandObj.shift();
    	thisObj.style.height=""
    	thisObj.style.width="";
        if (expandObj.length>0) startExpansion("");
    }else{
        expandTimer = setTimeout("doExpansion()",2);
        currentExpandHeight+=dh;
        currentExpandWidth+=dw;
    	thisObj.style.height=(currentExpandHeight)+"px";
    	thisObj.style.width=(currentExpandWidth)+"px";
    }
}




function collapseThisObj(src, collapseTheWidth, collapseTheHeight) {
	inlist=false;
	for (i=0;i<collapseObj.length;i++) if (collapseObj[i]==src) inlist=true;
	if (!inlist) {
		collapseObj.push(new Array(src,collapseTheWidth,collapseTheHeight));
		if (collapseTimer==null) startCollapse();
	}
}
function startCollapse() {
	currentCollapseHeight=collapseObj[0][0].offsetHeight;
	currentCollapseWidth=collapseObj[0][0].offsetWidth;
	desiredCollapseHeight=collapseObj[0][0].offsetHeight;
	desiredCollapseWidth=collapseObj[0][0].offsetWidth;
	if (collapseObj[0][2]) desiredCollapseHeight=0;
	if (collapseObj[0][1]) desiredCollapseWidth=0;
	collapseObj[0][0].style.overflow='hidden';
	collapseObj[0][0].style.height=currentCollapseHeight+"px";
	collapseObj[0][0].style.width=currentCollapseWidth+"px";
    collapseTimer = setTimeout("doCollapse()",collapseInterval);
}
function doCollapse() {
    thisObj=collapseObj[0][0];
    dh=(desiredCollapseHeight-currentCollapseHeight)/2;
    if (dh>collapseMaxVelocity) dh=collapseMaxVelocity;
    if (dh<-collapseMaxVelocity) dh=-collapseMaxVelocity;
    dw=(desiredCollapseWidth-currentCollapseWidth)/2;
    if (dw>collapseMaxVelocity) dw=collapseMaxVelocity;
    if (dw<-collapseMaxVelocity) dw=-collapseMaxVelocity;
    if (dh<1 && dh>-1 && dw<1 && dw>-1) {
        currentCollapseHeight=desiredCollapseHeight;
        currentCollapseWidth=desiredCollapseWidth;
        collapseObj[0][0].style.display='none';
        clearTimeout(collapseTimer);
        collapseTimer=null;
        collapseObj.shift();
    	thisObj.style.height=""
    	thisObj.style.width="";
        if (collapseObj.length>0) startCollapse("");
    }else{
        collapseTimer = setTimeout("doCollapse()",2);
        currentCollapseHeight+=dh;
        currentCollapseWidth+=dw;
    	thisObj.style.height=(currentCollapseHeight)+"px";
    	thisObj.style.width=(currentCollapseWidth)+"px";
    }
}
