/**
 * 天気予報の情報BOXを作成する
 * @param {Object} id この予報を識別するユニークなID
 * @param {Object} yohou livedoorから取得した天気
 */
function makeWeatherBox(id, yohou){
	
	var div = new Element('div', {
		'class': 'weather-box',
		'title': yohou.title
	}); 
	
	div.adopt((new Element('h4')).appendText(yohou.title));
	
	//気温
	var tem = new Element('div', {'class': 'weather-temp'}); 
	tem.adopt(getTempMax(yohou));
	tem.adopt(new Element('br'));
	tem.adopt(getTempMin(yohou));
	div.adopt(tem);

	div.adopt(new Element('img', {
		'src': yohou.image.url, 
		'title': yohou.image.title, 
		'class': 'weather-icon'}));
	div.appendText(yohou.telop);
	div.adopt(new Element('br'));
	
	return div;
}
/**
 * googleMapsに表示される天気予報を作成する
 * @param {Object} id この予報を識別するユニークなID
 * @param {Object} yohou livedoorから取得した天気
 */
function makeWeatherFukidashi(id, yohou){
	var div2 = new Element('div', {'id': id + 'b', 'class': 'weather-info-box'}); 
	div2.adopt((new Element('h4')).appendText(yohou.title));

	div2.adopt(new Element('a', {
		'href': yohou.link 
	}).adopt(new Element('img', {
		'src': yohou.image.url, 
		'title': yohou.image.title, 
		'class': 'weather-icon'})));
	div2.appendText(yohou.telop);
	div2.appendText('/');
	
	//気温
	div2.adopt(getTempMax(yohou));
	div2.appendText('/');
	div2.adopt(getTempMin(yohou));

	var text = decodeURIComponent(yohou.description);
	text = text.replace(/<[^>]+>.*<\/[^>]+>/gi, "");
	var descript = new Element('div', {'class': 'weather-description'});
	descript.appendText(text);
	descript.inject(div2);

	var detailLink = new Element('div', {'class': 'weather-detail-link'});
	var link = new Element('a', {
		'href': yohou.link,
		'target': '_blank'
	});
	link.appendText('livedoor天気で詳細表示');
	link.addClass('link-blank');
	link.inject(detailLink);
	detailLink.inject(div2);
	
	return div2;
}
/**
 * 最高気温の文字列を取得する
 * @param {Object} yohou
 */
function getTempMax(yohou) {
	var tem_max = new Element('span', {'class': 'weather-temp-max'}); 
	tem_max.appendText('最高 ');
	if (typeof yohou.temperature.max.celsius == "object") {
		tem_max.appendText('---');
	} else {
		tem_max.appendText(yohou.temperature.max.celsius);
	}
	tem_max.appendText('℃');
	
	return tem_max;
}
/**
 * 最低気温の文字列を取得する
 * @param {Object} yohou
 */
function getTempMin(yohou) {
		var tem_min = new Element('span', {'class': 'weather-temp-min'}); 
	tem_min.appendText('最低 ');
	if (typeof yohou.temperature.min.celsius == "object") {
		tem_min.appendText('---');
	} else {
		tem_min.appendText(yohou.temperature.min.celsius);
	}
	tem_min.appendText('℃');
	
	return tem_min;
}

