var Inventory = ( function() {
	var _url = '/inventory/inventory.php';
	
	function c () {};
	
	c.listItems = function (div, category)
		{
			$(div).update('Loading...');
			new Ajax.Request(_url,
				{
					parameters: { _method: 'listItems', categoryName: category ? category : '' },
					onSuccess: function (transport)
						{
							var items = transport.responseText.evalJSON(true);
							
							var html = ['<table><tbody>'];
							
							for (var i = 0, l = items.length, item; i < l; ++i)
							{
								item = items[i];
								html[html.length] = '<tr><td class="label">';
								
								if (item.link != '')
								{
									html[html.length] = '<a href="';
									html[html.length] = item.link;
									html[html.length] = '">'; 
								}
								
								html[html.length] = item.label;
								
								if (item.link)
								{
									html[html.length] = '</a>'; 
								}
								
								html[html.length] = '</td><td class="price">';
								html[html.length] = item.price;
								html[html.length] = '</td></tr><tr><td colspan="2" class="description">';
								html[html.length] = item.description;
								html[html.length] = '</td></tr>';
							}
							
							html[html.length] = '</tbody></table>';
							$(div).update(html.join(''));
						},
					onFailure: function (transport)
						{
							$(div).update(transport.responseText);
						}
				});
		};
	return c;
})();
