function buildAarticle(o) {

	var recs = o.article;
	var curYM = null;
	var curY = null;
	var $sect = null;

	for (i = 0; i < recs.length; i++) {
		var record = recs[i];
		var date = record.date;
		var service = record.service;
		var ym = date.year + '' + date.month;
		var y = date.year;
		if (curYM != ym) {
			if(curY == y){
				$sect = $('<section></section>')
					.attr('class', 'arcbox group')
					.appendTo('#t2');
				$('<h4/>')
					.text(date.month + '月')
					.appendTo($sect);
				$sect = $('<div class="newslist"></div>').appendTo($sect);
			}else{
				$sect = $('<section></section>')
					.attr('class', 'arcbox group')
					.appendTo('#t2');
				$('<h4/>')
					.text(date.year + '年' + date.month + '月')
					.appendTo($sect);
				$sect = $('<div class="newslist"></div>').appendTo($sect);
			}
			curY = y;
			curYM = ym;
		}
		if ($sect == null) {
			continue;
		}
		var $dl = $('<dl/>').appendTo($sect);
		var $dt = $('<dt/>')
			.text(date.year + '/' + date.month + '/' + date.day + '　' + service.name)
			.appendTo($dl);
		$('<a/>')
			.attr('href', '/award/' + record.url)
			.attr('target', '_blank')
			.text(record.title)
			.appendTo($('<dd>').appendTo($dl));
	}
}

function buildAarticlePress(o) {

	var recs = o.article;
	var curYM = null;
	var curY = null;
	var $sect = null;

	if(recs.length > 0){
		for (i = 0; i < recs.length; i++) {
			var record = recs[i];
			var date = record.date;
			var service = record.service;
			var ym = date.year + '' + date.month;

			if (curY != date.year) {
				$('<h3/>')
					.text(date.year + '年')
					.appendTo('#h3');
				curY = date.year;
			}

			if (curYM != ym) {
				$sect = $('<section></section>')
					.attr('class', 'arcbox group')
					.appendTo('#t2');
				$('<h4/>')
					.text(date.year + '年' + date.month + '月')
					.appendTo($sect);
				$sect = $('<div class="newslist"></div>').appendTo($sect);
				curYM = ym;
			}
			if ($sect == null) {
				continue;
			}
			var $dl = $('<dl/>').appendTo($sect);
			var $dt = $('<dt/>')
				.text(date.year + '/' + date.month + '/' + date.day + '　')
				.appendTo($dl);
			$('<a/>')
				.attr('href', '/' + record.url)
				.attr('target', '_blank')
				.text(record.title)
				.appendTo($('<dd>').appendTo($dl));
		}
	}else{
		var r = getRequest();
		if(r.year == null){
			var this_year = getCurrentYear();
			$('<h3/>')
				.text(this_year + '年')
				.appendTo('#h3');
		}else{
			$('<h3/>')
				.text(r.year + '年')
				.appendTo('#h3');
		}
		$sect = $('<section></section>')
			.attr('class', 'arcbox group')
			.appendTo('#t2');
			$('<h4/>')
				.appendTo($sect);
			$sect = $('<div class="newslist"></div>').appendTo($sect);
			var $dl = $('<dl/>').appendTo($sect);
			var $dt = $('<dt/>')
				.text('記事がありません')
				.appendTo($dl);
	}
}

