/* 文字コードはUTF-8 */
datelist = function(){
	this.init = function(pos, path, type, content_extension){
		document.write('<div id="datelist' + pos + '" class="datelist">読み込み中...</div>');
		var curdate = '';
		if(location.pathname.match(/\/index\-d([0-9]{4,6})/)){
			curdate = RegExp.$1;
			$('h1, title').append('（' + (('' + curdate).length == 4 ? curdate + '年' : curdate.substring(0, 4) + '年' + curdate.substring(4, 6) + '月') + '）');
		}
		var tobj = $('#datelist' + pos).eq(0);
		var xml_url = path + 'datelist_' + type + '.xml';
		$.get(xml_url, {}, function(xml, textStatus){
			var html = '';
			if(textStatus == 'success'){
				if($(xml).find('item').length > 0){
					html += (type == 'y' ? '年' : '月') + '別アーカイブ　<select><option value="">最新のエントリー</option>';
					var items = $(xml).find('item');
					items.each(function(){
						var date = $(this).attr('date');
						var count = $(this).attr('count');
						var date_string = (('' + date).length == 4 ? date + '年' : date.substring(0, 4) + '年' + date.substring(4, 6) + '月');
						html += '<option value="' + date + '"' + (curdate == date ? ' selected="selected"' : '') + '>' + date_string + ' (' + count + '件)</option>';
					});
					html += '</select>';
				}
			}
			tobj.html(html);
			$('select', tobj).change(function(){
				var date = this.options[this.selectedIndex].value;
				location.href = path + 'index' + (date != '' ? '-d' + date : '') + content_extension;
			});
		});
	}
}

