/* 文字コードはUTF-8 */
subinformation = function(){
	this.init = function(tid, xml_url){
		this.tid = tid;
		this.xml_url = xml_url;
		this.count = (typeof(arguments[2]) != 'undefined' ? arguments[2] : 10);
		this.link_type = (typeof(arguments[3]) != 'undefined' ? arguments[3] : '_self');
		this.dateobj = new Date();
		this.now = this.dateobj.getTime();
		this.object = document.getElementById(this.tid);
		this.object.innerHTML = '<div style="font-size:12px;color:#bbb;">読込中...</div>';
		this.load();
	}
	this.fail = function(){
		this.object.innerHTML = '<div style="font-size:12px;color:#900;">データが読み込めませんでした。</div>';
	}
	this.load = function(){
		xmlhttp.res[this.xml_url] = new Object();
		xmlhttp.res[this.xml_url].pointer = this;
		xmlhttp.res[this.xml_url].exec = function(){
			var html = '';
			var root = xmlhttp.res[this.pointer.xml_url].XML.getElementsByTagName('rss');
			if(root.length > 0){
				var items = root.item(0).getElementsByTagName('item');
				if(items.length > 0){
					html += '<ul>';
					var count = (items.length < this.pointer.count ? items.length : this.pointer.count);
					for(var i = 0; i < count; i++){
						var item = items.item(i);
						var title = xmlhttp.getNodeValue(item, 'title');
						var link = xmlhttp.getNodeValue(item, 'link');
						var pubDate = xmlhttp.getNodeValue(item, 'pubDate');
						var pubtime = Date.parse(pubDate);
						this.pointer.dateobj.setTime(pubtime);
						var year = this.pointer.dateobj.getFullYear();
						var month = this.pointer.dateobj.getMonth() + 1;
						var day = this.pointer.dateobj.getDate();
						var date_str = year + '.' + (month < 10 ? '0' : '') + month + '.' + (day < 10 ? '0' : '') + day;
						var class_name = (i == 0 ? 'first' : ((count - i) == 1 ? 'last' : ''));
						if(this.pointer.now - pubtime < 86400000){
							class_name = (class_name != '' ? ' ' : '') + 'new';
						}
						html += '<li><span class="xs b">' + date_str + '</span><a href="' + link + '" target="' + this.pointer.link_type + '" class="m ar-org">' + htmlspecialchars(title) + '</a></li>';
					}
					html += '</ul>';
				}
				else{
					html += '<div style="font-size:12px;color:#bbb;">現在、準備中です。</div>';
				}
			}
			this.pointer.object.innerHTML = html;
		}
		xmlhttp.res[this.xml_url].fail = this.fail;
		xmlhttp.loadDoc(this.xml_url, 'get', true, true);
	}
}

subblog = function(){
	this.init = function(tid, xml_url){
		this.tid = tid;
		this.xml_url = xml_url;
		this.count = (typeof(arguments[2]) != 'undefined' ? arguments[2] : 10);
		this.link_type = (typeof(arguments[3]) != 'undefined' ? arguments[3] : '_self');
		this.dateobj = new Date();
		this.now = this.dateobj.getTime();
		this.object = document.getElementById(this.tid);
		this.object.innerHTML = '<div style="font-size:12px;color:#bbb;">読込中...</div>';
		this.load();
	}
	this.fail = function(){
		this.object.innerHTML = '<div style="font-size:12px;color:#900;">データが読み込めませんでした。</div>';
	}
	this.load = function(){
		xmlhttp.res[this.xml_url] = new Object();
		xmlhttp.res[this.xml_url].pointer = this;
		xmlhttp.res[this.xml_url].exec = function(){
			var html = '';
			var root = xmlhttp.res[this.pointer.xml_url].XML.getElementsByTagName('rss');
			if(root.length > 0){
				var items = root.item(0).getElementsByTagName('item');
				if(items.length > 0){
					html += '<ul>';
					var count = (items.length < this.pointer.count ? items.length : this.pointer.count);
					for(var i = 0; i < count; i++){
						var item = items.item(i);
						var title = xmlhttp.getNodeValue(item, 'title');
						var link = xmlhttp.getNodeValue(item, 'link');
						var pubDate = xmlhttp.getNodeValue(item, 'pubDate');
						var content_encoded = xmlhttp.getNodeValue(item, 'content:encoded');
						var pubtime = Date.parse(pubDate);
						this.pointer.dateobj.setTime(pubtime);
						var year = this.pointer.dateobj.getFullYear();
						var month = this.pointer.dateobj.getMonth() + 1;
						var day = this.pointer.dateobj.getDate();
						var date_str = year + '.' + (month < 10 ? '0' : '') + month + '.' + (day < 10 ? '0' : '') + day;
						html += '<li><img src="/resource/image/blog/ico_update.gif" alt="Updated" width="50" height="12" /><p class="xs b update-txt"><a href="' + link + '" target="' + this.pointer.link_type + '">' + date_str + '　' + htmlspecialchars(title) + '</a></p><p class="m"><a href="' + link + '" target="' + this.pointer.link_type + '">' + content_encoded + '</a></p></li>';
					}
					html += '</ul>';
				}
				else{
					html += '<div style="font-size:12px;color:#bbb;">現在、準備中です。</div>';
				}
			}
			this.pointer.object.innerHTML = html;
		}
		xmlhttp.res[this.xml_url].fail = this.fail;
		xmlhttp.loadDoc(this.xml_url, 'get', true, true);
	}
}

function htmlspecialchars(str){
	str = str.replace(/&/, '&amp;');
	str = str.replace(/</, '&lt;');
	str = str.replace(/>/, '&gt;');
	return str;
}
