$(window).load(function(){
	
	$.ajax({
		type: 'GET',
		url: 'js/siteinfo/getrss.php',
		dataType: 'xml',
		async: false,
		success: function(rss){
			
			var updates = [];
			$(rss).find('item').each(function(){
				//var date = $(this).find('date').text().split('T')[0];
				var title = $(this).find('title').text();
				var link = $(this).find('link').text();
				var date;
				$(this).children().each(function() {
					if ($(this)[0].tagName == "dc:date") {
						date = $(this).text().split('T')[0];
					}
				});
				//var html = '<a href="'+link+'">'+title+'</a>';
				updates.push([date,title]);
			});
			
			//
			// view next
			//
			var currentOffset = 0;
			$('#news_contents .next').click(function(event){
				currentOffset = currentOffset+1>=updates.length
				              ? 0
				              : currentOffset+1;
				$('#news_contents dt, #news_contents dd').fadeOut(300);
				setTimeout(function(){
					// update information
					$('#news_contents dt').html(updates[currentOffset][0]);
					$('#news_contents dd').html(updates[currentOffset][1]);
					$('#news_contents dt, #news_contents dd').fadeIn(300);
				},300);
				// cancel default event
				event.preventDefault();
			});
			
			//
			// initialize
			//
			//$('#news_contents .next').click();
			$('#news_contents dt').html(updates[0][0]);
			$('#news_contents dd').html(updates[0][1]);
			
			
			//
			// auto transition
			//
			var flagStopTransition = false;
			$('#news')
				.mouseover(function(){
					flagStopTransition = true;
				})
				.mouseout(function(){
					flagStopTransition = false;
				});
			var transitionFunction = function(){
				if ( !flagStopTransition )
				{
					$('#news_contents .next').click();
				}
				setTimeout(transitionFunction,5000);
			};
			setTimeout(transitionFunction,5000);
			
		}
	});
	/*
	var updates = [
		['2011-07-13','‘ω‘）'],
		['2011-07-12','ふう・・・'],
		['2011-07-11','うおおおおおおお！'],
		['2011-07-10','にゅーすないよう！'],
		['2011-07-09','にゅーすないよう？'],
		['2011-07-08','にゅーすないよう。'],
		['2011-07-07','七夕。にゅーすないよう。']
	];
	*/
});
