var oLastMenuItemSelected = null;
var oLastProductSelected  = null;
function populateMenuItems()
{
	var oProductsMenu = document.getElementById('products_menu');
	var oListItem = null;
	var oListItemLink = null;
	var oElements = document.getElementById('product_text').getElementsByTagName('div')
	var iID = 1;
	var bFirstSubCategory = true;
	// Loop through all articles assigning them unique IDs. Grab the title attributes
	// and assign them to the dynamically created navigation elements along
	// with unique IDs.
	for ( var i = 0; i < oElements.length; i++ )
	{
		if ( oElements[i].title )
		{
			oElements[i].setAttribute( 'id','product_' + iID + 'a' );
			oListItemLink = document.createElement('a');
			oListItemLink.setAttribute('href','#');
			oListItemLink.setAttribute('id','product_' + iID);
			oListItemLink.onclick = new Function ('showProduct(this)');
			oListItemLink.appendChild( document.createTextNode(oElements[i].title) );
			//Remove title from DIV as it's not required.
			oElements[i].removeAttribute('title');
			oListItem = document.createElement('li');
			oListItem.appendChild( oListItemLink );
			if ( oElements[i].className == 'subcategory' )
			{
				if ( bFirstSubCategory )
				{
					oProductsMenu.lastChild.appendChild( document.createElement('ul') )
				}
				bFirstSubCategory = false;
				oProductsMenu.lastChild.lastChild.appendChild( oListItem );
			}
			else
			{
				bFirstSubCategory = true;
				oProductsMenu.appendChild( oListItem );
			}
			iID++;
		}
	}
}
function showProduct( oElement )
{
	if (oLastMenuItemSelected != null)
	{
		oLastMenuItemSelected.className = 'normal';
		oLastProductSelected.style.display = 'none';
	}
	document.getElementById('products_description').style.display = 'none';
	oElement.className = 'selected';
	oLastMenuItemSelected = oElement;
	// add 'a' to content ID to differentiate from the corresponding
	// navigation element ID. E.g. 'product_1' relates to 'product_1a'
	document.getElementById( oElement.id + 'a' ).style.display = 'block';
	oLastProductSelected = document.getElementById( oElement.id + 'a' );
}