	function gatherPrices() {
	  
	  itemPrices = {};
    itemTotals = {};
    totalShipping = 0;
    totalUnits = 0;
    totalCost = 0;
    
    // update shipping if the postcode exists
   // checkPostcode();
    // loop through each product, and save to hash
	  $("input[name*=quantity]").each(function(){
	    name = getInt(this.name);
	    itemPrices[name] = {};
	    itemTotals[name] = {};
	    
	    itemPrices[name]["bottle"] = parseInt($(this).nextAll("input[name*=price]").val());
	    //itemPrices[this.id]["case"] = $("."+this.id+"_case").parseNumber();
	    update.apply(this);
	  });
	}
	
	function update(target) {
	  var item;
	  // logic to see if this is direct or from key binding
	  if (this.id == undefined) {
	    item = target;
    } else {
      item = this;
    }
    
    var units;
    if (item.value == "") {
      units = 0;
    } else {
      units = parseInt(item.value);
    }
    
    // calculations
    var result = itemPrices[getInt(item.name)]["bottle"] * units;
	  itemTotals[getInt(item.name)]["cost"] = result;
	  itemTotals[getInt(item.name)]["unit"] = units;
	  
	  $("#total_"+getInt(item.name)).text(formatCurrency(itemTotals[getInt(item.name)]["cost"]));
	  total();
	}
	
	function total() {
	  totalCost = 0;
	  totalUnits = 0;
	  for(var i in itemTotals) {
	    totalCost += itemTotals[i]["cost"];
	    totalUnits += itemTotals[i]["unit"];
    }
    
    // update shipping if the postcode exists
    //checkPostcode();
    
    var cases = Math.floor(totalUnits / 6);
    var remain = totalUnits % 6;
    
    var remainString = "<ul>";
    var caseString = "<ul>";
    for (i = 0; i < cases; i++) {
      caseString += "<li class=\"case\">Full 6 pack</li>";
    }
    for (i = 0; i < remain; i++) {
      remainString += "<li class=\"bottle\">Bottle</li>";
    }
    
    caseString += "</ul>";
    remainString += "</ul>";
    
    $("#cases #main").html(remainString);
    $("#cases #full").html(caseString);
    
    if (remain == 0 && cases >= 1) {
      $("#productForm #submit").removeClass("disabled").attr("disabled", "")
      $("#productForm #warning").hide();
    } else {
      $("#productForm #submit").addClass("disabled").attr("disabled", "disabled")
      $("#productForm #warning").show();
    }
    
    $("#fc_total_products").text(totalUnits);
    $("#fc_total_cost").text(formatCurrency(totalCost));
	}
	
	function formatCurrency(amount) {
  	var i = parseFloat(amount);
  	if(isNaN(i)) { i = 0.00; }
  	var minus = '';
  	if(i < 0) { minus = '-'; }
  	i = Math.abs(i);
  	i = parseInt((i + .005) * 100);
  	i = i / 100;
  	s = new String(i);
  	if(s.indexOf('.') < 0) { s += '.00'; }
  	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
  	s = minus + "$" + s;
  	return s;
  }
  
  function getInt(string) {
	  return string.split(':',1);
  }
