//<script language="javascript">

function klxColumnsInit(oDocument, divContent, lColCount, sColClassName, sColId, bShowColumns)
{
	// Purpose:		Initialise columns for viewing, load content
	// Parameters:	divContent: A reference to the div that contains the content to be 
	//				columnised. divContent will be displayed if javascript is not enabled. The text 
	//				content must be sub divided in p tags.
	//				divColumns: an array of divs to be populated as columns.
	//				lColCount: the number of columns to divide the content into
	//				sColClassName: CSS class to be applied to the columns
	//				sColId: Id to be used for column divs. Will be appended with the column number.
	//				bShowColumns: If true, the columnised content will be displayed initially, if
	//				if false, divContent will be displayed.
	// Modified: 19/09/2006
	// By: DJW
	// Changes: Insert the new columns before the divContent rather than append them
	//				Don't show the columns if only one has content
	
	if (divContent == null) return;
	// create column divs
	var divColumns = new Array();
	var fullColumns = false;
		
	for (var i = 0; i < lColCount; i++)
	{
		if (i == (lColCount - 1))
		{
			// Copy all of the content into the last column
			divColumns[i] = divContent.cloneNode(true);
		}
		else
		{
			divColumns[i] = oDocument.createElement('div');
		}
		divColumns[i].className = sColClassName;
		var j = i + 1;
		divColumns[i].setAttribute("id", sColId + j.toString());
		//divContent.parentNode.appendChild(divColumns[i]);
		divContent.parentNode.insertBefore(divColumns[i], divContent);
	}

	// distribute the content	
	while (divColumns[lColCount - 2].offsetHeight < divColumns[lColCount - 1].offsetHeight)
	{
		for (i = 0; i < lColCount - 1; i++)
		{
			//if (divColumns[lColCount - 1].children.length > 1)
			if (divColumns[lColCount - 2].offsetHeight < divColumns[lColCount - 1].offsetHeight)
			{
				divColumns[i].appendChild(divColumns[lColCount - 1].firstChild);
			}
			else
			{
				break;
			}
		}
	}
	// Check if all content is in only one column
	for (i = 1; i < lColCount; i++)
		if (divColumns[i].childNodes.length != 0) fullColumns = true;
	// Show the columns
	klxColumnsShow(oDocument, divContent, lColCount, sColId, bShowColumns & fullColumns);
}
function klxColumnsShow(oDocument, divContent, lColCount, sColId, bShowColumns)
{
	// show the column(s)
	for (var i = 0; i < lColCount; i++)
	{
		var j = i + 1;
		var divColumn = oDocument.getElementById(sColId + j.toString());
		
		if (bShowColumns == true)
		{
			divColumn.style.display = "block";
		}
		else
		{
			divColumn.style.display = "none";
		}
	}
	
	if (bShowColumns == true)
	{
		divContent.style.display = "none";
	}
	else
	{
		divContent.style.display = "block";
	}
}
//</script>