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";
			$("#archiveEntryList ul").animate({"height":"250px"},"fast");
			$("#archiveEntryList .scaleButton").animate({"top":"251px"},"fast");
		}else{
			document.getElementById("scaleButtonImage").src = "/common/img/btn_area_scaleup.gif";
			$("#archiveEntryList ul").animate({"height":"78px"},"fast");
			$("#archiveEntryList .scaleButton").animate({"top":"79px"},"fast");
		}
		
	};
	
	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 = $("#archiveEntryList div:eq(0)");
			$categoryTitleContainer.text($("data:eq(0)",xmlHttp.responseXML).attr("title") + text+"一覧");
			var container = document.getElementById("archiveEntryList").getElementsByTagName("ul")[0];
			var count = $("item",xmlHttp.responseXML).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;
			
			$("#archiveEntryList li a").click(function(){
				if($.cookie("useAjax")=="true"){
					var href = $(this).attr("href");
					if(ajaxLoadHTML(href))	return false;
				}
			});

		}else{
			return;	
		}
	}
	
	function drawBaseHTML(){
		$("#pageTitle").after('<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="640" height="12" /></a></div></div>');
	}
	
	var path = G.href;
	var archiveEntryXML = path.slice(0,path.lastIndexOf("/")+1) + "index.xml";
	drawBaseHTML();
	createXMLHttp(archiveEntryXML);
};
