/*
 * Copyright (c) DESIGN inc. All Rights Reserved.
 * http://www.design-inc.jp/
 *
 */

(function($){

// ロールオーバー
$.fn.rollOver = function(options){
	
	var settings = $.extend({
		selectorFade: 'a.ro-fade img',	// フェードクラス
		selectorReFade: 'a.ro-xfade img',	// フェードクラス（通常時が半透明）
		selectorSwitch: 'a.ro-switch img',	// 画像切替クラス
		selectorFadeswith: 'a.ro-fswitch img',	// フェード画像切替クラス
		animateTime: 300,	// アニメーションの時間
		fadeOpacity: 0.7,	// フェードのパーセンテージ
		attachStr: '-on',	// ロールオーバー画像の名前
		easingStyle: 'easeOutCubic'	//イージング
	}, options);
	
	// フェード
	$(settings.selectorFade).each(function(){
		$(this).hover(function(){
			$(this).animate({opacity: settings.fadeOpacity}, {duration: settings.animateTime, easing: settings.easingStyle, queue: false});
		}, function(){
			$(this).animate({opacity: 1}, {duration: settings.animateTime, easing: settings.easingStyle, queue: false});
		});
	});
	
	// フェード（通常時が半透明）
	$(settings.selectorReFade).css({opacity: settings.fadeOpacity});
	$(settings.selectorReFade).each(function(){
		$(this).hover(function(){
			$(this).animate({opacity: 1}, {duration: settings.animateTime, easing: settings.easingStyle, queue: false});
		}, function(){
			$(this).animate({opacity: settings.fadeOpacity}, {duration: settings.animateTime, easing: settings.easingStyle, queue: false});
		});
	});
	
	// 画像切替
	$(settings.selectorSwitch).not('[src*="' + settings.attachStr + '."]').each(function(){
		this.overImg = new Image();
		this.overImg.src = $(this).attr('src').replace(new RegExp('(\.gif|\.jpg|\.png)$'), settings.attachStr + '$1');
		$(this.overImg).css({position: 'absolute', opacity: 0});
		$(this).before(this.overImg);
		$(this.overImg).hover(function(){
			$(this).css({opacity: 1});
		},
		function(){
			$(this).css({opacity: 0});
		});
	});
	
	// フェード画像切替
	$(settings.selectorFadeswith).not('[src*="' + settings.attachStr + '."]').each(function(){
		this.overImg = new Image();
		this.overImg.src = $(this).attr('src').replace(new RegExp('(\.gif|\.jpg|\.png)$'), settings.attachStr + '$1');
		$(this.overImg).css({position: 'absolute', opacity: 0});
		$(this).before(this.overImg);
		$(this.overImg).hover(function(){
			$(this).animate({opacity: 1}, {duration: settings.animateTime, easing: settings.easingStyle, queue: false});
		},
		function(){
			$(this).animate({opacity: 0}, {duration: settings.animateTime, easing: settings.easingStyle, queue: false});
		});
	});
	
	return this;
};

// ページ内スクロール
$.fn.easingScroll = function(a){
	var e = $.extend({
			easing: 'easeOutCubic',
			duration: 500
		},a),
		t = $.support.boxModel ? navigator.appName.match(/Opera/) ? 'html' : 'html,body' : 'body';
	if(isNaN(e.duration)==null){
		if(e.duration.match(/fast/)) e.duration = 210;
		else if(e.duration.match(/normal/)) e.duration = 410;
		else if(e.duration.match(/slow/)) e.duration = 610;
	}
	$(this).each(function(){
		if(this.hash
		&& $(this.hash).length>0
		&& this.href.match(new RegExp(location.href.split('?')[0]))){
			$(this).click(function(d){
				$(t).queue([]).stop();
				var h = this.hash;
				var c = $(h).offset();
				$(t).animate({
					scrollTop: c.top,
					scrollLeft: c.left
				},{
					duration:e.duration,
					easing:e.easing
				});
				d.preventDefault();
				d.stopPropagation();
			});
		}
	});
	$(document).click(function(d){
		$(t).queue([]).stop();
	});
}

})(jQuery);

jQuery(function($){
	
	// liとtrの奇数・偶数・最初・最後にクラス付与（odd, even, first, last）
	$('li:nth-child(odd), tr:nth-child(odd)').addClass('odd');
	$('li:nth-child(even), tr:nth-child(even)').addClass('even');
	$('li:first-child, tr:first-child').addClass('first');
	$('li:last-child, tr:last-child').addClass('last');
	
	$.fn.rollOver();
	$('a.scroll').easingScroll();
});
