$(document).ready(function (){

function fakeRSSCall()
{
//		var entry = r.getElementsByTagName('item');
		var html  = [];
//		var len   = entry.length;
		html.push('<ul>');
		html.push('<li><a href="http://www.ryzwear.jp/contest/contribution.php"><span>2011.9.1</span>&nbsp;チャリティコンテスト　RISE UP　スタート!</a></li>');
/*
		for(var i=0; i<len; i++) {
			var title  = entry[i].getElementsByTagName('title')[0].firstChild.nodeValue;
//			var url    = entry[i].getElementsByTagName('link')[0].firstChild.nodeValue;//
			var url    = 'http://www.ryzwear.jp/category/news';
			var date   = entry[i].getElementsByTagName('pubDate')[0].firstChild.nodeValue;
			newDate    = new Date(date);
			var Y = newDate.getFullYear();
			var M = newDate.getMonth() + 1;
			var d = newDate.getDate();

			html.push('<li>');
			html.push('<a href="'+ url +'">');
			html.push('<span>');
			html.push(Y + '.' + M + '.' + d);
			html.push('</span>&nbsp;');
			html.push(title);
			html.push('</a>');
			html.push('</li>');
		}
*/
		html.push('</ul>');
		$('#topnews').html(html.join(''));				

		var topnews   = $('#topnews');
		var scroll    = $('#topnews ul');
		var news      = $('#topnews ul li');
		var time      = 5000;
		var i         = 0;
		var lock      = false;
		
		if (news.size() < 2){
			news.css('display', 'block');
		}
		else {
			news.css('display', 'none');
		
			var prev  = 0;
			var next  = 1;
			var timer = function () {
				setTimeout(function () {
					news.eq(prev).fadeOut(500, function () {
						news.eq(next).fadeIn(500, timer);
						prev = next;
						next = (news.size() == next + 1) ? 0 : next + 1;
					});
				}, time);
			};
			
			news.eq(0).fadeIn(500, timer);
		}
	}
fakeRSSCall();
$.ajax({
	url     : 'http://www.ryzwear.jp/?feed=rss2&cat=6',
	type    : 'GET',
	dataType: 'xml',
	cache   : false,
	success : function (r) {
		var entry = r.getElementsByTagName('item');
		var html  = [];
		var len   = entry.length;
		html.push('<ul>');
		html.push('<li><a href="http://www.ryzwear.jp/contest/contribution.php"><span>2011.9.1</span>&nbsp;チャリティコンテスト　RISE UP　スタート!</a></li>');
/*
		for(var i=0; i<len; i++) {
			var title  = entry[i].getElementsByTagName('title')[0].firstChild.nodeValue;
//			var url    = entry[i].getElementsByTagName('link')[0].firstChild.nodeValue;//
			var url    = 'http://www.ryzwear.jp/category/news';
			var date   = entry[i].getElementsByTagName('pubDate')[0].firstChild.nodeValue;
			newDate    = new Date(date);
			var Y = newDate.getFullYear();
			var M = newDate.getMonth() + 1;
			var d = newDate.getDate();

			html.push('<li>');
			html.push('<a href="'+ url +'">');
			html.push('<span>');
			html.push(Y + '.' + M + '.' + d);
			html.push('</span>&nbsp;');
			html.push(title);
			html.push('</a>');
			html.push('</li>');
		}
*/
		html.push('</ul>');
		$('#topnews').html(html.join(''));				

		var topnews   = $('#topnews');
		var scroll    = $('#topnews ul');
		var news      = $('#topnews ul li');
		var time      = 5000;
		var i         = 0;
		var lock      = false;
		
		if (news.size() < 2){
			news.css('display', 'block');
		}
		else {
			news.css('display', 'none');
		
			var prev  = 0;
			var next  = 1;
			var timer = function () {
				setTimeout(function () {
					news.eq(prev).fadeOut(500, function () {
						news.eq(next).fadeIn(500, timer);
						prev = next;
						next = (news.size() == next + 1) ? 0 : next + 1;
					});
				}, time);
			};
			
			news.eq(0).fadeIn(500, timer);
		}
	}
});
});

