//
// 文書ロード時
//
$(document).ready(
	function()
	{
		$("#shuffle").cycle({ fx: 'fade', pause: 1, speed: 2000 });
		$("#shuffle").show();
		
		$("#frm2cart1, #frm2cart2").submit(
			function()
			{
				var scd  = $("#" + this.id + " #scd").attr("value");
				var gcd  = $("#" + this.id + " #gcd").attr("value");
				var dday = $("#" + this.id + " #dday").attr("value");
				if (!dday)
				{
					alert(err["ERROR_NODDAY"]);
					$("#" + this.id + " #dday").trigger("focus");
					return false;
				}
				$.post(
					this.action,
					{
						"cmd-add" : 1,
						"scd"  : scd,
						"gcd"  : gcd,
						"dday" : dday
					},
					function(res)
					{
						if (res.status == 'SUCCESS')
						{
							// 商品をCookieに追加
							var s = $.cookie("ORDER");
							var o = (s) ? $.parseJSON(s) : { "items": [] };
							
							var item  = new Object();
							item.scd  = scd;
							item.gcd  = gcd;
							item.dday = dday;
							item.num  = 1;
							o.items.push(item);
							s = $.toJSON(o);
							$.cookie("ORDER", s, { "path": "/" });
							
							// カート一覧へ
							location.href= "/cart.html";
						}
						else
						{
							if (err[res.status])
							{
								alert(err[res.status]);
							}
							else
							{
								alert(res.status);
							}
						}
					},
					'json'
				);
				return false;
			}
		);
	}
);

//
// 商品画像詳細
//
function showMini(seq, scd, gcd)
{
	var url = "/goods-images/" + scd + "/" + gcd + "/" + seq + "l.jpg";
	alert(url);
//	var url = "/goods/mini.html?scd=" + scd + "&gcd=" + gcd + "&KeepThis=true&TB_iframe=true&width=714&height=535";
	$("#img_" + seq).attr("href", url);
	return false;
}

function reloadCart()
{
	tb_remove();
	location.href= "/cart.html";
}

