// Easingの追加
jQuery.easing.outexpo = function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(1.7, -10 * t/d) + 1) + b;

};

//全体共通ready時スクリプト
function readyfunc(){
	//簡易TOPバナーアニメーションスクリプト
	var animcnt=7;	//アニメーションコマ数
	var animind=0;
	var baranime = function() {
		animind++;
		if(animind>=(animcnt-1)*2) animind=0;
		if(animind<animcnt){
			$("#anim_patarn").css("margin-left",160-160*animind-1);
		} else {
			$("#anim_patarn").css("margin-left",160-160*((animcnt-1)*2-animind)-1);
		}
		window.setTimeout(baranime, 60);
	};
	//アニメパターンIDがあったらアニメさせる
	if($("#anim_patarn").size()>0){
		$("#anim_patarn").show();
		window.setTimeout(baranime, 100);
	}

	//テーブル偶数行にのみクラスを指定
	$('table.ltab tr:even').addClass('ltabeven');

	//ページ内リンクをスムーズスクロール仕様にする（tico-jpn.com）
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({ scrollTop: targetOffset }, 500, 'outexpo');
				return false;
			}
		}
	});

}
$(document).ready(readyfunc);


$(function(){
	/* サムネイルをスクローラブルにします */
	function buildThumbs($elem){
		var $wrapper		= $elem.next();
		var $menu 		= $wrapper.find('.sc_menu');
		var inactiveMargin 	= 30;
		/* スクロールダウンの高さを取得 */
		$wrapper.scrollTop($menu.outerHeight());
		/* マウスの動作によりサムネイルを動かします */
		$wrapper.bind('mousemove',function(e){
			var wrapperHeight 	= $wrapper.height();
			var menuHeight 	= $menu.outerHeight() + 2 * inactiveMargin;
			var top 	= (e.pageY - $wrapper.offset().top) * (menuHeight - wrapperHeight) / wrapperHeight - inactiveMargin;
			$wrapper.scrollTop(top+10);
		});
	}

	var stacktime;

	$('#menu li > a').bind('mouseover',function () {
		var $this = $(this);

//		buildThumbs($this);

		var pos	=	1;

		var f	=	function(){
			if(pos==$this.next().find('a').size()) clearTimeout(stacktime);
			var o=$this.next().find('a:nth-child('+pos+')');
			var wp=o.height();
			o.css({'height':'10px', 'opacity':'0'});
//			o.css('opacity','0');
			o.css('visibility','visible');
			o.animate({opacity:'1.0', 'height':wp},150);
//			o.animate({opacity:1.0},220);
			++pos;
		};
		/* サムネイル表示タイミングをずらします */
		stacktime = setInterval(f , 50);
	});

	/* liタグ内からマウスアウトしたら隠します */
	$('#menu li').bind('mouseleave',function () {
		var $this = $(this);
		clearTimeout(stacktime);
		$this.find('.sc_menu').css('visibility','hidden').find('a').css('visibility','hidden');
		$this.find('.sc_menu_wrapper').css('visibility','hidden');
	});

	/* サムネイルにマウスオーバーしたらopacityを変更 */
	$('.sc_menu a').hover(
	function () {
		var $this = $(this);
		$this.find('img')
		.stop()
		.animate({'opacity':'1.0'},200);
	},
	function () {
		var $this = $(this);
		$this.find('img')
		.stop()
		.animate({'opacity':'0.3'},200);
	}
);
});

