function lt_init() {
	jQuery("form.cf_type" ).attr("selectedIndex", 0);
	jQuery("form.cf_color").attr("selectedIndex", 0);
	jQuery("form.cf_size" ).attr("selectedIndex", 0);
}

function undzero(atr) {
	return ((atr == undefined) ? 0 : atr);
}

/* Lifetree-hayama.com
 * Selectで選択されたとき、対応する li要素を切替える
 * <form id="a-form04">
 *	 <select class="cf_type" onchange="lt_changeCart(this)">
 * 	 <ul class="cart_ul">
 *   	 <li style="display:inline"><input name="3" 
 */
function lt_changeCart(obj) {
	var form = jQuery(obj).parents("form");
//alert(form.attr("id"));
	selt = undzero(form.find(".cf_type" ).attr("selectedIndex"));
	selc = undzero(form.find(".cf_color").attr("selectedIndex"));
	sels = undzero(form.find(".cf_size" ).attr("selectedIndex"));

  form.find("li:visible").hide();
  form.find("#cart"+selt+selc+sels).show();
}

/* Lifetree-hayama.com
 * [カートに入れる]ボタンを押されたときに、選択された色、サイズ、数量を cart.phpに渡す
 * <ul class="cart_ul">
 *   <li style="display:inline"><input name="3" 
 */
function lt_setCart(obj) {
	var form = jQuery(obj);
	form.find("li:visible input:first").each(function () {
		form.find(".i_num").val(jQuery(this).attr("name"));
		form.find(".i_cnt").val(form.find(".cf_cnt").val());
		if (form.find(".cf_color").size() > 0) {
			jQuery(".i_opa_value").val(form.find(".cf_color").val());
		}
		if (form.find(".cf_size").size() > 0) {
			jQuery(".i_opb_value").val(form.find(".cf_size").val());
		}
  });
}

/* 一旦縦横とも"auto"にして実寸を取得。長い方を sizに設定して表示 */
function lt_resize(img, siz) {
	img.style.visibility = "hidden";
	img.style.width  = "auto";
	img.style.height = "auto";
	if (img.width > img.height) {
		if (img.width  > siz) {
			img.style.width  = siz + "px";
		}
	} else {
		if (img.height > siz) {
			img.style.height = siz + "px";
		}
	}
	img.style.visibility = "visible";
}

