
/// <reference name="MicrosoftAjax.js"/>
/// <reference path="../Wcf/SDProxy.svc" />
/// <reference path="Lib/jquery-1.5.1-vsdoc.js" />
/// <reference path="beetservices-core.js" />
/// <reference path="carousel-0.0.js" />
/// <reference path="common-core.js" />
/// <reference path="cookiegram-0.0.js" />
/// <reference path="eventmanager-core.js" />
/// <reference path="lunchcartservices-core.js" />
/// <reference path="popupwindow-core.js" />
/// <reference path="productservices-core.js" />
/// <reference path="userservices-core.js" />

///
/// Written by CC ~ 06/04/2009
/// Revised RR ~ 06/18/2009
///
Type.registerNamespace('Specialtys.SpecialtysDirect.Client.ProductGallery');

Specialtys.SpecialtysDirect.Client.ProductGallery = function(clientId) {
    // constructor
    this._clientId = clientId;
}
Specialtys.SpecialtysDirect.Client.ProductGallery.prototype = {
  generateQtyId: function(product) {
    return this._clientId + '_qty_' + product.ProductId;
  },
  generateLinePriceId: function(product) {
    return this._clientId + '_linePrice_' + product.ProductId;
  },
  generatePriceId: function(product) {
    return this._clientId + '_itemPrice_' + product.ProductId;
  },
  addToCart: function(product, activeIngList) {
    var inst = this;
    $(document).ready(function() {
      var qty = $("#" + inst.generateQtyId(product));
      if (qty.length == 0)
        qtyToAdd = 1;
      else
        qtyToAdd = qty.val();
      if (qtyToAdd <= 0) {
        alert("Your quantity must be greater than zero");
      } else {
        if (activeIngList == undefined || activeIngList == null) {
          lunchcartMgr.addToCart(product.ProductId, qtyToAdd);
        } else {
          lunchcartMgr.addToCartWithEdits(product.ProductId, qtyToAdd, activeIngList);
        }
      }
    });
  },
  decreaseQty: function(product) {
    var currentQty = parseInt($("#" + this.generateQtyId(product)).val());
    var basePrice = parseFloat($("#" + this.generatePriceId(product)).val());
    if ((currentQty - 1) > 0) {
      $("#" + this.generateQtyId(product)).val(currentQty - 1);
      $("#" + this.generateLinePriceId(product)).val((parseFloat(currentQty - 1) * basePrice).toFixed(2));
    } else {
      $("#" + this.generateQtyId(product)).val("0");
      $("#" + this.generateLinePriceId(product)).val("0.00");
    }

  },
  increaseQty: function(product) {
    var currentQty = parseInt($("#" + this.generateQtyId(product)).val());
    var basePrice = parseFloat($("#" + this.generatePriceId(product)).val());
    $("#" + this.generateQtyId(product)).val(currentQty + 1);
    $("#" + this.generateLinePriceId(product)).val(((parseFloat(currentQty + 1) * basePrice)).toFixed(2));
  }
}

