/*

Last UpDate 2011-05-19

*/

$(function(){
	//現在居るファイル名	   
	var currentFile = location.href.split('/').pop();
	
	//ua取得
	var ua = navigator.userAgent;

	//classが、'nav'で終わるulの、最後のliに、'last'クラスを付ける
	$('ul[class$="nav"]').each(function(){
		$('li:last',this).addClass('last');
	});

	/* ウィンク効果 */
	//$("a img").hover(function(){
		//$(this).css("opacity", "0.2");
		//$(this).css("filter", "alpha(opacity=20)");
		//$(this).fadeTo("slow", 1.0);
	//});

	//classが、'nav'で終わるulの、最後のliに、'last'クラスを付ける
	$('ul[class$="nav"]').each(function(){
		$('li:last',this).addClass('last');
	});
	
	//classが、'navs'で終わるulの、最初のliに、'first'クラスを付ける
	$('ul[class$="navs"]').each(function(){
		$('li:first',this).addClass('first');
	});

	//classが、'list'で終わるulの、偶数の要素に、'even'クラスを付ける
	$('ul[class$="list"] li:nth-child(even)').addClass('even');

	//classが、'table'で終わるテーブルの、偶数trに、'even'クラスを付ける
	$('table[class$="table"] tr:nth-child(even)').addClass('even');

	//classが、'number'で終わるulの、4番目のliに、'hoge'クラスを付ける
	$('ul[class$="number"] li:nth-child(4n)').addClass('hoge');

	//fancybox(lightbox)
	try{
		$("div a").fancybox({
			'zoomOpacity' : true,'overlayShow' : false,'zoomSpeedIn' : 500,'zoomSpeedOut' : 500});
	}catch(e){}

	//rollover
	$('a img').each(function(){
		var imgSrc = $(this).attr('src');
		//smartRollover
		if(imgSrc.match(/(.*)_off(\..*)/)){
			var repSrc = RegExp.$1+'_on'+RegExp.$2;
			$('<img />').attr('src',repSrc);
			$(this).hover(function(){
				$(this).attr('src',repSrc);
				$(this).css({opacity: '1',filter: 'alpha(opacity=100)'});
			},function(){
				$(this).attr('src',imgSrc);
			});
		//ロールオーバーが無い場合は、透明度80%
		}else if(!$(this).hasClass('not')){
			$(this).hover(function(){
					$(this).css({
						opacity: '0.8',
						filter: 'alpha(opacity=80)'
					});
			},function(){
					$(this).css({
						opacity: '1',
						filter: 'alpha(opacity=100)'
					});
			}
			
			);
		}
	});

	/* 
	お問い合わせフォームの送信ボタンで、ロールオーバーやウィンク、とpngに指示があった場合に
	ご利用ください。使わない方は”削除”してください
	*/
	
	//タイプ1.submit押した感 & smartrollover
	$('form p input').mousedown(function(){
		$(this).css({position:'relative',top:'1px',left:'1px'});
	}).mouseup(function(){
		$(this).css({position:'static'});
	}).mouseout(function(){
		$(this).css({position:'static'});
	})
	  .hover(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.*)_off.(.*)$/,'$1_on.$2'));
	},function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.*)_on.(.*)$/,'$1_off.$2'));
	});
	
	/* ←使う際は、このコメントを削除してください
	//タイプ2.submit押した感 & ウィンク
	$('form p.submit input').mousedown(function(){
		$(this).css({position:'relative',top:'1px',left:'1px'});
	}).mouseup(function(){
		$(this).css({position:'static'});
	}).mouseout(function(){
		$(this).css({position:'static'});
	})
	  .hover(function(){
		$(this).css({opacity:0.2});
		$(this).fadeTo('slow',1.0);
	});
	*/

  // #で始まるアンカーをクリックした場合に処理
   $('a[href^=#]').click(function() {
      // スクロールの速度
      var speed = 400;// ミリ秒
      // アンカーの値取得
      var href= $(this).attr("href");
      // 移動先を取得
      var target = $(href == "#" || href == "" ? 'html' : href);
      // 移動先を数値で取得
      var position = target.offset().top;
      // スムーススクロール
      $($.browser.safari ? 'body' : 'html').animate({scrollTop:position}, speed, 'swing');
      return false;
   });


  // www.sample.com以外の外部リンクはtarget="_blank"を自動指定
	$(document).ready( function () {
		$('a[href^="http"]').not('[href*="www.sample.com"]').click(function(){
		window.open(this.href, '');
		return false;});
	});

  // スライドショー　　crossslide.jsが必須
	$('#slide #slideimg').crossSlide({
	  fade: 0.2    //sec
	}, [
		{ src: 'image/slide/01.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:1.0},
		{ src: 'image/slide/02.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:0.8},
		{ src: 'image/slide/03.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:0.8},
		{ src: 'image/slide/04.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:0.8},
		{ src: 'image/slide/05.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:0.8},
		{ src: 'image/slide/06.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:0.8},
		{ src: 'image/slide/07.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:0.8},
		{ src: 'image/slide/08.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:0.8},
		{ src: 'image/slide/09.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:3.0},
		{ src: 'image/slide/10.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:2.0},
		{ src: 'image/slide/11.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:1.5},
		{ src: 'image/slide/12.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:1.5},
		{ src: 'image/slide/13.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:4.0},
		{ src: 'image/slide/14.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:2.0},
		{ src: 'image/slide/15.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:1.5},
		{ src: 'image/slide/16.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:4.0},
		{ src: 'image/slide/17.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:2.0},
		{ src: 'image/slide/18.jpg' , from: '100% 100%' , to:   '100% 100%' ,time:60.0}
	]);

  // カレント表記
	var currentURL = location.href;

	$("ul.menu li a").each(function(){
		var target = $(this).attr("href");
		var re = new RegExp(target + "$");
		
		if(currentURL.match(re) != null ){
			$("img",this).attr("src",$("img",this).attr("src").replace("_off","_on"));
		}
	});

	$("#side dl dd a").each(function(){
		var target = $(this).attr("href");
		var re = new RegExp(target + "$");
		
		if(currentURL.match(re) != null ){
			$(this).addClass("current");
		}
	});

});
