/* плавное открытие блоков */

var curr_row = '';
var curtainStep = 10; 
var moving_digit = 0;
var check_height = 0;// высчитывать размер выпадающего блока	
var check_step_IE = 7;
var check_step_ALL = 10;
var koryto = new Object;

var start_height;
var end_height;
var if_opened;
var not_auto_height = 0;

function razvorot(obj, check_height, not_auto_height, click_obj, click_func)
{	
	if_opened = koryto[obj][2];
	if(check_height && gebi(obj+'_innerdiv').innerHTML != "")
	{
		div = gebi(obj+'_innerdiv');
		div_h = gebi(obj+'_hidden');//вспомогательный div для посчета размера высоты выпадающего блока, который должен иметь класс "hidden_div" и иметь внутриний div		
		if(div_h && div_h.hasChildNodes() && div.style.display == 'none')
		{
			div_h_p = div_h.firstChild;
			if(div_h_p.nodeName == "DIV")
			{
				div_h_p.innerHTML = div.innerHTML;
				height = div_h_p.offsetHeight;	
				div_h_p.innerHTML = '';
			}
			else
				if(div.style.display == 'none')
				{
					div.style.display = 'block';		
					height = div.offsetHeight;		
					div.style.display = 'none';			
				}
				else height = div.offsetHeight;
		}
		else
			if(div.style.display == 'none')
			{
				div.style.display = 'block';		
				height = div.offsetHeight;		
				div.style.display = 'none';			
			}
			else height = div.offsetHeight;
		if(height)
		{
			if(if_opened) koryto[obj][0] = height;
			else koryto[obj][1] = height;
			step = isIE ? check_step_IE : check_step_ALL;
			curtainStep = parseInt(height/step);
			if(curtainStep < 3) curtainStep = 3;
		}
	}
	
	start_height = koryto[obj][0];
	end_height = koryto[obj][1];	
	razvorot_deal(obj, start_height, end_height, start_height,0, not_auto_height, click_obj, click_func);
}

function razvorot_deal(obj, height1, height2, moving_digit, started, not_auto_height, click_obj, click_func)
{		
	var goon = '1';
	if (height1 < height2)
		if (started == 0)
		{ 
			var moving_digit = height1;
			moving_digit += curtainStep;				
		}
		else 
		{
			if (moving_digit < height2)	
			{ 		
				moving_digit += curtainStep;
				goon = 1;
			}
			else 
			{ 
				koryto[obj][2] = 1;						
				gebi(obj+'_innerdiv').style.display = 'block';
				moving_digit = not_auto_height ? height2 : 'auto';			
				goon = 0;
				click_obj.onclick = function onclick(event) { click_func(click_obj); return false; } 
			}	
		}
	if (height1 > height2)
		if (started == 0)
		{ 
			var moving_digit = height1;				
			gebi(obj).style.height = moving_digit;
			gebi(obj+'_innerdiv').style.display = 'none'; 
			moving_digit -= curtainStep;
		}
		else 
		{
			if (moving_digit > height2 && moving_digit>=curtainStep)	
			{ 		
				moving_digit -= curtainStep;
				goon = 1;						
			}
			else
			{
				moving_digit = 0;
				koryto[obj][2] = 0;
				goon = 0;
				click_obj.onclick = function onclick(event) { click_func(click_obj); return false; }
			}
		}	
		document.getElementById(obj).style.height = moving_digit;	
		if(goon == 1) setTimeout(function() { razvorot_deal(obj, height1, height2, moving_digit, 1, not_auto_height, click_obj, click_func) }, 1); 
} 
