// JavaScript Document

var itemsArr = new Array(1);

function pickUpBuild(){
	$.getJSON(
"http://pipes.yahoo.com/pipes/pipe.run?_id=68d59b9895458802a0814424be44b9f3&_render=json&_callback=?",  /*"http://pipes.yahoo.com/pipes/pipe.run?_id=04f5db336e9a0cbfe855b649e9785b43&_render=json&_callback=?"*/
	parse_xml
    );
}


function parse_xml(data){
	
	var i=0;
	while(i < 10){
		var item = data.value.items[0].item[i];
		
		var itemSet = new Array(1);
		itemSet["brand"]= item.brand_name;
		itemSet["image"]= item.image_url;
		itemSet["name"]= item.product_name;
		itemSet["price"]= priceOpt(item.price);
		itemSet["url"]= item.dateil_url;
		itemSet["target"]= item.target;
		itemSet["target"]= "_blank";
		itemSet["description"]= item.description;
		itemsArr[i] = itemSet;
		//alert(itemSet["brand"]);
		i++;
		
	}
	
	
	constElements();
	
}

function priceOpt(p){//指定桁数の場合区切り文字を挿入
	//区切り桁
	partNum = 3;
	//区切り文字
	point = ",";
	
	newP = p;
	priceLength = newP.length;
	
	for(i=priceLength; i>0; i--){
		if(i % partNum == 0 && i != priceLength) {
			front = newP.slice(0, -i);
			rear = newP.slice(-i);
			newP = front + point + rear;
		}
	}
	newP = "\\" + newP + "-";
	return newP;
	
}

function constElements(data){
	//alert(itemsArr.length);
	var targetBox = document.getElementById("thumBoxArea");
	//targetBox.innerHTML = "'"+data+"'";
	var html="";
	
	for(i=0; i<itemsArr.length; i++){
		
		html += "<div class='thumBox'>";
		html += "<p class='brandName'>"+ itemsArr[i]["brand"] +"</p><p class='goodsPhoto'><a href='"+ itemsArr[i]["url"] +"' target='" + itemsArr[i]["target"] + "'><img src='" + itemsArr[i]["image"] + "' alt='" + itemsArr[i]["name"] + "' /></a></p>";
		html += "<p class='goodsName'><a href='" + itemsArr[i]["url"]  +"' target='" + itemsArr[i]["target"] + "'>" + itemsArr[i]["name"] + "<br />" + itemsArr[i]["price"] + "</a></p>";
		html += "</div>"
		
		//targetBox.appendChild(html);
		
	}
	
	targetBox.innerHTML = html;

//	alert("高さあわせ開始");

//Special Contents,PickUp Itemの高さ合わせ

$(document).ready(function(){
	var biggestHeight = 0;
	$('.equalheight').each(function(){
		if ($(this).height() > biggestHeight) {
			biggestHeight = $(this).height();
		}
	});
	$('.equalheight').height(biggestHeight);
	
});

}


