/* ================================================================================
* 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
* exFixed 1.2.2
* jQuery.ScrollTo 1.4.2
*
* 確認済ブラウザ: [Mac] FireFox3.0, Safari3.1.2 [Win] IE6.0, 7.0
* Macで作業するときの注意：バックスラッシュ\を入力するときはoptionを押しながらエンマーク
================================================================================ */
/* 目次
selfLink()     : 自ページリンクにクラス付与
loadFlash()    : SWFObject使ったFlashファイルの埋め込み
fontSwitcher()  : フォントサイズ変更
menuRollover() : 透明効果を使ったナビゲーションのマウスオーバー
btnRollover()  : 透明効果を使ったナビゲーションのマウスオーバー(クラス付与)
selfScroll()   : ページ内スムーススクロール。jQuery.ScrollTo を使用
loadCseId()    : Googleカスタム検索のロゴ読み込み
*/
(function($)
{
//---------------------------------------------------------------------
	$(function()
	{
	//	$.ASconf.selfLink();
		var agent = navigator.userAgent;
		if(agent.indexOf("Mac") == -1 || agent.indexOf("Firefox") == -1)
		{//Mac FirefoxではFlashと相性が悪いので、表示しない
			$.ASconf.pulldown();
		}
		$.ASconf.menuRollover();
		$.ASconf.btnRollover();
		$.ASconf.selfScroll();
		$.ASconf.menuScroll();
		$.ASconf.ec();
		//$('#headerWrap').exFixed(); // for IE6 'position:fixed'
	});
//---------------------------------------------------------------------
	$.ASconf =
	{
	//---------------------------------------------------------------------
		selfLink: function ()
		{
			var c = $.extend(
			{
				selfLinkClass:'current'
			});
			
			$.ASconf.selfLinkClass = '.' + c.selfLinkClass;
			$.ASconf.theUrl = location.href.replace(location.hash, '');
			$.ASconf.shrUrl = document.getElementById('baseCSS').href.replace('css/import.css', '');
			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');
				}
			});
		}
		,
		//-----------------------------------------------------------------
		pulldown: function()
		{
			var c = $.extend(
			{
				selector:'#cNav li[id]'
			});
			
			$(c.selector).hover(function()
			{
				$(this).find('ul:not(:animated)').slideDown('normal');
				//$('#headerWrap').css('height','300');
			}
			,function()
			{
				$(this).find('ul').slideUp(0);
				//$('#headerWrap').css('height','auto');
			});
		}
		,
		//-----------------------------------------------------------------
		menuRollover: function()
		{
			var c = $.extend(
			{
				selector:'#cNav img'
			});
			$(c.selector).each(function()
			{
				if($(this).parent().attr('class') == 'current')
				{
					$(this).fadeTo(0, 0);
				}
				else
				{
					$(this).hover(function()
					{
						$(this).not(':animated').fadeTo('fast', 0);
					}
					,function()
					{
						$(this).fadeTo('fast', 1);
					});
				};
			});
		}
		,
		//-----------------------------------------------------------------
		btnRollover: function()
		{
			var c = $.extend(
			{
				selector:'#menu a img,#primary a img,#secondary a img,#footer a img,div.submitbtn input'
			});

			$(c.selector).each(function()
			{
				if($(this).parent().attr('class') == 'current')
				{
					$(this).fadeTo(0, 0.5);
				}
				else
				{
					$(c.selector).hover(function()
					{
						$(this).stop().fadeTo('fast', 0.5);
					}
					,function()
					{
						$(this).stop().fadeTo('fast', 1);
					});
				};
			});
		}
		,
		//-----------------------------------------------------------------
		selfScroll: function()
		{
			var c = $.extend(
			{
				selector:'#pagetop'
			});
			$('#sNav a[href*="#"]').each(function()
			{
				if(this.href.split('#')[0] == $.ASconf.theUrl)
				{//ページ内リンクだったら
					$(this).click(function()
					{
						var hash= this.hash;
						var target = $(hash).offset().top;
						$.scrollTo( target, { duration:300 });				
						return false;
					});
				}
			});
		}
		,
		//-----------------------------------------------------------------
		menuScroll: function()
		{
			$('#side').each(function()
			{
				var target = $(this);
				if($(target).css("left") != "0px")
				{//* htmlでIE6のみ違う値を設定し除外する
					
					
					var offsetTop = target.offset().top;
					//var offsetTop2 = $('#mainWrap').css('padding-top').split('px')[0] - 13;
					var targetHeight = target.attr('offsetHeight');
					var footerOffset = 2000;
					var maxScroll = footerOffset - (targetHeight + offsetTop - 50);
					
					function winScroll(e)
					{
						var scrollTop = $(document).scrollTop();
						if(scrollTop < maxScroll)
						{
							if(offsetTop -102 < scrollTop)
							{
								var offset = (scrollTop);
	
								$(target).stop().animate({top:offset+'px'},{ duration:350, queue: false });
							}
							else
							{
								$(target).stop().animate({top:50},{ duration:350, queue: false });//////default:{top:0}_____100121_yanagisawa(^^)
							}						
						}
						else
						{
							$(target).stop().animate({top:maxScroll},{ duration:350, queue: false });
						}
					}
					winScroll();//Fire Fox で Google Analyticsを埋め込んだページでは、ページ読み込み時のscrollイベントが発生しない？？ので、その対策
					$(window).bind('scroll', winScroll);
					$(window).bind('resize', winScroll);
				}
			});
		}
		,
		//-----------------------------------------------------------------
		ec: function()
		{
				$('div.productImg a[href$=jpg],div.productImg a[href$=jpeg],#subImgList a,.phototd a').each(function(){
						$(this).lightBox({
						overlayBgColor: '#EEEEEE',
						overlayOpacity: 0.6,
						imageLoading: '/shr/img/lightbox/lightbox-ico-loading.gif',
						imageBtnClose: '/shr/img/lightbox/lightbox-btn-close.gif',
						imageBtnPrev: '/shr/img/lightbox/lightbox-btn-prev.gif',
						imageBtnNext: '/shr/img/lightbox/lightbox-btn-next.gif',
						containerResizeSpeed: 350,
						fixedNavigation:false
						});
				});
				
				$(window).bind('load', function() {
					var pr = $('#primaryInside');
					var cnt = $('#content');
					var prh = pr.height();
					var cnth= cnt.height();
					pr.height((prh < cnth)?cnth + 6:prh);
					cnt.height((prh > cnth)?prh - 6:cnth);
				});
				
		}
	//-----------------------------------------------------------------
	};
//---------------------------------------------------------------------
})(jQuery);
