// JavaScript Document

function booklink(str) {
	var winname, opt;
	
	winname = "web_book";
	
	w = Math.round(window.screen.availWidth * 0.9);
	h = Math.round(window.screen.availHeight * 0.9);

	if (w > 1400) w = 1400;
	if (h >  900) h =  900;

	opt = new Array();
	opt.push("width=" + w);
	opt.push("height=" + h);
	opt.push("left=" + Math.round((window.screen.availWidth - w) * 0.5));
	opt.push("top=" + Math.round((window.screen.availHeight - h) * 0.3));
	opt.push("resizable=yes");
	opt = opt.join(",");
	
	var url = "../web_book/2009/index.html#" + str;
	
	window.open(url, winname,opt);
	return false;
}

function getAll(){

	$("#result").empty();
	
	var category = $("input:radio[@name='category']:checked").val();
	var type = "us";
	
	var pImage;
	
	var query = new Array();
	query.push(category);
	query.push(type);
	
	var cnt = 0;
	var arr_cnt = 0;
	while(cnt <= query.length) {
		if(query[cnt]) {
			arr_cnt += 1;
		}
		cnt+=1;
	}
	
	
	
	var pImage = "";
	
	switch( category ){
		case "ポスチャーピロー":
		pImage += '<h2 class="acc-img"><img src="../../imgdir/accessories/img_posture_pillow.jpg" width="603" height="178" alt="Posture Pillow" /></h2>';
		break;
		
		case "ユーロラテックスピロー":
		pImage += '<h2 class="acc-img"><img src="../../imgdir/accessories/img_latex_pillow.jpg" width="603" height="178" alt="Euro Latex Pillow" /></h2>';
		break;
				
		default:
		pImage = "";
		break;
		
	}
	
	
	
	var jsonDataUrl = "../acce_bl.js";
	
	$.getJSON(jsonDataUrl,function(json) {
		var num = json.channel.items.length;
		var html = "";
		var i = 0;
		var box_cnt = 1;
		var box_class = "";
		var color_text = "";
		var kikaku_text = "";
		var page = "";
				
		while(i < num) {
			if((box_cnt % 4) == 0) {
				box_class = " class=\"box_right\"";
			} else {
				box_class = " class=\"box\"";
			}
			if(json.channel.items[i].type) {
				kikaku_text = "<dt class=\"info_dt\">規格：</dt><dd class=\"info_dd\">" + json.channel.items[i].kikaku + "</dd>";
			}
			if(json.channel.items[i].color && json.channel.items[i].color != '-') {
				color_text = "<dt>カラー：</dt><dd>" + json.channel.items[i].color + "</dd>";
			} else {
				color_text = "";
			}
			
			page = parseFloat(json.channel.items[i].catalog) + 1;
			
			if(arr_cnt > 1) {
				if(json.channel.items[i].category == category && (json.channel.items[i].type == type || json.channel.items[i].type == "common")) {
					html += "<div" + box_class + "><div class=\"photo\"><img src=\"../acc_img/" + json.channel.items[i].photo + ".jpg\" /></div><div class=\"desc\"><h3 class=\"product_name\"><a href=\"javascript:booklink('" + page + "')\">" + json.channel.items[i].name + "</a></h3><div class=\"option\"><dl>" + kikaku_text + "<dt class=\"info_dt\">サイズ：</dt><dd class=\"info_dd\">" + json.channel.items[i].size + "<dt class=\"info_dt\">価格：</dt><dd class=\"info_dd\">" + json.channel.items[i].price + "</dd><dt>仕様</dt><dd>" + json.channel.items[i].spec + "</dd>" + color_text + "</dl></div></div></div>";
					box_cnt++;
				}
			} else if(arr_cnt <= 1) {
				if(category) {
					if(json.channel.items[i].category == category) {
						html += "<div" + box_class + "><div class=\"photo\"><img src=\"../acc_img/" + json.channel.items[i].photo + ".jpg\" /></div><div class=\"desc\"><h3 class=\"product_name\"><a href=\"javascript:booklink('" + page + "')\">" + json.channel.items[i].name + "</a></h3><div class=\"option\"><dl>" + kikaku_text + "<dt class=\"info_dt\">サイズ：</dt><dd class=\"info_dd\">" + json.channel.items[i].size + "<dt class=\"info_dt\">価格：</dt><dd class=\"info_dd\">" + json.channel.items[i].price + "</dd><dt>仕様</dt><dd>" + json.channel.items[i].spec + "</dd>" + color_text + "</dl></div></div></div>";
						box_cnt++;
					}
				}
				if(type) {
					if(json.channel.items[i].type == type || json.channel.items[i].type == "common") {
						html += "<div" + box_class + "><div class=\"photo\"><img src=\"../acc_img/" + json.channel.items[i].photo + ".jpg\" /></div><div class=\"desc\"><h3 class=\"product_name\"><a href=\"javascript:booklink('" + page + "')\">" + json.channel.items[i].name + "</a></h3><div class=\"option\"><dl>" + kikaku_text + "<dt class=\"info_dt\">サイズ：</dt><dd class=\"info_dd\">" + json.channel.items[i].size + "<dt class=\"info_dt\">価格：</dt><dd class=\"info_dd\">" + json.channel.items[i].price + "</dd><dt>仕様</dt><dd>" + json.channel.items[i].spec + "</dd>" + color_text + "</dl></div></div></div>";
						box_cnt++;
					}
				}
			}
			i++;
			
		}
		if(html) {
			$("#result").html(pImage+html);
		} else {
			$("#result").html("<p>お探しの条件のアクセサリーはございません。<br />他の条件をご指定ください。</p>");
		}
	});
	
	return false;
	
}
