var visibleBlock = new Array();

var maxlevel  = 0;
var rollInc   = 5;
var rollDelay = 20;

function showCateg(prefix, link)
{
	showSubcateg(prefix, link);
}

function showSubcateg(prefix, link)
{
	// hide the current block
	level = prefix.split('-').length;
	if(level>maxlevel)
		maxlevel = level;
	
	for(i=maxlevel; i>=level; i--)
	{
		if( visibleBlock[i] )
		{
			if(visibleBlock[i] == prefix)
			{
				window.location = link;
				return;
			}
				
			oldBlock = window.document.getElementById(visibleBlock[i]);
			//oldBlock.style.display = 'none';
			hideCateg(visibleBlock[i]);
			visibleBlock[i] = 0;
		}
	}
	
	theContent = window.document.getElementById(prefix);
	
	startCategAnimation(prefix);
	
	if(theContent)
	{
		theContent.style.display = 'block';
		visibleBlock[level] = prefix;
	}
	
}


function startCategAnimation(id)
{
	theDiv = window.document.getElementById(id);
	
	if( !theDiv )
		return;
		
	theUl  = theDiv.getElementsByTagName('ul');
	
	theUl = theUl[0];
	
	theDiv.style.height     = '0px';
	theDiv.style.visibility = 'visible';
	theDiv.style.display    = 'block'; 
	theDiv.style.position   = 'relative';

	theHeight = theUl.offsetHeight;
	
	categAnimation(id, theHeight, rollInc, rollDelay);
}

function hideCateg(id)
{

	theDiv = window.document.getElementById(id);


	if( !theDiv )
		return;
		
	categAnimation(id, 0, -2*rollInc, rollDelay);

}

function categAnimation(id, fh, inc, delay)
{
	//alert("entry:\nid:" + id + '\nfh:' + fh + '\ninc:' + inc + '\ndelay:' + delay);
	
	x = window.document.getElementById(id);
	
	hh = parseInt(x.offsetHeight);
	
	if(fh!=0)
		r = Math.abs((fh-hh)/fh);
	else
		r = 1;
	
	hh = hh + Math.ceil((r*4.5)*inc);
	if( (inc>0 && hh>fh) || (inc<0 && hh<fh))
		hh = fh;
		
	x.style.height = hh + 'px';
	
	if( (inc>0 && hh<fh) || (inc<0 && hh>fh) )
		setTimeout("categAnimation('" + id + "'," + fh + ", " + inc + "," + delay + ")", delay);
	else
	{
		if(inc<0)
			x.style.height = '0';
		else
		{
			x.style.height = '100%';
			//x.style.minHeight = fh + 'px';
		}
	}
	
}

