var count = 0;
var expanded= null;
var working = 0;


function change_state(height, id){
	//alert(id);
	current_height = parseInt(document.getElementById(id).offsetHeight);
	if (working==0){
	if (current_height > 0){
		expanded = null;
		compress(height, id);
	}
	else{
		if(expanded){
			compress(height,expanded);
			expand_adv(height,id,expanded);
		}else{
			expand(height, id);
		}
		expanded = id;
	}
	}
}

function expand(height, id){
    if($(id+'_but'))
    $(id+'_but').className='filter_button_active';
	current_height = parseInt(document.getElementById(id).offsetHeight);

	smooth = .2 * (height - current_height);
	if (smooth > 0){
		smooth = Math.ceil(smooth);
	}
	else{
		smooth = Math.floor(smooth);
	}

	if (current_height == 0){
		count = 0;

	}
	else{
		count++;

	}

	document.getElementById(id).style.height = current_height + smooth + 'px';
	if (current_height < height && count < 7){
		working = 1;
		setTimeout('expand(\''+height+'\',\''+id+'\')', 5);


	}
	else if (count >= 7){
		document.getElementById(id).style.height = height + 'px';

		working = 0;
	}
}


function expand_adv(height, id,expanded){
    if($(id+'_but'))
    $(id+'_but').className='filter_button_active';
	current_height = parseInt(document.getElementById(id).offsetHeight);
	expanded_height = parseInt(document.getElementById(expanded).offsetHeight);

	if(expanded_height==0){
	smooth = .2 * (height - current_height);
	if (smooth > 0){
		smooth = Math.ceil(smooth);
	}
	else{
		smooth = Math.floor(smooth);
	}

	if (current_height == 0){
		count = 0;

	}
	else{
		count++;

	}
	document.getElementById(id).style.height = current_height + smooth + 'px';
	if (current_height < height && count < 7){
		setTimeout('expand(\''+height+'\',\''+id+'\')', 5);
	}
	else if (count >= 7){
		document.getElementById(id).style.height = height + 'px';
		working = 0;
	}

	}
	else{
		working = 1;
		setTimeout('expand_adv(\''+height+'\',\''+id+'\',\''+expanded+'\')',10);
	}
}




function compress(height, id){
    if($(id+'_but'))
    $(id+'_but').className='filter_button';
	current_height = parseInt(document.getElementById(id).offsetHeight);

	smooth = .2 * current_height;
	if (smooth > 0){
		smooth = Math.ceil(smooth);
	}
	else{
		smooth = Math.floor(smooth);
	}

	if (current_height == height){
		count = 0;

	}
	else{
		count++;

	}
	document.getElementById(id).style.height = current_height - smooth + 'px';
	if (current_height > 0 && count < 72){
		working = 1;
		setTimeout('compress(\''+height+'\',\''+id+'\')', 5);
	}
	else if (count >= 7){
		working = 0;
		document.getElementById(id).style.height ='0px';
	}
}

function pausecomp(millis){
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis);
}