var minHeight;
var maxHeight;
var prevRoll;
var prevLnk;
var scrollSpeed;

var txtExpand;
var txtCollapse;

minHeight = 22;
maxHeight = 140;
scrollSpeed = 29;
prevRoll = "";
prevLnk = "";

txtExpand = "+";
txtCollapse = "-";

function setPrevRoll(param)
{
 prevRoll = param;
}

function roll(itemName, lnkName, mnHeight, mxHeight)
{           
	
	//if they are clicking the same item then roll it up
	if(prevRoll == itemName)
	{
		rollUp(itemName, mnHeight, mxHeight);
	}
	else
	{
		//if there is something rolled down first roll it up
		if(prevRoll != "")
			rollUp(prevRoll, mnHeight, mxHeight);
			
		//roll down the item clicked
		rollDown(itemName, lnkName, mnHeight, mxHeight);
	}
}

function rollDown(itemName, linkName, mnHeight, mxHeight)
{
	//if there is something already expanded then collapse it
	if(prevRoll != "")
		rollUp(prevRoll, mnHeight, mxHeight);
		
	//store the itemname that we are getting ready to expand
	prevRoll = itemName;
	prevLnk = linkName;
				   
	//change the link text
	//document.getElementById(linkName).innerText = txtCollapse;
				   
	//expand the item
	animateRoll(itemName, mnHeight, mxHeight, true);
}

function rollUp(itemName, mnHeight, mxHeight)
{
	//change the link text
	//document.getElementById(prevLnk).innerText = txtExpand;
	document.getElementById(itemName).style.overflow = 'hidden';
	document.getElementById(itemName).scrollTop = 0;
	
	//delete the ref to the item prev rolled down
	prevRoll = "";
				
	animateRoll(itemName, mnHeight, mxHeight, false);
}

function animateRoll(itemName, mnHeight, mxHeight, direction)
{
	if(direction == false)
	{
		mxHeight -= scrollSpeed * ((mxHeight - mnHeight) / mxHeight);
		document.getElementById(itemName).style.height = mxHeight + "px";
		
		if(mxHeight >= (mnHeight + 1))
			window.setTimeout("animateRoll('" + itemName + "', " + mnHeight + ", " + mxHeight + ", " + direction + ")", 1);
		else
			document.getElementById(itemName).style.height = mnHeight + "px";
	}
	else
	{
		mnHeight += scrollSpeed * ((mxHeight - mnHeight) / mxHeight);
		document.getElementById(itemName).style.height = mnHeight + "px";
		
		if(mnHeight <= (mxHeight - 1))
			window.setTimeout("animateRoll('" + itemName + "', " + mnHeight + ", " + mxHeight + ", " + direction + ")", 1);
		else
	 {
			document.getElementById(itemName).style.height = mxHeight + "px";
		 document.getElementById(itemName).style.overflow = 'auto';
	 }
	}
}