function set_cart(target,kid,quantity,success,error)
{
	$(function()
	{
		if($('#in_cart :animated').size()==0)
		{
			$(target).hide().after('<img src="/cart/load.gif" alt="load" />');
			$.post('/cart/set_cart.php',{"flag":"add","kid":kid,"quantity":quantity},function(data)
			{
				$(target).next().remove().end().show();
				data=$.parseJSON(data);
				if(data.flag==2)
				{
					$('#in_cart_'+data.kid+' select').replaceWith($('<select name="quantity" class="quantity">'+data.select+'</select>').change(number_change));
					$('#in_cart_total').text(data.total+'円');
					if(data.send!='')
					{
						$('#in_cart_send').html('<p class="att-box">'+data.send+'</p>');
					}
					else
					{
						$('#in_cart_send').html('');
					}
					$(target).after($('<img src="/common/images/contents/add_cart.gif" alt="商品がカートに入りました。" width="98" height="50" class="success" />').hide().fadeIn('fast',function()
					{
						$(this).delay(1500).fadeOut(function()
						{
							$(this).remove();
						})
					}));
					success(data.message);
				}
				else if(data.flag==1)
				{
					$('#in_cart').append($('<div id="in_cart_'+data.kid+'"><p><a href="/product/'+data.kid+'" title="'+data.name+'">'+data.name+'</a></p><ul class="unit"><li><select name="quantity" class="quantity">'+data.select+'</select></li><li class="price">'+data.price+'円</li><li class="last in_cart_del"><a href="#"><img src="/common/images/side/btn_delete.gif" alt="削除" width="48" height="20" /></a></li></ul></div>').find('select').change(number_change).end().hide().fadeIn('slow'));
					$('#in_cart_total').text(data.total+'円');
					if(data.send!='')
					{
						$('#in_cart_send').html('<p class="att-box">'+data.send+'</p>');
					}
					else
					{
						$('#in_cart_send').html('');
					}
					$(target).after($('<img src="/common/images/contents/add_cart.gif" alt="商品がカートに入りました。" width="98" height="50" class="success" />').hide().fadeIn('fast',function()
					{
						$(this).delay(1500).fadeOut(function()
						{
							$(this).remove();
						})
					}));
					success(data.message);
				}
				else
				{
					error(data.message);
				}
			});
		}
	});
}

$(function()
{
	$('.in_cart_del').live('click',function()
	{
		if($('#in_cart :animated').size()==0)
		{
			var target=$(this);
			target.hide().after('<img src="/cart/load.gif" alt="load" />');
			var p_div=$(this).closest('div');
			$.post('/cart/set_cart.php',{"flag":"del","kid":p_div.attr('id').substr(8)},function(data)
			{
				target.next().remove();
				data=$.parseJSON(data);
				$('#in_cart_total').text(data.total+'円');
				if(data.send!='')
				{
					$('#in_cart_send').html('<p class="att-box">'+data.send+'</p>');
				}
				else
				{
					$('#in_cart_send').html('');
				}
				p_div.fadeOut('slow',function()
				{
					p_div.remove();
				});
				$('.kid[value="'+p_div.attr('id').substr(8)+'"]').closest('div').find('p.in-cart,dd.in-cart').fadeOut('slow',function()
				{
					$(this).remove();
				});
			});
		}
		return false;
	});

	$('#in_cart .quantity').change(number_change);
});

function number_change()
{
	var target=$(this);
	target.hide().after('<img src="/cart/load.gif" alt="load" />');
	var p_div=$(this).closest('div');
	$.post('/cart/set_cart.php',{"flag":"ch","kid":p_div.attr('id').substr(8),"quantity":$(this).val()},function(data)
	{
		target.next().remove().end().show();
		data=$.parseJSON(data);
		$('#in_cart_total').text(data.total+'円');
		if(data.send!='')
		{
			$('#in_cart_send').html('<p class="att-box">'+data.send+'</p>');
		}
		else
		{
			$('#in_cart_send').html('');
		}
	});
}

