

sekaimon.sr = {};


sekaimon.sr.showPriceRefineButton = function() {
	document.getElementById("price_submit").style.display = "block";
}


sekaimon.onRead.addEventListener(function() {

	if(UA.IE && UA.IE < 7) sekaimon.sr.ecHeight_changeHeight = function(Ob,  H) { Ob.style.height    =  H; }
	else                   sekaimon.sr.ecHeight_changeHeight = function(Ob, xH) { Ob.style.maxHeight = xH; }

	sekaimon.sr.ecHeight = function(Ob, nH, tH, Ac) {
		var frames = 5;
		var currentFrame = 0;
		var interval = 20;
		var distance = (tH - nH) / frames;
		var Action = Ac ? Ac : function() { return; };
		var STEP = setInterval(function() {
			currentFrame++;
			if(currentFrame == frames) {
				sekaimon.sr.ecHeight_changeHeight(Ob, tH + "px");
				clearInterval(STEP);
				Action();
			} else {
				sekaimon.sr.ecHeight_changeHeight(Ob, Ob.offsetHeight + distance + "px");
			}
		}, interval);
	}

	if(document.getElementById("search-refinement_sekaimon-shipping").getElementsByTagName("p")[0].offsetWidth == 170) {

		(new Image()).src = "/res/images/search-refinement/detail_h_closed_bg.gif";

		sekaimon.sr.Root = document.getElementById("search-refinement");
		sekaimon.sr.Details = sekaimon.sr.Root.getElementsByClassName("search-refinement_detail");
		sekaimon.sr.Details_num = 1;

		foreach(sekaimon.sr.Details, function(Detail) {

			Detail.id = "search-refinement_detail_" + sekaimon.sr.Details_num;

			if(Detail.getElementsByTagName("ul").length && Detail.getElementsByTagName("ul")[0].className.match(/criteria /)) {

				var UL  = Detail.getElementsByTagName("ul")[0];
				var Max = UL.className.split("_")[1];
				var LIs = UL.getElementsByTagName("li");

				if(LIs.length > Max) {

					UL.id = "search-refinement_detail_list_all_" + sekaimon.sr.Details_num;

					var aUL = document.createElement("ul");
					aUL.id = "search-refinement_detail_list_" + sekaimon.sr.Details_num;
					for(var i = 0; i < Max; i++) {
						var aLI = document.createElement("li");
						aLI.innerHTML = LIs[i].innerHTML;
						aUL.appendChild(aLI);
					}

					var moreP = document.createElement("p");
					moreP.className = "more";
					moreP.id = "search-refinement_detail_more_" + sekaimon.sr.Details_num;
					var moreEM = document.createElement("em");
					var moreA = document.createElement("a");
					moreA.innerHTML = 'もっと見る';
					var fR = function(num) {
						return function() {
							document.getElementById("search-refinement_detail_more_" + num).style.display = "none";
							document.getElementById("search-refinement_detail_list_" + num).style.display = "none";
							document.getElementById("search-refinement_detail_list_all_" + num).style.display = "block";
						}
					}
					moreA.onclick = moreA.onkeypress = fR(sekaimon.sr.Details_num);
					moreEM.appendChild(moreA);
					moreP.appendChild(moreEM);

					UL.style.display = "none";
					Detail.appendChild(aUL);
					Detail.appendChild(moreP);

					UL.style.height = document.getElementById("search-refinement_detail_list_" + sekaimon.sr.Details_num).offsetHeight + document.getElementById("search-refinement_detail_more_" + sekaimon.sr.Details_num).offsetHeight + "px";

				}

			}

			var H3  = Detail.getElementsByTagName("h3")[0];

			Detail.opened = 1;
			Detail.openedHeight = 0;
			Detail.closedHeight = H3.offsetHeight - 4;

			H3.style.cursor = "pointer";
			H3.onmouseover = function() { this.style.color = "#FFAA00"; }
			H3.onmouseout  = function() { this.style.color = "#FE7800"; }

			var fR = function(num) {
				return function() {
					var D = document.getElementById("search-refinement_detail_" + num);
					var H3 = D.getElementsByTagName("h3")[0];
					if(D.opened) {
						D.openedHeight = D.offsetHeight;
						sekaimon.sr.ecHeight(D, D.openedHeight, D.closedHeight, function() {
							D.opened = 0;
							H3.style.textDecoration = "underline";
							H3.style.backgroundImage = "url(/res/images/search-refinement/detail_h_closed_bg.gif)";
						});
					} else {
						sekaimon.sr.ecHeight(D, D.closedHeight, D.openedHeight, function() {
							D.opened = 1;
							if(!UA.IE || UA.IE > 6) D.style.maxHeight = "10000px";
							H3.style.textDecoration = "none";
							H3.style.backgroundImage = "url(/res/images/search-refinement/detail_h_opened_bg.gif)";
						});
					}
				}
			}

			H3.onclick = H3.onkeypress = fR(sekaimon.sr.Details_num);

			sekaimon.sr.Details_num++;

		});

		document.getElementById("price_submit").style.display = "none";
		var pINPUTs = document.getElementById("price_us").getElementsByTagName("input");
		foreach(pINPUTs, function(pINPUT) {
			pINPUT.onchange = pINPUT.onblur = sekaimon.sr.showPriceRefineButton;
		});

	}

});