
$(document).ready(function(){
	initRSSFeed();
});


function initRSSFeed(){
	jQuery.getFeed({url:'/proxy.php?url=http://shokokai.kdrserv.com/news/index.rss',success:onComplete1});
	jQuery.getFeed({url:'/proxy.php?url=http://shokokai.kdrserv.com/seminar/index.rss',success:onComplete2});
	jQuery.getFeed({url:'/proxy.php?url=http://shokokai.kdrserv.com/localnews/index.rss',success:onComplete3});
	function onComplete1(feed) {
		var txt = '◆商工会連合会からのお知らせ：';
		commonFunc(feed, txt);
	}

	function onComplete2(feed) {
		var txt = '◆セミナー開催のお知らせ：';
		commonFunc(feed, txt);
	}

	function onComplete3(feed) {
		var txt = '◆地域の商工会からのお知らせ：';
		commonFunc(feed, txt);
	}


}
//日付表記を変換
function changeDate(str){
	var myDate=new Date(str);
	var YYYY=myDate.getFullYear();
	var MM=myDate.getMonth()+1;
	if(MM<10){MM="0"+MM;}
	var DD=myDate.getDate();
	if(DD<10){DD="0"+DD;}
	var date=YYYY+"/"+MM+"/"+DD;
	return date;
}

function commonFunc(getFeed, getTxt) {
	var temp = getTxt;
	var item = getFeed.items[0];
	temp += changeDate(item.updated)+'&nbsp;&nbsp;';
	temp += item.title;
	addMessage("#marquee1",temp);
}




$(function(){
	/* 例1 */
	$("#marquee1").marquee({
		loop: -1
		// 初期時
		, init: function ($marquee, options){
			if( $marquee.is("#marquee2") ) options.yScroll = "bottom";
		}
		// メッセージ切替表示前
		, beforeshow: function ($marquee, $li){
			var $author = $li.find(".author");
			if( $author.length ){
				$("#marquee-author").html("<span style='display:none;'>" + $author.html() + "</span>").find("> span").fadeIn(850);
			}
		}
		// メッセージ表示切替時（上から下にスライド表示された時）
		, show: function (){
		}
		// メッセージスクロール完了後（スライド表示されたメッセージが左方向へすべてスクロールされた時）
		, aftershow: function ($marquee, $li){
			// find the author
			var $author = $li.find(".author");
			// hide the author
			if( $author.length ) $("#marquee-author").find("> span").fadeOut(250);
		}
	});
	/* 例2 */
	$("#marquee2").marquee({yScroll: "bottom"});
});
var iNewMessageCount = 0;
function addMessage(selector,msg){
	iNewMessageCount++;
	var $ul = $(selector).append("<li>" + msg + "</li>");
	// update the marquee
	$ul.marquee("update");
}
function pause(selector){
	$(selector).marquee('pause');
}
function resume(selector){
	$(selector).marquee('resume');
}

