
/*━━━━━━━━━━━━━━━━━━━
Image Rollover
--------------------------------------*/

$(function(){
	$('img.rollover, .rollover img, input.rollover')
	.not('[src*="_o."]')
	.mouseover(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_o$2'));
	})
	.mouseout(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.+)_o(\.[a-z]+)$/, '$1$2'));
	})
	.each(function(){ //プリロード設定
		$('<img>').attr('src',$(this).attr('src').replace(/^(.+)(\.[a-z]+)$/, '$1_o$2'));
	})
	$('img.current')
	.mouseover(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.+)_c(\.[a-z]+)$/, '$1_o$2'));
	})
	.mouseout(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.+)_o(\.[a-z]+)$/, '$1_c$2'));
	})
	.each(function(){ //プリロード設定
		$('<img>').attr('src',$(this).attr('src').replace(/^(.+)_c(\.[a-z]+)$/, '$1_o$2'));
	})
});

/*━━━━━━━━━━━━━━━━━━━
Opacity2
--------------------------------------*/

$(function(){
	$('#visualSlider ul li img')
	.bind('mouseenter focus',function(){
		var fig = $(this);
		fig.stop().animate({opacity:.3},10,function(){fig.animate({opacity:.8},300)});
	})
	.bind('mouseleave blur',function(){
		$(this).stop().animate({'opacity':3},100);
	});
});

/*━━━━━━━━━━━━━━━━━━━
Include HTML
--------------------------------------*/

$(function(){
	$('[class*="inc:"]').each(function(){
		$(this).load(unescape(this.className.replace(/.*inc:([^ ]+)( .*|$)/, '$1')));
	});
});

/*━━━━━━━━━━━━━━━━━━━
Page Scroller
--------------------------------------*/

(function($){
	$(function(){
		$('.scroll a[href^=#]').initScroll();
	});
	$.fn.initScroll = function(){
		return (this.each(function(){
			$(this).click(function(){
				var target = $('#' + this.getAttribute('href').split('#')[1]);
				if (target){
					$.scroller.start.init({
						endY:target.offset().top
					});
					return false;
				}
			});
		}));
	};
	$.scroller = {
		start: (function(){
			var params;
			var timerId;
			var stepCount = 0;
			var startY = 0;
			var endY = 0;
			var lastY = 0;
			function move(){
				if (stepCount == params.step){
					window.scrollTo(getCurrentX(), params.endY);
					stepCount = 0;
				}
				else if (lastY == getCurrentY()){
					stepCount++;
					window.scrollTo(getCurrentX(), getEasingY());
					lastY = getEasingY();
					timerId = setTimeout(move, Math.floor(1000/params.fps));
				}
			};
			var getCurrentY = function(){
				return (document.body.scrollTop || document.documentElement.scrollTop);
			}
			var getCurrentX = function(){
				return (document.body.scrollLeft || document.documentElement.scrollLeft);
			}
			var getEasingY = function(){
				return (Math.floor(getEasing(params.startY, params.endY, stepCount, params.step, params.easing)));
			}
			var getEasing = function(start, end, stepCount, step, easing){
				var s = stepCount / step;
				return ((end - start) * (s + easing / (100 * Math.PI) * Math.sin(Math.PI * s)) + start);
			}
			return {
				init: function(options){
					params = $.extend({
						easing:100,
						step:30,
						fps:80
					}, options);
					stepCount = 0;
					lastY = params.startY = getCurrentY();
					timerId = setTimeout(move, Math.floor(1000/params.fps));
				}
			};
		})()
	};
})(jQuery);

