// the_workshop.js


window.onload = function()
{

   var categories = getCategories() //
   var posts      = getPosts()     //

	createClientsMenu ( getWorkClientList (categories).sort(), posts )  //
	createTypesMenu   ( getWorkTypeList   (categories).sort(), posts ) //


   return null

}


function createClientsMenu(clients, posts)
{

	for( var cx = 0 ; cx < clients.length ; cx++ ) // for each client
	{

	  var menuItem = create("li", "client"+cx, id('clientList'))
	  var menuText = create("span", "client"+cx+"scroller", menuItem)
		menuText.setAttribute("class", "scroller closed")
		menuText.setAttribute("className", "scroller closed")

		listener(text(menuText, clients[cx]), "click", scrollMenu)


		createCollapseableMenu(menuItem, getPostsByCategories(posts, "Client: "+clients[cx])) // create submenu

	}


   return id('clientList').getElementsByTagName('li') // reference to newly created menu items

}

function createTypesMenu(types, posts)
{

	for( var cx = 0 ; cx < types.length ; cx++ ) // for each work type
	{

	  var menuItem = create("li", "type"+cx, id('typeList'))
	  var menuText = create("span", "type"+cx+"scroller", menuItem)
		menuText.setAttribute("class", "scroller closed")
		menuText.setAttribute("className", "scroller closed")

		listener(text(menuText, types[cx]), "click", scrollMenu)


		createCollapseableMenu(menuItem, getPostsByCategories(posts, "Work_Type: "+types[cx])) // create submenu

	}


   return id('typeList').getElementsByTagName('li') // reference to newly created menu items

}


// extracts and returns array of all prefixed client categories from passed 'categories' array
function getWorkClientList(categories)
{

   var clients = new Array()


	for( var cx = 0 ; cx < categories.length ; cx++ ) // for each category
	{

		if( categories[cx].indexOf('Client: ') != -1 ) // if prefixed with 'Client: '
		{

			clients.push(categories[cx].substring(8, categories[cx].length))

		}

	}


   return clients

}
// extracts and returns array of all prefixed work type categories from passed 'categories' array
function getWorkTypeList(categories)
{

   var types = new Array()


	for( var cx = 0 ; cx < categories.length ; cx++ ) // for each category
	{

		if( categories[cx].indexOf('Work_Type: ') != -1 ) // if prefixed with 'Work_Type: '
		{

			types.push(categories[cx].substring(11, categories[cx].length))

		}

	}


   return types

}

function clientPosts(client, posts) { return getPostsByCategories(posts, "Client: "   +client) }  //
function   typePosts(type  , posts) { return getPostsByCategories(posts, "Work_Type: "+type  ) } //
<!-- ph=1 -->