function buildAarticleTopic(o) {

	var recs = o.article;
	var curYM = null;
	var curY = null;
	var $sect = null;

	if(recs.length > 0){
		for (i = 0; i < recs.length; i++) {
			var record = recs[i];
			var date = record.date;
			var service = record.service;
			var ym = date.year + '' + date.month;

			if (curY != date.year) {
				$('<h3/>')
					.text(date.year + '年')
					.appendTo('#h3');
				curY = date.year;
			}

			if (curYM != ym) {
				$sect = $('<section></section>')
					.attr('class', 'arcbox group')
					.appendTo('#topic_title');
				$('<h4/>')
					.text(date.year + '年' + date.month + '月')
					.appendTo($sect);
				$sect = $('<div class="newslist"></div>').appendTo($sect);
				curYM = ym;
			}
			if ($sect == null) {
				continue;
			}
			var $dl = $('<dl/>').appendTo($sect);
			var $dt = $('<dt/>')
				.text(date.year + '/' + date.month + '/' + date.day + '　')
				.appendTo($dl);
			$('<a/>')
				.attr('href', record.url)
				.attr('target', '_blank')
				.text(record.title)
				.appendTo($('<dd>').appendTo($dl));
		}
	}else{
		var r = getRequest();
		if(r.year == null){
			var this_year = getCurrentYear();
			$('<h3/>')
				.text(this_year + '年')
				.appendTo('#h3');
		}else{
			$('<h3/>')
				.text(r.year + '年')
				.appendTo('#h3');
		}

		$sect = $('<section></section>')
			.attr('class', 'arcbox group')
			.appendTo('#topic_title');
			$('<h4/>')
				.appendTo($sect);
			$sect = $('<div class="newslist"></div>').appendTo($sect);
			var $dl = $('<dl/>').appendTo($sect);
			var $dt = $('<dt/>')
				.text('記事がありません')
				.appendTo($dl);
	}
}

function buildAarticlePub(o) {

	var recs = o.article;
	var curYM = null;
	var curY = null;
	var $sect = null;

	if(recs.length > 0){
		for (i = 0; i < recs.length; i++) {
			var record = recs[i];
			var date = record.date;
			var service = record.service;
			var media = record.media;
			var ym = date.year + '' + date.month;

			if (curY != date.year) {
				$('<h3/>')
					.text(date.year + '年')
					.appendTo('#h3');
				curY = date.year;
			}

			if (curYM != ym) {
				$sect = $('<section></section>')
					.attr('class', 'arcbox group')
					.appendTo('#pub_title');
				$('<h4/>')
					.text(date.year + '年' + date.month + '月')
					.appendTo($sect);
				$sect = $('<div class="newslist"></div>').appendTo($sect);
				curYM = ym;
			}
			if ($sect == null) {
				continue;
			}
			var $dl = $('<dl/>').appendTo($sect);
			var $dt = $('<dt/>')
				.text(date.year + '/' + date.month + '/' + date.day + '[')
				.appendTo($dl);
				$('<a/>')
					.attr('href', media.url)
					.attr('target', '_blank')
					.text(media.name)
					.appendTo($dt);
			$dt.append(']');

			if(record.url == ""){
					$('<dd/>')
					.append(record.title)
					.appendTo($dl);
			}else{
				$('<a/>')
					.attr('href', record.url)
					.attr('target', '_blank')
					.text(record.title)
					.appendTo($('<dd/>').appendTo($dl));
			}
		}
	}else{
		var r = getRequest();
		var this_year = getCurrentYear();
		if(r.year == null){
			$('<h3/>')
				.text(this_year + '年')
				.appendTo('#h3');
		}else{
			$('<h3/>')
				.text(r.year + '年')
				.appendTo('#h3');
		}
		$sect = $('<section></section>')
			.attr('class', 'arcbox group')
			.appendTo('#pub_title');
			$('<h4/>')
				.appendTo($sect);
			$sect = $('<div class="newslist"></div>').appendTo($sect);
			var $dl = $('<dl/>').appendTo($sect);
			var $dt = $('<dt/>')
				.text('記事がありません')
				.appendTo($dl);
	}
}

function buildAarticleWhatsNew(o) {

	var recs = o.article;

	for (i = 0; i < recs.length; i++) {
		var record = recs[i];
		var date = record.date;

		$('<dt/>')
			.text(date.year + '.' + date.month + '.' + date.day)
			.appendTo('#whats');
		$title = $('<dd/>')
			.appendTo('#whats');
		$('<a/>')
			.attr('href',record.url)
			.text(record.title)
			.appendTo($title);
	}
}

function getRequest(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++) { 
	 hash = hashes[i].split('='); 
	 vars.push(hash[0]);
	 vars[hash[0]] = hash[1];
	}
	return vars;
}

function getCurrentYear(){
	var d = new Date();
	var this_year = d.getFullYear();
	return this_year;
}

