$(document).ready(function(){
	$.ajax({
		type: "POST",
		url: "history.json",
		dataType: "json",
		success: function(json){
			showPress(json);
		}
	});
	
	$("#to_charanavicom").mouseout(
		function() {
			$(this).attr("src", "./img/to_charanavicom_off.png");
		}
	);
	$("#to_charanavicom").mouseover(
		function() {
			$(this).attr("src", "./img/to_charanavicom_on.png");
		}
	);
});


function showPress(json) {
	$("#press_list .content_inner #chara_grad").empty();
	//最新の年の配列を格納
	var index = 0;
	var historyList = json[index];

	var now = 0;
	for (var i = 0; i < 6; i++) {
		var history;
		
		//配列にインデックスが存在するかどうか
		if (now in historyList) {
			history = historyList[now];
		//存在しない場合
		} else {
			//次の年
			index++;
			historyList = json[index];
			//次の年の最初のインデックス
			now = 0;
			history = historyList[now];
		}

		var dateHTML = "";
		var contentsHTML = "";
		
		if(history.title.indexOf("キャラナビ") != -1){
			if (history.url != "") {
				contentsHTML = "<span class=\"history_content\"><a href=\"" + history.url + "\" target=\"_blank\">" + history.title + "</a></span>";
			} else {
				contentsHTML = "<span class=\"history_content\">" + history.title + "</span>";
			}
			
			//月、日がない場合のエラー処理をすること
			if (history.month == "" && history.date == "") {
				dateHTML = "<div class=\"press_child\"><span class=\"history_date\">　　" + historyList.year + "年　　　　　　</span>";
			} else {
				dateHTML = "<span class=\"history_date\">　　" + historyList.year + "年" + history.month + "月" + history.date + "日</span>";
			}
			
			$("#press_list .content_inner #chara_grad").append("<div class=\"press_child\">" + dateHTML + "　　" + contentsHTML + "</div>");
		}
		now++;
	}
	$("#press_list .content_inner").append("<img src=\"./img/chara_news_bottom.png\" />\n");
}


