var cpRollSpaceTimeoutId;

function cpRollCookieSet(minutes){
	var d = new Date()
	d.setTime( d.getTime() + 1000 * 60 * minutes );
	document.cookie = "displayed=true;expires=" + d.toGMTString();
}

function cpRollCookieGet(){
	var c = document.cookie;
	if(c.indexOf("displayed=true") < 0) return false;
	return true;
}

function cpRollSpace( idContainer, idSubcontainer, direction, progress, min, max ){
	
	window.clearTimeout(cpRollSpaceTimeoutId)

	var myDate=new Date();
	
	var container = document.getElementById(idContainer);
	var subcontainer = document.getElementById(idSubcontainer);
	
	// subcontainer visible/hidden
	if( direction > 0 && progress >= 100 ) subcontainer.style.display = "block";
	else subcontainer.style.display = "none";
	
	// container visible/hidden
	if( direction < 0 && progress >= 100 ) container.style.display = "none";
	else container.style.display = "block";
	 
	if ( progress >= 100 ){
		return true;
	}
	
	var height = parseInt(container.style.height);
	var stepMax = 0.5;//0.5; 
	var stepMin = 0.1;//0.05;
	var step = (stepMax - stepMin)*(progress/100) + stepMin;
	var offset = 0;
	
	if( direction > 0 ){
		offset = ( max - height ) * step;
	}
	else offset = ( height - min ) * step * (-1);
	offset =  Math.round(offset);

	container.style.height = height + offset + "px";
	
	if( direction > 0 ) progress = Math.round( height / max * 100 ) + 1;
	else progress = 100 - Math.round( height / max * 100 ) + 1;
	
	cpRollSpaceTimeoutId = window.setTimeout("cpRollSpace( '"+idContainer+"', '"+idSubcontainer+"', "+direction+", "+progress+", "+min+", "+max+" )", 30);

}

/*
function cpRollSpaceDelay(minutes){

	

	var c = document.cookie;

	if(c.indexOf("displayed=true") < 0){
		var d = new Date()
		d.setTime( d.getTime() + 1000 * 60 * minutes );
		document.cookie = "displayed=true;expires=" + d.toGMTString();
		return true;
	}
	else{
		return false;		
	}
	
}

function cpRollSpace( idContainer, idSubcontainer, direction, progress, min, max ){
	
	window.clearTimeout(cpRollSpaceTimeoutId)

	var myDate=new Date();
	
	var container = document.getElementById(idContainer);
	var subcontainer = document.getElementById(idSubcontainer);
	
	// debugger
	// document.getElementById("info").innerHTML = progress + " " + parseInt(container.style.height) + " " + myDate.getTime();
	
	// subcontainer visible/hidden
	if( direction > 0 && progress >= 100 ) subcontainer.style.display = "block";
	else subcontainer.style.display = "none";
	
	// container visible/hidden
	if( direction < 0 && progress >= 100 ) container.style.display = "none";
	else container.style.display = "block";
	 
	if ( progress >= 100 ){
		return true;
	}
	
	if(1){
		var height = parseInt(container.style.height);
		var stepMax = 0.5;//0.5; 
		var stepMin = 0.1;//0.05;
		var step = (stepMax - stepMin)*(progress/100) + stepMin;
		var offset = 0;
		
		if( direction > 0 ){
			offset = ( max - height ) * step;
		}
		else offset = ( height - min ) * step * (-1);
		offset =  Math.round(offset);

		container.style.height = height + offset + "px";
		
		if( direction > 0 ) progress = Math.round( height / max * 100 ) + 1;
		else progress = 100 - Math.round( height / max * 100 ) + 1;
		
		cpRollSpaceTimeoutId = window.setTimeout("cpRollSpace( '"+idContainer+"', '"+idSubcontainer+"', "+direction+", "+progress+", "+min+", "+max+" )", 30);
	}	
}
*/