
(function($) {

	$(function() {
		$.story.Pagetop();
		$.story.News();
		$.story.NavRss('shopping_diary');
		$.story.NavRss('report');
		$.story.rollover();
		$.story.LinkBlock();
	});

	//---------------------------------------------------------------------
	$.story = {
		
		//リンクブロック
		LinkBlock: function() {
			$('div.topright li a').each(function(){
			  var Href = $(this).attr('href');
			  $(this).parents("li").click(function() {
				window.open(Href,'_self');
				return false;
			  });
			});
			$('div.topright li').append('<div class="ovlay"></div>')
								.hover(function(){
									$(this).find('div.ovlay').stop().animate({width: "100%"}, 200);
								  },function(){
									$(this).find('div.ovlay').stop().animate({width: "0px"}, 200);
								  });			
		},
		
		//ページ内リンク
		Pagetop: function(){ 
			$('a[href^=#]').click(function () {
				$(this).blur();
				var href = $(this).attr("href");
				var topPx = $(href).offset().top;
				$('html,body').animate({ scrollTop: topPx }, 500, "swing");
				return false;
        	});
		},
		
		
		//all xml読み込み
		News: function(){			
			 $.ajax({
				url: 'index.xml',
				type: 'GET',
				dataType: 'xml',
				timeout: 2000,
				success: function(xml){
					var data = $(xml).find("item");
					var num = 0;
					$("div#news").append('<ul></ul>');
						data.each(function(){
						//3件表示			   
						if(num<3) {
						var title = $(this).find("title").text();
						var date = $(this).find("viewDate").text();
						var links = $(this).find("link").text();

						// 文字制限 2010.09.01追加
						var len = 40;
						var title = $("title", this).text();
						title = title.length > len ? title.substr(0, len) + "…" : title;
						
						//dom構築
						var html = '<li><a href="'+links+'"><span>'+ date +'</span>'+ title +'</a></li>';
						$("div#news ul").append(html);
						};
						num++;
					});
				} //success
			});//$.ajax
		},//all
		
		//all xml読み込み
		NavRss: function(name){			
			 $.ajax({
				url: name + '/index.xml',
				type: 'GET',
				dataType: 'xml',
				timeout: 2000,
				success: function(xml){
					var data = $(xml).find("item");
					var num = 0;
						data.each(function(){
						//1件表示			   
						if(num<1) {

						var title = $(this).find("title").text();
						var date = $(this).find("viewDate").text();
						var strlen = title.length;
						if(strlen > 18) { title = title.substr(0,15) +'...'; }
						
						//dom構築
						var html = '<span>'+ date +'</span>'+ title;
						$("div.topright p#" + name).append(html);
						
						};
						num++;
					});
				} //success
			});//$.ajax
		},//all
		
		//ロールオーバー
		rollover: function() {
				var preLoad = new Object();
				$('img.rollover,input.rollover').not("[src*='_o.']").each(function(){
					var imgSrc = this.src;
					var fType = imgSrc.substring(imgSrc.lastIndexOf('.'));
					var imgName = imgSrc.substr(0, imgSrc.lastIndexOf('.'));
					var imgOver = imgName + '_o' + fType;
					preLoad[imgSrc] = new Image();
					preLoad[imgSrc].src = imgOver;
					$(this).hover(
						function (){ this.src = imgOver; },
						function (){ this.src = imgSrc; }
					);
				});
		}
		
	};
})(jQuery);