var History = Class.create();

History.prototype = Object.extend(new AttachInnerHTML(), {
	initialize: function(history) {
		this.history = history;
		this.loadUpdateXML();
	},

	loadUpdateXML: function() {
		new Ajax.Request(
			"update/update.xml", {
				method: 'get',
				requestHeaders: ['If-Modified-Since','Wed, 15 Nov 1995 00:00:00 GMT'],
				onSuccess: this.viewHistory.bind(this),
				onFailure : function(error) {
					alert(error.responseText);
				}
			});
	},

	viewHistory: function(xml) {
		var xml = xml.responseXML.documentElement;
		var day = getNode('day', xml);
		var text = "";

		for	(var cnt = 0; cnt < day.length && cnt < this.history; cnt++) {
			var date = getAttributes(day[cnt])['-date'];
			var items = getNode('item', day[cnt]);
			text += '<span class="update_date">' + date.left(4, 2) + '/' + date.substr(4, 2) + '/' + date.right(2) + '</span><br/>';
			for	(var item = 0; item < items.length; item++) {
				var category = getSimpleValue('category', items[item]);
				var modify = getSimpleValue('modify', items[item]);
				var description = getSimpleValue('description', items[item]);
				var title = getSimpleValue('title', items[item]);
				var url = getSimpleValue('url', items[item]);
				text += '<li/><span class="subtitle"><a href="/kanpachi' + url + '">' + title + '</a><br><span class="description">&nbsp;&nbsp;-&nbsp;' + description + '</span></span><br/>';
			}
			text += '<br/>';
		}
		this.attachInnerHTML('update',  text);
	}
});

