/* ================================================================================

* 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.selfLinkAndSmoothScroll();

		$.ASconf.menuRollover();

		$.ASconf.pulldown();

		$.ASconf.btnRollover();

		$.ASconf.headerScroll();

		$.ASconf.searchMenu();

		*/

		$.ASconf.accordion();

		$.ASconf.swapImages();
		
		$.ASconf.miniFix();

		//$.ASconf.searchPopUp();
		
	

	});

//---------------------------------------------------------------------

	$.ASconf =

	{



	//---------------------------------------------------------------------

		selfLinkAndSmoothScroll: function ()

		{

			if($.browser.msie && $.browser.version == 7){

			  setInterval(function(){

			var w = $('html').width();

			var lm = (w - $('#contents').width()) / 2;

			$('#contents').css('margin-left',lm);

			$('#headerWrap,#footerWrap').css('padding-left',lm).css('padding-right',lm);

			  $('#body').css('width',w);

			  

			     }, 500);  

			

			}



			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');

				else if($(this).attr('href').substr(0,1) == '#')

					$(this).click(function()

					{//-118px は各施設一覧ヘッダーの高さ分決め打ち

						var hash = this.hash;

						if(!hash || hash == "#")

							return false;

						$($.browser.safari ? 'body' : 'html')

						.animate({scrollTop: $(hash).offset().top - 118}, 500);

						return false;

					});

			});

		}

		,

		//-----------------------------------------------------------------

		menuRollover: function()

		{

			var parentClass = 'current';

			

			$('ul#cNav img, div#detailMenuList img').each(function()

			{

				if($(this).parent().attr('class') == parentClass)

					$(this).fadeTo(0, 0);

				else if($(this).attr('class') != 'no_f')////add by yanagisawa____100505

				{

					$(this).hover(function(){

						$(this).not(':animated').fadeTo('fast', 0);}

					,function(){

						$(this).fadeTo('fast', 1);});

				}

			});

		}

		,

		//-----------------------------------------------------------------

		pulldown: function()

		{

			$('ul#cNav li.pulldown, li#detailMenuListSub').each(function()

			{

				//一旦非表示にする

				$(this).find('div').hide().end().hover(function(){

					$(this).find('div:not(:animated)').slideDown('fast');}

				,function() {

					$(this).find('div').slideUp('fast');});

				

				//各施設一覧ヘッダーのリンクをクリックしたら隠す

				var target = $(this).find('div');

				$(this).find('td a').click(function(){

					$(target).not(':animated').slideUp('fast');});

			});

		}

		,

		//-----------------------------------------------------------------

		btnRollover: function()

		{

			$('div#main img.btn, div#main table.btns img, div#main div.imgsWrap p.layout, div#index table dt img, #result th.photo img').hover(function(){

				$(this).stop().fadeTo('fast', 0.5);}

			,function(){

				$(this).stop().fadeTo('fast', 1);});

		}

		,

		//-----------------------------------------------------------------

		headerScroll: function()

		{

			var target = $('div#headerWrap');

			

			function winScroll(e)

			{

				var scrollLeft = $(document).scrollLeft();

				target.stop().css('left', -scrollLeft);

			}

			winScroll();

			$(window).bind('scroll', winScroll);

			$(window).bind('resize', winScroll);

		}

		,

		//-----------------------------------------------------------------

		accordion: function()

		{

			$('div#detail div.option h3').each(function()

			{

				var textNode = $(this).next('div').hide();

				$(this).click(function (){

					if ($(textNode).is(':hidden'))

						$(textNode).slideDown();

					else

						$(textNode).slideUp('fast');

				});

			}).hover(function(){$(this).stop().fadeTo('fast', 0.7);},

			function(){$(this).stop().fadeTo('fast', 1);});

		}

		,

		//-----------------------------------------------------------------

		searchPopUp: function()

		{

			$('#searchMenu li.col3').hover(

				function(){

					$(this).find("div.popUp").show()

					.end().css("cursor","pointer");

				},

				function(){

					$(this).find("div.popUp").hide()

					.end().css("cursor","auto");

				}

			);

		}

		,

		//-------------------------------------------------------------------

		swapImages: function()

		{

			$('div#detail div.photos').each(function()

			{

				var target = $(this).find('p.big img');

				var originalSrc = target.attr('src');

				

//				$(this).mouseout(function(event)

//				{

//					//$(target).stop().fadeTo(0, 0.5, function(){$(target).fadeTo('fast', 1);}).attr('src', originalSrc);

//					$(target).attr('src', originalSrc);

//				});



				$(this).find('p.small img').hover(function()

				{

					var rolloverSrc = $(this).attr('src').replace('_s.jpg', '.jpg');

					$(this).stop().css('cursor','pointer').fadeTo('fast', 0.5);

					$(target).attr('src', rolloverSrc);

				}

				,function(){

					$(this).stop().fadeTo('fast', 1);})

				.each(function(){//プリロード

        	$("<img>").attr('src', $(this).attr('src').replace('_s.jpg', '.jpg'))});

			});

		},





		searchMenu: function()

		{

			$('div#searchMenu').each(function()

			{

/*				var target = $(this);

				var offsetTop = target.offset().top;

				offsetTop = 185;

				var defaultOffset = offsetTop;

				var targetHeight = target.attr('offsetHeight');

				var footerOffset = $('div#footerWrap').offset().top;

				var maxScroll = footerOffset - (targetHeight + defaultOffset);



				function menuScroll(e)

				{

					var scrollTop = $(document).scrollTop();

					if(scrollTop - defaultOffset < maxScroll)

					{

						if(offsetTop < scrollTop)

						{

							var offset = (scrollTop - defaultOffset);

							$(target).stop().animate({top:offset+'px'},{ duration:350, queue: false });

						}

						else

							$(target).stop().animate({top:0},{ duration:350, queue: false });

					}

					else

						$(target).stop().animate({top:maxScroll},{ duration:350, queue: false });

				}

				$(window).bind('scroll', menuScroll);

				$(window).bind('resize', menuScroll);

				menuScroll();*/

				



				//個別ページのプルダウン

				//pulldown() へ移動↑

				

				//100519追加

				//オプション検索の開閉

				var optionMenu = $(this).find('div#optionMenu');

				var optionTitle = $(this).find('p#optionMenuTitle');

				var optionTitleText = 'オプション検索を';

				

				$(optionTitle).unbind('click');

				$(optionTitle).click(function(){

					if ($(optionMenu).is(':hidden')){

						$(optionMenu).slideDown();

						$(this).removeAttr('class');//.text(optionTitleText+'閉じる');

					}

					else{

						$(optionMenu).slideUp('fast');

						$(this).addClass('change');//.text(optionTitleText+'開く');

					}

				});

				

			});



		},

		//-----------------------------------------------------------------

		miniFix: function()

		{
			var now = new Date();
			var tgt = new Date(2011,0,5,9);
			if(now <= tgt){
			$('#header').append('<div style="position:absolute;width:147px;height:49px;top:42px;left:490px"><a href="http://www.bellesalle.co.jp/backnumber/top/2010/12_883.html"><img src="http://www.bellesalle.co.jp/shr/img/header_banner.gif" alt="年末年始の営業時間のご案内" width="147" height="49" class="bnr" /></a></div>').find('img.bnr').hover(function(){$(this).stop().fadeTo('fast', 0.7);},function(){$(this).stop().fadeTo('fast', 1);});
			}

		}







	//-----------------------------------------------------------------

	};

//---------------------------------------------------------------------

})(jQuery);




