/* ================================================================================
* Title: Jquery Function
*
* Copyright (c) 2009 Astra The Studio Inc.
* http://www.studio.co.jp/
* Date: Jan.23, 2009
* @author: Chihiro Mori
* @version: 0.9.1
*
* jQuery 1.2.6
* jQuery.ScrollTo 1.4
* jQuery Color Animations
*
* 確認済ブラウザ: [Mac] FireFox3.0, Safari3.1.2 [Win] IE6.0, 7.0
* Macで作業するときの注意：バックスラッシュ\を入力するときはoptionを押しながらエンマーク
================================================================================ */
/* 目次
selfLink()  :自ページリンクにクラス付与
rollover()  :透明効果を使ったナビゲーションのマウスオーバー
pulldown()  :プルダウンメニュー
loadJS()    :JavaScriptファイル読み込み
selfScroll():ページ内スムーススクロール。loadJS() で ScrollTo を読み込み
topTeaser() :トップページ用マウスオーバー。loadJS() で jQuery Color Animations を読み込み
*/
// フェード処理時のカーソルちらつき対策(Internet Explorer6対策)
try { 
	document.execCommand('BackgroundImageCache', false, true); 
} catch(e) {}

var delayTime = 200;  // メニューの遅延表示時間(ミリ秒) (例) 200 = 0.2秒

var menuFlag = false;
var menuTimerID;
var menuSlideObj;
var menuFadeObj;


function menuTimer() {
	clearTimeout(menuTimerID);
	if (menuFlag) {
		menuFlag = false;
		menuFadeObj.fadeTo(140, 0);
		menuSlideObj.slideDown('fast');
	}
}

(function($)
{
//---------------------------------------------------------------------
	$(function()
	{
		$.ASconf.selfLink();
		$.ASconf.rollover();
		$.ASconf.pulldown();
		$.ASconf.selfScroll();
		$.ASconf.loadJS();
	});
//---------------------------------------------------------------------
	$.ASconf =
	{
	//---------------------------------------------------------------------
		selfLink: function ()
		{
			var c = $.extend(
			{
				selfLinkClass:'current'
			});
			$.ASconf.selfLinkClass = '.' + c.selfLinkClass;
			$.ASconf.theUrl = location.href.replace(location.hash, '');
			var theUrl = $.ASconf.theUrl.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(c.selfLinkClass).removeAttr('href');
				}
			});
		}
		,
		//-----------------------------------------------------------------
		rollover: function()
		{
			var c = $.extend(
			{
				selector:'dl#sNav, dl#tNav'
			});
			$(c.selector).find('dt a').each(function()
			{
				var selfFlag = false;
				$(this).filter($.ASconf.selfLinkClass).each(function()
				{
					selfFlag = true;
					$(this).css('opacity', 0);
				});
				if (selfFlag == false)
				{
					$(this).stop().hover(function()
					{
						$(this).fadeTo(140, 0);						
	
					}
					,function()
					{
						$(this).fadeTo('normal', 1);
						
					});
				}
			});
		}
		,
		//-----------------------------------------------------------------
		pulldown: function()
		{
			var c = $.extend(
			{
				parentSelector:'div#pulldown li.menu' + ':has(a' + $.ASconf.selfLinkClass + ')',
				parentClass:'parentMenu',
				selector:'div#pulldown li.menu, div#pulldown li.void'
			});
			$(c.parentSelector).find('a:first').each(function()
			{
				$(this).css('opacity', 0.5).addClass(c.parentClass);
			});
			
			$(c.selector).stop().hover(function()
			{
				//$(this).find('a:first').not($.ASconf.selfLinkClass).fadeTo(140, 0);
				//$('ul', this).slideDown('fast');
				
				menuFadeObj = $(this).find('a:first').not($.ASconf.selfLinkClass);
				menuSlideObj = $('ul', this);
				menuFlag = true;
				menuTimerID = setTimeout('menuTimer()', delayTime);
			}
			,function()
			{
				$('ul', this).slideUp('fast');
				$(this).find('a:first').not('.'+c.parentClass).fadeTo('normal', 1);
				$(this).find('a:first').filter('.'+c.parentClass).fadeTo('normal', 0.5);
				
				menuFlag = false;
			});
		}
		,
		//-----------------------------------------------------------------
		selfScroll: function()
		{
			var c = $.extend(
			{
				bodyId:'#pagetop'
			});
						
			$('a[href^="#"]').click(function()
			{
				var hash= this.hash;
				var target = hash == c.bodyId ? $('body') : hash; //safari taisaku
				$.scrollTo( target, { duration:300, onAfter:function()
				{
					location.href = $.ASconf.theUrl + hash;
				}});				
				return false;
			});
		}
		,
		
		//-------------------------------------------------------------------
		loadJS: function()
		{
			//goolge site search
			$.getScript('http://www.google.com/coop/cse/brand?form=cse-search-box&lang=ja');
		}
		
		//-------------------------------------------------------------------
	/*	function As_load_swf()
		{
			var param=document.getElementById('loadSwf').getElementsByTagName('mv').item(0);
			var path=param.src.replace(/(\.gif|\.jpg|\.png)/,'\.swf');
			var str='<object data="../../../jp/shr/js/'+path+'" width="'+param.width+'" height="'+param.height+'" type="application/x-shockwave-flash" /><param name="movie" value="'+path+'" /><param name="wmode" value="transparent" /></object>';
	param.parentNode.innerHTML=str
	}
	,
*/
	//-----------------------------------------------------------------
	};
//---------------------------------------------------------------------
})(jQuery);