var archiveEntry = new function(){
	
	this.changeScale = function(){
		var container = document.getElementById("archiveEntryList").getElementsByTagName("ul")[0];

		if(document.getElementById("scaleButtonImage").src.indexOf("scaleup") != -1){
			document.getElementById("scaleButtonImage").src = "/common/img/btn_area_scaledown.gif";
			container.style.height = "250px";
		}else{
			document.getElementById("scaleButtonImage").src = "/common/img/btn_area_scaleup.gif";
			container.style.height = "78px";
		}
	};
	
	function createXMLHttp(url){
		var xmlHttp;
		
		try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
				xmlHttp=new XMLHttpRequest();
		}
		
		xmlHttp.onreadystatechange = function() {
		　　　　if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		　　　　　　onComplete(xmlHttp,url);
		　　　　}
		　　};
		
		xmlHttp.open("GET",url,true); 
		xmlHttp.send(null);
	}
	
	function onComplete(xmlHttp,url){
		if(url == archiveEntryXML){
			var text = document.getElementById("pageTitle").firstChild.lastChild.nodeValue;
			var categoryTitleContainer = document.getElementById("archiveEntryList").getElementsByTagName("div")[0];
			categoryTitleContainer.firstChild.nodeValue = xmlHttp.responseXML.getElementsByTagName("data")[0].getAttribute("title") + text+"一覧";
			var container = document.getElementById("archiveEntryList").getElementsByTagName("ul")[0];
			var count = xmlHttp.responseXML.getElementsByTagName("item").length;
			var html = "";
			
			for(var i = 0; i < count; i++){
				var date = xmlHttp.responseXML.getElementsByTagName("item")[i].getAttribute("date").slice(0,10);
				var title = xmlHttp.responseXML.getElementsByTagName("item")[i].getAttribute("title");
				var url = xmlHttp.responseXML.getElementsByTagName("item")[i].getAttribute("href");
				html += "<li><span class='date'>"+date+"</span> ： <a href='"+url+"'>"+title+"</a></li>";
			}
			
			container.innerHTML = html;
		}else{
			return;	
		}
	}
	
	function drawBaseHTML(){
		document.write(
				 '<div id="archiveEntryList">'
				+'	<div class="title">　</div>'
				+'	<ul>'
				+'		<li>ロード中…</li>'
				+'	</ul>'
				+'	<div class="scaleButton"><a href="#" onclick="archiveEntry.changeScale(); return false;"><img id="scaleButtonImage" src="/common/img/btn_area_scaleup.gif" alt="" width="55" height="19" /></a></div>'
				+'</div>');
	}
	
	var path = window.location.href;
	var archiveEntryXML = path.slice(0,path.lastIndexOf("/")+1) + "index.xml";
	
	drawBaseHTML();
	createXMLHttp(archiveEntryXML);
}