/**
* newsdigest取得
* JSONデータとして取得
*/

$(function() {
	var url = "http://www1.hosp.yamaguchi-u.ac.jp";
	
	
	var url_json = url + "/news/digests.php?jsoncallback=?";
	var param = null;
	var counter = 5;	// 最大記事表示件数
	
	/**
	* NewsURLの設定
	*/
	$("#importantNewsBlock .layoutBlock a.listNaviBtn").attr("href", url + '/news/');
	$("#newsBlock .layoutBlock a.listNaviBtn").attr("href", url + '/news/');
	
	/**
	* jsonデータ取得
	*/
	$.getJSON(url_json, param, function(json) {
		//alert(json.Notice);
		// 重要なお知らせがない場合は、importantNewsBlock そのものを表示しない
		if (json.Notice == undefined) {
			$("#importantNewsBlock").remove();
		} else if (json.Notice.length > 0) {
			$("#importantNewsBlock .layoutBlock dl").remove();
			$.each(json.Notice, function(index, domEle) {
				// domEle = this
				if (index >= counter) {
					return false;
				}
				// 新着
				if (domEle.new_release) {
					newIcon = '&nbsp;<span class="icon"><img src="' + url + '/img/i_new.gif" "width"=32 "height"="11" "alt"="ニュース"></span>';
				} else {
					newIcon = "";
				}
				//$("#importantNewsBlock dl").remove();
				$("#importantNewsBlock .layoutBlock").append("<dl>" +
					"<dt>" + domEle.release + "</dt>" +
					"<dd>" + 
					"<a href=\"" + url + "/news/article-" + domEle.id + ".html\">" + domEle.title + "</a>" +
					newIcon +
					"</dd>" +
					"</dl>");
			});
		} else {
			$("#importantNewsBlock").remove();
		}

		
		// 通常のお知らせ
		if (json.Post == undefined) {
		} else if (json.Post.length > 0) {
			$("#newsBlock .layoutBlock dl").remove();
			$.each(json.Post, function(index, domEle) {
				// domEle = this
				if (index >= counter) {
					return false;
				}
				// 新着
				if (domEle.new_release) {
					newIcon = '&nbsp;<span class="icon"><img src="' + url + '/img/i_new.gif" "width"=32 "height"="11" "alt"="ニュース"></span>';
				} else {
					newIcon = "";
				}
				//$("#newsBlock dl").remove();
				$("#newsBlock .layoutBlock").append("<dl>" +
					"<dt>" + domEle.release + "</dt>" +
					"<dd>" + 
					"<a href=\"" + url + "/news/article-" + domEle.id + ".html\">" + domEle.title + "</a>" +
					newIcon +
					"</dd>" +
					"</dl>");
			});
		} else {}

	}, 'jsonp');
});

