function setItem(str)
{
	if(str)
	{
		var buff = $.cookie('cart');
		if(buff)
		{
			if(jQuery.inArray(str, buff.split(',')) === -1)
			{
				$.cookie('cart', buff+','+str, {path:'/',expire:0});
				alert("カートへ写真を追加しました");
			}
			else
			{
				alert("既にカートの中にあります");
			}
		}
		else
		{
			$.cookie('cart', str, {path:'/',expire:0});
			alert("カートへ写真を追加しました");
		}
		reloadCart();
	}
}
function reloadCart()
{
	$.ajax(
	{
		type: 'post',
		url: 'getCart.json',
		dataType: 'json',
		success: function(request)
		{
			$('#view_cart').empty();
			var count = 0;
			$.each(request, function(key,value)
			{
				var artist = value.artist;
				if(!artist.length)
				{
					artist = 'Takamichi';
				}
				$('#view_cart')
				.append(
				$('<div />')
				.attr('class', 'cart_box')
				.append(
				$('<div />')
				.attr('class', 'pic')
				.append(
				$('<img />')
				.attr('src', value.img+'S'+value.ext)
				.attr('alt', value.building+'の写真 '+value.code+value.no)
				.attr('title', value.building+'の写真 '+value.code+value.no)
				))
				.append(
				$('<p />')
				.append('['+value.code+value.no+']<br />')
				.append(value.building+'<br />')
				.append('photo by '+artist+'<br />')
				.append('￥'+value.price+'<br />')
				)
				.append(
				$('<div />')
				.attr('class', 'clear')
				));
				count++;
			});
			if(count<1)
			{
				$('#view_cart').empty();
				$('#view_cart')
				.append(
					$("<em />")
					.append("カートに商品はありません")
				);
			}
		},
		error: function(request)
		{
			alert('カートの中身がありません');
		},
		timeout: function (request)
		{
			alert('カートの中身がありません');
		}
	});				
}
function deleteItem(str)
{
	var mess = str+"をカートから削除します\nよろしければOKを押してください"
	if(confirm(mess))
	{
		var newid = "";
		var ids = $.cookie('cart').split(',');
		for(var i=0; i<ids.length; i++)
		{
			if(ids[i] === str)
			{
				continue;
			}
			if(newid.length)
			{
				newid+=',';
			}
			newid+=ids[i];
		}
		$.cookie('cart', newid, {path:'/',expire:0});
		window.location.reload();
	}
}

