var currentToolbarItem;

function setupToolbar (listID) {
	
	var list = document.getElementById(listID).childNodes[1];
	var linkIndex = 0;
	var divIndex = 0;
	
	for (var i=0; i<list.childNodes.length; i++) {
		if (list.childNodes[i].nodeType == 1) {
		
			divElement = list.childNodes[i].firstChild;
			linkElement = divElement.firstChild;

			if (divElement) {
				divIndex++;
				
				if (divIndex == 1) {
					divElement.setAttribute("class", "toolbar-cell-base");
				} else {
					divElement.setAttribute("class", "toolbar-cell");
				}
				
				divElement.setAttribute("id", "toolbar-cell-"+divIndex);
			}
			
			if (linkElement) {
				linkIndex++;
				
				linkElement.setAttribute("href", "#"+linkIndex);
				linkElement.setAttribute("class", "toolbar-link");
				linkElement.setAttribute("onclick", "toolbarAction("+linkIndex+")");
			}
		}
	}
	
	// Select the first toolbar item
	toolbarAction(1);
}

function toolbarAction (item) {
					
	// Restore current items cell class
	if (currentToolbarItem > 0) {
		element = document.getElementById('toolbar-cell-'+currentToolbarItem);
		nextElement = document.getElementById('toolbar-cell-'+(currentToolbarItem + 1));
		
		if (currentToolbarItem == 1) {
			element.className  = "toolbar-cell-base";
		} else {
			element.className  = "toolbar-cell";
		}
		
		nextElement.className = "toolbar-cell";
	}
	
	// Set the elements cell class
	element = document.getElementById('toolbar-cell-'+item);
	nextElement = document.getElementById('toolbar-cell-'+(item + 1));
	
	if (item == 1) {
		element.className = "toolbar-cell-selected-base";
	} else {
		element.className = "toolbar-cell-selected";
	}
	
	nextElement.className = "toolbar-cell-adjacent";
	
	// Set the current item
	currentToolbarItem = item;
}
