var CART = function() {
  this.myCart = 0;
  return {

    initialize: function(sCartID, data) {
      CART.myCart = new clsCart({ container: $(sCartID) }, data);
    },

    itemAdd: function(type, post_id, index) {
      collection = { cn: $('divCartNoticeID'), 1: $('spanCartType1ID'), 2: $('spanCartType2ID'), sn: $('strongCartNoticeID') };
      if (collection[1]) collection[1].style.display = 'none';
      if (collection[2]) collection[2].style.display = 'none';
      CART.myCart.show();
      CART.reqAction(type, post_id, 'add', index);
				if (collection.cn) {
            if (CART.myCart.control.container.offsetHeight >= 50) {
              if (typeof NLBfadeBg == 'function') NLBfadeBg(CART.myCart.control.container.id, '#f7f6b8', '#ffffff', '2000');
            }
          if (collection[type]) collection[type].style.display = 'inline';
					collection.sn.innerHTML = '"'+ arguments[3] +'"';
					collection.cn.show();
					scroll(0,0);
				}
    },

    itemRemove: function(post_id, index) {
      CART.reqAction(0, post_id, 'remove', index);
    },

    clear: function() {
      CART.reqAction(0, 0, 'clear');
    },

    reqAction: function(type, post_id, action, index) {
      CART.myCart.control.title.load();
      new Ajax.Request('/global/web/execute/partsearch.v2/cart.execute.php', {
        method: 'get',
        parameters: $H({ type: type, post_id: post_id, action: action, index: index }),
        onSuccess: function(transport) {
          if (action == 'add') {
            CART.myCart.addData(transport.responseJSON);
          } else {
            CART.myCart.data = transport.responseJSON;
            CART.myCart.setData();
          }
        },
        onComplete: function() {
          CART.myCart.control.title.done();
          if (action == 'remove' || action == 'clear') window.location.reload();
        }
      });
    }

  }
}();


