$(document).ready(function(){
/*
	$.ajax({
		type: "GET",
		url: "news.php",
		cache: false,
		success: xmlParser
	});

	$("#info").hover(
		function(){
			$("#info .newWindow img").stop(false, true).fadeTo("normal",0);
			$("#info-box").stop(false, true).fadeTo("normal",1, function(){ $("#info-box").css('display','block'); } );
		},
		function(){
			$("#info .newWindow img").stop(false, true).fadeTo("normal",1);
			$("#info-box").stop(false, true).fadeTo("fast",0, function(){ $("#info-box").css('display','none'); } );
		}
	);
*/

	$("#header .nav img").each( function() {
		$(this).parent().css('background', 'url('+this.src.replace('off.','on.')+') left top no-repeat' );
	});
	$("#header .nav img").hover(
		function(){
			$(this).stop(false, true).fadeTo("fast",0);
		},
		function(){
			$(this).stop(false, true).fadeTo("fast",1);
		}
	);

	$("#faci h5").hover(
		function(){
			var id = '#'+$(this).attr('class').replace('a','p');
			$("#view dl").each( function() {
				if( $(this).css('display') == 'block' ) {
					$(this).css('display','none');
				}
			});
			$(this).css('color','#999999');
			$(id).css('display','block');
		},
		function(){
			$(this).css('color','#000000');
		}
	);


	$(".outImg").hover(
		function(){
			$(this).stop(false, true).fadeTo("normal",0);
		},
		function(){
			$(this).stop(false, true).fadeTo("normal",1);
		}
	);

	$(".hovImg").hover(
		function(){
			this.src = this.src.replace('off.','on.');
		},
		function(){
			this.src = this.src.replace('on.','off.');
		}
	);

	$(".newWindow").click(
		function(){
			window.open(this.href); return false;
		}
	);

	$(".backBtn").click(
		function(){
			history.back(); return false;
		}
	);

	$(".topBtn").click(
		function(){
			$("html,body").animate({ scrollTop: 0 }, 500); return false;
		}
	);


});

function xmlParser(xml) {

	var now = new Date();
	var startDate = now.getTime() - 365 * 86400000;// 過去1年分
	var lastDate = 0;

	$("#info-box").html('');

	$(xml).find("item").each(function () {
		var title = $(this).find("title").text();
		var url = $(this).find("link").text();

		var date;
		$(this).children().each(function() {
			if ($(this)[0].tagName == "dc:date") {
				date = ''+$(this).text().match(/^[0-9]{2,4}-[0-9]{2}-[0-9]{2}/i);
				date = new Date( date.replace(/-/g,'/') );
			}
		});

		if( lastDate < date.getTime() )  lastDate = date.getTime();
		
		if( date.getTime() > startDate ) {
			$("#info-box").append('<dt>● <a class="title" href="'+ url + '">' + title + '</a></dt><dd>' + chgDate( date ) + '</dd>');
		}
	});
	$("#lastupdate").html( '<b>更新日 ' + chgDate( new Date(lastDate) ) + '</b>' );
}


function chgDate( d ){
	yy = d.getYear();
	mm = d.getMonth() + 1;
	dd = d.getDate();
	if (yy < 2000) { yy += 1900; }
	if (mm < 10) { mm = "0" + mm; }
	if (dd < 10) { dd = "0" + dd; }

	return yy + "/" + mm + "/" + dd;
}


