/* JavaScript functions used on the right-nav components */

/******** NOTE THAT I haven't done the sliding script yet, currently the toggle script only opens/closes the target ul. Once some critical work on other ends is done, I'll add the sliding capability. ****************/ 

//Define global variables to be used for sliding
// How many pixels will be used per call to the toggle function
var verticalStep = 5;
// In how many miliseconds there'll be a call to the toggle function
var timeStep = 5;
// How fast will the slide effect be - set it to medium as default
var speed = 'medium';

// Basic trim function for getting rid of the spaces at the beginning & end of a string 
function trim(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function toggle(action,targetElement)
{
	if (action == 'hide')
	{
		targetElement.style.marginTop = '-' + initialHeight - currentHeight + 'px';
		currentHeight = currentHeight - verticalStep;
	}
}

function toggleElement(callerElement,targetElementId,speed)
{
	var targetElement  = document.getElementById(targetElementId);
	// Set the parameters of the toggle function based on the input speed level
	if (speed == 'slow')
	{
		timeStep = 100;
		verticalStep = 1;
	}
	else if (speed == 'fast')
	{
		timeStep = 10;
		verticalStep = 10;
	}
	else
	{
		timeStep = 5;
		verticalStep = 5;
	}
	
	// If the callerElement had a "minus" sign ...
	if (trim(callerElement.innerHTML) == '-')
	{
		
		targetElement.style.display = 'none';
		callerElement.innerHTML = '+ ';
		callerElement.style.paddingLeft = '7px';
		/* To be used for sliding 
		var initialHeight = targetElement.offsetHeight;
		var currentHeight = initialHeight;
		
		targetElement.style.marginTop = '-' + initialHeight - currentHeight + 'px';
		
		currentHeight = currentHeight - verticalStep;
		
		if (currentHeight >= 0)
		{
			setTimeout('toggle("hide",' + targetElement + ')',timeStep);
		}
		*/
	}
	else
	{
		targetElement.style.display = 'block';
		callerElement.innerHTML = ' - ';
		callerElement.style.paddingLeft = '10px';
	}

}