/* ================================================================================
* Title: Jquery Function
*
* Copyright (c) 2010 Astra The Studio Inc.
* http://www.studio.co.jp/
* Date: Mar.26, 2010
* @author: Chihiro Mori Otto Kamiya 
* @version: 1.0.5
*
* jQuery 1.4.2
*
* 確認済ブラウザ: [Mac] FireFox3.0, Safari3.1.2 [Win] IE6.0, 7.0, 8.0
* Macで作業するときの注意：バックスラッシュ\を入力するときはoptionを押しながらエンマーク
================================================================================ */
/* 目次
selfLink():
自ページリンク（ハッシュは除外）にcurrentクラスを付与し、href属性を削除。
※スラッシュ（/）とファイル名を省略したアクセスの場合は、/index.htmlを補完して評価

selfScroll(): 
ページ内リンクのスムーススクロール。href属性にハッシュ（#）を指定したAタグを評価。
※ファイル名とhashの組み合わせ（hoge.html#hoge）は評価しない。
※headerfixの値にヘッダーの高さを指定すると、アンカーリンクで飛んだときにヘッダーに隠れない。

menuRollover():
透明効果を使った画像のマウスオーバー。IDに#cNavを指定した、DIV等のブロック要素の子タグのみ評価。
※imgの親のAタグがcurrentだったら透明度0になり背景画像が表示される。

btnRollover():
透明効果を使った画像のマウスオーバー。class="btn"を指定したimgタグを評価。
※imgの親のAタグがcurrentだったら透明度0.7になる。

headerScroll():
positionにfixを指定した要素も、横スクロールに対応できるようにする。
IDに#headerWrapを指定した、DIV等のブロック要素のみ評価。

*/
(function($)
{
//---------------------------------------------------------------------
	$(function()
	{
		$.ASconf.selfLink();
		$.ASconf.selfScroll();
		$.ASconf.menuRollover();
		$.ASconf.btnRollover();
		$.ASconf.btnRolloverSP();
		$.ASconf.headerScroll();
		$.ASconf.historyBack();
		
		//ブラウザの戻るを使ってもスクリプトが実行されるように
		window.onunload= function(){};
	});
//---------------------------------------------------------------------
	$.ASconf =
	{
	//---------------------------------------------------------------------
		selfLink: function ()
		{
			var selfLinkClass = 'current';
			
			var theUrl = location.href.replace(location.hash, '').replace(/(\/|\#)$/, '/index.html');
			
			$('a[href]').each(function()
			{
				var i = document.createElement('span');
				i.innerHTML = '<a href="' + $(this).attr('href') + '" />';
				var absolutePath = i.firstChild.href;
				if(absolutePath == theUrl)
					$(this).addClass(selfLinkClass).removeAttr('href');
			});
		}
		,
		//-----------------------------------------------------------------
		selfScroll: function()
		{//^は初めの文字が#だった場合。*にするとhoge.html#hogeもマッチ
		//headerfixはヘッダーが固定の場合のヘッダーの高さ
			if (typeof document.documentElement.style.maxHeight != "undefined")
			{// IE 7.0 以上 または Gecko などモダンブラウザー
				var headerfix = 140;
				var locationHash = location.hash;
				$('a[href^=#]').click(function()
				{
					var hash = this.hash;
					if(!hash || hash == "#")
						return false;
					$($.browser.safari ? 'body' : 'html')
					.animate({scrollTop: $(hash).offset().top - headerfix}, 300, "swing");
					return false;
				});
				
				if(locationHash)
				{//別ページへ移動するときもスムースに！
					var isMSIE = /*@cc_on!@*/0;
				   if(isMSIE) {
					 //IEの場合はちょっと待ってからスクロール
					 setTimeout(function(){scrollTo(0,0);$('html').animate({scrollTop: $(locationHash).offset().top - headerfix}, 300, "swing");},50);
				   } else {
						scrollTo(0, 0);
						$($.browser.safari ? 'body' : 'html')
						.animate({scrollTop: $(locationHash).offset().top - headerfix}, 300, "swing");
				   }
				}		
			}
		}
		,
		//-----------------------------------------------------------------
		menuRollover: function()
		{
			var parentClass = 'current';
			
			$('#gNavi li').each(function()
			{
				if($(this).find('a').attr('class') == parentClass)
					$(this).fadeTo(0, 0);
				else
				{
					$(this).hover(function(){
						$(this).not(':animated').fadeTo('fast', 0);}
					,function(){
						$(this).fadeTo('fast', 1);});
				};
			});
		}
		,
		//-----------------------------------------------------------------
		btnRollover: function()
		{
			var parentClass = 'current';
			
			$('li.btn').each(function()
			{
				if($(this).find('a').attr('class') == parentClass)
					$(this).fadeTo(0, 0.7);
				else
				{
					$(this).hover(function(){
						$(this).not(':animated').fadeTo('fast', 0.7);}
					,function(){
						$(this).fadeTo('fast', 1);});
				};
			});
		}
		,
		//-----------------------------------------------------------------
		btnRolloverSP: function()
		{
			var parentClass = 'current';
			
			$('a.btn').each(function()
			{
				if($(this).attr('class') == parentClass)
					$(this).fadeTo(0, 0.7);
				else
				{
					$(this).hover(function(){
						$(this).not(':animated').fadeTo('fast', 0.85);}
					,function(){
						$(this).fadeTo('fast', 1);});
				};
			});
		}
		,
		//-----------------------------------------------------------------
		headerScroll: function()
		{
			var target = $('#hWrapper');
			
			function winScroll(e)
			{
				var scrollLeft = $(document).scrollLeft();
				target.stop().css('left', -scrollLeft);
			}
			winScroll();//FireFoxでGoogle Analyticsと併用すると、ページ読み込み時のscrollイベントが発生しない為その対策
			$(window).bind('scroll', winScroll);
			$(window).bind('resize', winScroll);
		}
		,
		//-----------------------------------------------------------------
		historyBack: function()
		{
			$('#before').click(function()
			{
				window.history.back();
				return false;
			});
		}
	//-----------------------------------------------------------------
	};
//---------------------------------------------------------------------
})(jQuery);