var submitButtonClass = 'button.btn-cart';
var productFieldId = '#synAjaxCartId';
var datasToBind = new Object();
var productQty = 0;


var productId = -1;

jQuery(document).ready(function(){
	productId = jQuery(productFieldId).val();
	jQuery(submitButtonClass).attr('onclick','');
	jQuery(submitButtonClass).unbind('click');
	jQuery(submitButtonClass).click(function(){
		
		productQty = jQuery(this).parent().find('#qty').val();
		jQuery(document).trigger('synbeforeaddtocart');
		var posts = jQuery(this).closest('form').serialize();
		posts = posts + '&synAjaxId=' + productId;
		jQuery.post('/ajaxcart/index/addproduct', posts, function(data){
			processDatas(data);
			jQuery(document).trigger('afteraddtocart');
		},'json');
		return false;
	});
	
});


// EDITABLE :
datasToBind.rightCart = '.block-cart';
datasToBind.cartPrice = '.cart-price span';
datasToBind.cartItems = '.cart-items .cart-items-link';
function processDatas(datas)
{
	for(key in datasToBind)
	{
		jQuery(datasToBind[key]).each(function(){
			var element = jQuery(this);
			var stateDisplay = jQuery(this).css('display');
			var newElement = jQuery(datas[key]);
			element.animate({opacity:0},'slow',function(){
				newElement.css({opacity:0});
				element.replaceWith(newElement);
				newElement.animate({opacity:1},'slow');
				jQuery('.btn-remove').css('display','none');
			})	
		})
		
	}
}



