var item_database = {};
var item_selection = [];

function getPrice(options, prices) {
	var price = null;
	for(var i = 0; i < prices.length; i++) {
		var p = prices[i];
		var found_price = true;
		for(cat in options) {
			if(p.options[cat] != options[cat]) {
				found_price = false;
				break;
			}
		}
		if (found_price) {
			price = p.price;
			break;
		}
	}

	return price;
}

function calcPrice()
{
	var total = 0;
	for(var idx = 0; idx < item_selection.length; idx++) {
		var item_select = item_selection[idx];
		var item_id = item_select.item;

		// skip id 0, it implies no selection
		if(item_id <= 0) {
			continue;
		}

		var item = item_database[item_id];
		var price = getPrice(item_select.options, item.prices);

		if(price != null) {
			total += price;
		}
	}
	$('#price').html((total > 0) ? "$" + total : "Unavailable");
}
