
(function($){

	$(function(){

		var $news = $("#list-topics dt");
		var length = $news.length;
		var EffectDuration = 500;
		var IntervalTime = 4000;

		$("#headline").append("<ul></ul>");
		$news.each(function(){
			var texts = $(this).next().html();
			$("#headline ul").append("<li>"+texts+"</li>");
			var date = $(this).html();
			if(texts.indexOf("</a>") != -1 || texts.indexOf("</A>") != -1){
				$("#headline li:last>a").append(" ["+date+"]");
			}else{
				$("#headline li:last").append(" ["+date+"]");
			}
		});

		var newsChange = function(step){
			clearTimeout(newstimer);
			newstimer = setTimeout(rotation,IntervalTime+EffectDuration);
			if(step==1){
				//next
				$("#headline li:first").clone(true).appendTo("#headline ul");
				targetY = -24;
				targetIndex = 2;
			}else{
				//prev
				$("#headline li:last").clone(true).css("margin-top","-24px").prependTo("#headline ul");
				targetY = 0;
				targetIndex = 1;
			}
			$("#headline li:first").animate( { marginTop: targetY+"px" }, EffectDuration, 'swing', function(){
				if(step==1){
					$("#headline li:first").remove();
				}else{
					$("#headline li:last").remove();
				}
			});
		}

		// ローテーション
		function rotation(){
			newsChange(1);
		}
		newstimer = setTimeout(rotation,IntervalTime);

		$("#home #headline li").mouseover(function(){
			$(this).attr("style", "background-color:#FFC");
		}).mouseout(function(){
			$(this).removeAttr("style");
		});
		$("#home #headline li").blocklink();

	});

})(jQuery);
