	/**
	 * 
	 * Javascript Product
	 * 
	 * @name Product
	 * @author vcantin
	 * @since 2008-01-11
	 * @version 1.0.0
	 * @package reptileframework
	 * 
	 */
		
	var Product = Class.create
	({
		productId 	: null,
		API_CALL 	: 'cart.apiAdjustCart',
				
		/*
		 * Static function
		 */
		showBackButton : function(currentButton)
		{
			if(document.referrer.split(Request.get('basepath')).length == 2)
			{
				currentButton.show().observe
				(
					'click',
					function()
					{
						history.back()
					}
				);
			}
		},
		
		/*
		 * Init function
		 * @param int productId
		 */
		initialize : function(productId) 
		{     
			this.productId = productId;
		},	      
		
		/*
		 * Get quantity
		 */
		getQuantity : function()
		{
			var currentId 		= Cart.prefixProducts + this.productId.toString() + '_quantity';
			var elementValue 	= $(currentId);
			
			if (Object.isElement(elementValue)) 
			{
				return parseInt(elementValue.getValue());
			}	
			else
			{
				throw "CartValue not found";
				return 0;
			}		
		},

		/*
		 * Set quantity
		 * @param int cartValue
		 */
		setQuantity : function(cartValue)
		{
			var currentId 		= this.cartPrefix + this.productId.toString();
			var elementValue 	= $(currentId);
			
			if (Object.isElement(elementValue)) 
			{
				elementValue.setValue(cartValue);
			}				
		},
		
		/*
		 * Set quantity (Ajax call)
		 * @param int quantity
		 * @param bool isAbsotute
		 */
		_adjustQuantity : function(quantity,isAbsolute)
		{
			if(isAbsolute != true)
			{
				isAbsolute = false;
			}
			
			API.call
			(
				this.API_CALL,
				{
					'product_id' 	: this.productId, 
					'quantity' 		: quantity,
					'is_absolute' 	: isAbsolute
				},
				function() 
				{     					
					if(this.responseJSON.errors.length > 0)
					{
						Cart.displayErrors(this.responseJSON.errors);
					}
					else
					{
						Cart.updateTotalFields();
					}					
				}
			);												
		},
		
		/*
		 * Add quantity
		 */
		addQuantity : function()
		{
			this._adjustQuantity(this.getQuantity() + 1,true);	
		},	
		
		/*
		 * Redraw quantity 
		 */
		redrawQuantity : function()
		{
			this._adjustQuantity(this.getQuantity() -1,true);	
		},
		
		/*
		 * Adjust quantity absolute
		 */
		adjustQuantityAbs : function(quantity)
		{
			this._adjustQuantity(quantity,true);	
		},
		
		/*
		 * Adjust quantity relative
		 */
		adjustQuantityRel : function(quantity)
		{
			this._adjustQuantity(this.getQuantity() + quantity,false);	
		},
		
		/*
		 * Remove product 
		 */
		remove : function()
		{
			this._adjustQuantity(0,true);	
		}		
	});