/* ================================================================================
* Title: Jquery Function
*
* Copyright (c) 2009 Astra The Studio Inc.
* http://www.studio.co.jp/
* Date: Feb.13, 2009
* @author: Chihiro Mori
* @version: 1.0.3
*
* jQuery 1.3.2
*
* 確認済ブラウザ: [Mac] FireFox3.0, Safari3.1.2 [Win] IE6.0, 7.0
* Macで作業するときの注意：バックスラッシュ\を入力するときはoptionを押しながらエンマーク
================================================================================ */
/* 目次
selfLink():
対象：ページ内の全てのHEEF属性を持ったAタグ（#のみ、hoge.html#hoge、は除外）
・自ページリンクにcurrentクラスを付与し、href属性を削除
・ページ内リンクのスムーススクロール
※スラッシュ（/）とファイル名を省略したアクセスの場合は、/index.htmlを補完して評価

menuRollover():
対象： ul#cNav img, div#detailMenuList img 
透明効果を使ったIMGタグのマウスオーバー
※imgの親のAタグがcurrentだったら完全透明となり、背景が透過。

pulldown():
イベントの設定：ul#cNav li.pulldown, li#detailMenuListSub
イベントの対象：上記に含まれるDIVタグ

headerScroll():
positionにfixを指定した要素も、横スクロールに対応できるようにする。
IDに#headerWrapを指定した、DIV等のブロック要素のみ評価。

*/
(function($)
{
//---------------------------------------------------------------------
	$(function()
	{
		$.ASconf.selfLink();
		$.ASconf.selfScroll();
		$.ASconf.menuRollover();
		$.ASconf.btnRollover();
		$.ASconf.homeEffect();
	});
//---------------------------------------------------------------------
	$.ASconf =
	{
	//---------------------------------------------------------------------
		selfLink: function ()
		{
			var selfLinkClass = 'current';
			var pdfLinkClass = 'pdf';
			var blankLinkClass = 'blank';

			$.ASconf.theUrl = location.href.replace(location.hash, '').replace(/(\/|\#)$/, '/index.html');
			$.ASconf.shrUrl = document.getElementById('baseCSS').href.replace('css/import.css', '');
			
			$('a[href]').each(function()
			{
				var i = document.createElement('span');
				var path = $(this).attr('href');
				i.innerHTML = '<a href="' + path + '" />';
				var absolutePath = i.firstChild.href;
				var host = i.firstChild.hostname;
				if(absolutePath == $.ASconf.theUrl)
				{
					$(this).addClass(selfLinkClass).removeAttr('href');
				}
				else if(path.match(/pdf$/))
				{
					$(this).append(' <img alt="pdf" src="' + $.ASconf.shrUrl + '/img/icon_pdf_small.gif' + '" />').addClass(pdfLinkClass);
				}
				else if(path.match(/^http/))
				{
					$(this).filter(function (i) {
						return !($(this).find('img')[0]);
					})
					.attr('target', '_blank').append(' <img alt="blank" src="' + $.ASconf.shrUrl + '/img/icon_blank.gif' + '" />').addClass(blankLinkClass);
				}
			});
		}
		,
		//-----------------------------------------------------------------
		selfScroll: function()
		{
			var headerfix = 0;
			
			$('a[href*=#]').click(function()
			{
				var hash = this.hash;
				if(!hash || hash == "#")
					return false;
				if(this.href.replace(hash, '') == $.ASconf.theUrl)
				{
					//function addHash(event) {location.href = location.href + hash;}

					$($.browser.safari ? 'body' : 'html')
					.animate({scrollTop: $(hash).offset().top - headerfix}, 500);
					return false;
				}
			});
			
//			var locationHash = location.hash;
//			if(locationHash)
//			{//別ページへ移動するときもスムースに！
//				var isMSIE = /*@cc_on!@*/0;
//				 if(isMSIE) {
//				 //IEの場合はちょっと待ってからスクロール
//				 setTimeout(function(){scrollTo(0,0);$('html').animate({scrollTop: $(locationHash).offset().top - headerfix}, 500);},50);
//				 } else {
//					scrollTo(0, 0);
//					$($.browser.safari ? 'body' : 'html')
//					.animate({scrollTop: $(locationHash).offset().top - headerfix}, 500);
//				 }
//			}
		}
		,
		//-----------------------------------------------------------------
		selfScroll: function()
		{
			var headerfix = 0;
			//var locationHref = location.href;
			var locationHash = location.hash;
			
			$('a[href*=#]').click(function()
			{
				var hash = this.hash;
				if(!hash || hash == "#")
					return false;
				if(this.href.replace(hash, '') == $.ASconf.theUrl)
				{
					//function addHash(event) {location.href = location.href + hash;}

					$($.browser.safari ? 'body' : 'html')
					.animate({scrollTop: $(hash).offset().top - headerfix}, 500);
					return false;
				}
			});
			
			if(locationHash)
			{//別ページへ移動するときもスムースに！
				var isMSIE = /*@cc_on!@*/0;
				 if(isMSIE) {
				 //IEの場合はちょっと待ってからスクロール
				 setTimeout(function(){scrollTo(0,0);$('html').animate({scrollTop: $(locationHash).offset().top - headerfix}, 500);},50);
				 } else {
					scrollTo(0, 0);
					$($.browser.safari ? 'body' : 'html')
					.animate({scrollTop: $(locationHash).offset().top - headerfix}, 500);
				 }
			}
		}
		,
		//-----------------------------------------------------------------
		menuRollover: function()
		{
			var parentClass = 'current';
			
			$('a img:not(p#logoE img,p#logoJ img)').each(function()
			{
				if($(this).parent().attr('class') == parentClass)
					$(this).fadeTo(0, 0.7);
				else
					$(this).hover(function(){
						$(this).not(':animated').fadeTo('fast', 0.6);}
					,function(){
						$(this).fadeTo('fast', 1);});
			});
		}
		,
		//-----------------------------------------------------------------
		btnRollover: function()
		{
			$('div#main img.btn').hover(function(){
				$(this).not(':animated').fadeTo('fast', 0.6);}
			,function(){
				$(this).fadeTo('fast', 1);});
		}
		,
		//-----------------------------------------------------------------
		homeEffect: function()
		{
			$('div#main.home div.box').each(function()
			{
				var href = $(this).find('a').attr('href');
				$(this).filter(function (i) {
						return $(this).find('a')[0];
				})
				.css('cursor','pointer')
				.hover(function(){
					$(this).not(':animated').fadeTo('fast', 0.6);}
				,function(){
					$(this).fadeTo('fast', 1);})
				.click(function(){
					location.href = href;
				});
			});
			$('#homeVisual').each(function()
			{
				$(this).flash(
				{
					swf: 'shr/img/visual.swf',
					width: 690,
					height: 200,
					wmode: 'transparent',
					hasVersion: 8, // requires Flash 9
					hasVersionFail: function (options) { return false; }
				});
			});
		}
	//-----------------------------------------------------------------
	};
//---------------------------------------------------------------------
})(jQuery);
