// Properties
var iMaxHeight;
var iMinHeight;
var iIntervalTime = 30; // Animation speed
var iIntervalId, iTimeOutId = null;
var iInc, iDec;
var iAverage = (iMaxHeight * 50) / 100; // 70% of maximum height
var oLayer = null;

// ///////////////////////////// Dynamic Unfold/Fold layer effects ///////////////////////////

function UnfoldFoldLayer(sLayerId, iMinH, iMaxH){
	oLayer = document.getElementById(sLayerId);
	
	iMinHeight = iMinH;
	iMaxHeight = iMaxH;
	
	iInc = iMinHeight;
	iDec = iMaxHeight;
	
	// If the interval is running, it's cleared
	clearInterval(iIntervalId);
	
	if(oLayer.offsetHeight < iMaxHeight) {
		iIntervalId = setInterval("DynamicIncHeight()", iIntervalTime);
	} else if(oLayer.offsetHeight > iMinHeight){
		iIntervalId = setInterval("DynamicDecHeight()", iIntervalTime);
	}
}

// ///////////////////////////////// Height changes functions //////////////////////////////

function DynamicIncHeight(){
	if(iInc < iAverage){
		iInc += 10;
	} else {
		iInc += 25;
		if(iInc > iMaxHeight){
			iInc = iMaxHeight;
		}
	}
	
	ChangeHeight(iInc);
	
	if(iInc == iMaxHeight){
		clearInterval(iIntervalId);
	}
	
} // End of DynamicIncHeight function

function DynamicDecHeight(){
	if(iDec > iAverage){
		iDec -= 10;
	} else {
		iDec -= 25;
		if(iDec < iMinHeight){
			iDec = iMinHeight;
		}
	}
	
	ChangeHeight(iDec);
	
	if(iDec == iMinHeight){
		clearInterval(iIntervalId);
	}
	
} // End of DynamicDecHeight function

function ChangeHeight(iAmount){
	oLayer.style.height = iAmount + "px";
	
} // End of ChangeHeight function
