/* ================================================================================
* 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
* jQuery.ScrollTo 1.4.2
*
* 確認済ブラウザ: [Mac] FireFox3.0, Safari3.1.2 [Win] IE6.0, 7.0
* Macで作業するときの注意：バックスラッシュ\を入力するときはoptionを押しながらエンマーク
================================================================================ */
/* 目次
selfLink()     : 自ページリンクにクラス付与
menuRollover() : 透明効果を使ったナビゲーションのマウスオーバー
btnRollover()  : 透明効果を使ったナビゲーションのマウスオーバー(クラス付与)
selfScroll()   : ページ内スムーススクロール。jQuery.ScrollTo を使用
*/
(function($)
{
//---------------------------------------------------------------------
	$(function()
	{
		$.ASconf.selfLink();
		$.ASconf.selfScroll();
		$.ASconf.menuRollover();
		$.ASconf.menuScroll();
		$.ASconf.morBox();
		$.ASconf.gMaps();
		$.ASconf.loadFlash();
	});
//---------------------------------------------------------------------
	$.ASconf =
	{
	//---------------------------------------------------------------------
		selfLink: function ()
		{
			var selfLinkClass = 'current';
			var theUrl = location.href.replace(location.hash, '').replace(/(\/|\#)$/, '/index.html');
			$.ASconf.theUrl = theUrl;
			
			$('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');
				}
			});
		}
		,
		//-----------------------------------------------------------------
		menuRollover: function()
		{
			//IE6かどうか判定
			var selector = 'a:not(#logo) img';
/*			var noIE6 = ', #submitBtn';
			if (typeof document.documentElement.style.maxHeight != "undefined") {		
				selector += noIE6;
			}*/
			$('a:not(#logo) img').each(function()
			{
				if($(this).parent().attr('class'))
				{
					$(this).fadeTo(0, 0.6);
				}
				else
				{
					$(this).hover(function()
					{
						$(this).not(':animated').fadeTo('fast', 0.6);
					}
					,function()
					{
						$(this).fadeTo('fast', 1);
					});
				};
			});
		}
		,
		//-----------------------------------------------------------------
		menuScroll: function()
		{
			$('div#sideNav').each(function()
			{
				var target = $(this);
				var offsetTop = target.offset().top;
				var defaultOffset = offsetTop;
				var targetHeight = target.attr('offsetHeight');
				var footerOffset = $('div#footer').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 if ( 0 < maxScroll)
					{
						$(target).stop().animate({top:maxScroll},{ duration:350, queue: false });
					}
				}
				$(window).bind('scroll', menuScroll);
				$(window).bind('resize', menuScroll);
				menuScroll();
				
			});
		}
		,
		//-----------------------------------------------------------------
		selfScroll: function()
		{//^は初めの文字が#だった場合。*にするとhoge.html#hogeもマッチだけど、ページ内とページ外の判定無し
			//headerfixはヘッダーが固定の場合のヘッダーの高さ
			
			var headerfix = 0;
			var locationHash = location.hash;
			
			$('a[href*=#]').click(function()
			{
				var hash = this.hash;
				if(!hash || hash == "#")
					return false;
				if(this.href.replace(hash, '') == $.ASconf.theUrl)
				{
					$($.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);
				 }
			}
		}
		,
		//-----------------------------------------------------------------
		morBox: function()
		{
			$('div#cont div.morBox').each(function()
			{
				var url = $(this).find('a').attr('href');
				$(this).css('cursor','pointer')
				.hover(function()
				{
					$(this).not(':animated').fadeTo('fast', 0.6);
				}
				,function()
				{
					$(this).fadeTo('fast', 1);
				})
				.click(function()
				{
					if(url.indexOf('#')!= -1)
					{
						$($.browser.safari ? 'body' : 'html')
						.animate({scrollTop: $(url).offset().top}, 500);
					}
					else
					{
						location.href = url;
					}
				});
			});
		}
		,
		//-----------------------------------------------------------------
		gMaps:function()
		{
			$('table#gMaps').each(function()
			{
				Shadowbox.init();
				var c = $.extend(
				{
					honsya:'35.662986,139.711369',
					aoyama:'35.660539,139.713328',
					yokohama:'35.43931,139.646316'
				});
				
				$(this).find('tr[id]').each(function()
				{
					var point = eval('c.'+$(this).attr('id')).split(',');
					var pointN = point[0];
					var pointE = point[1];
					var title = $(this).find('th').text();
					var text = $(this).find('td').text();
					
					$(this).find('img').click(function()
					{
						Shadowbox.open(
						{
							player: 'html',
							content: '',
							height: 400,
							width: 600,
							options:
							{
								onFinish: function(item)
								{
									var myLatlng = new google.maps.LatLng(pointN, pointE);
									var mapCenter;
									var myOptions = {
									zoom: 16,
									center: myLatlng,
									mapTypeControl: false,
									mapTypeId: google.maps.MapTypeId.ROADMAP,
									scaleControl: true
									};
									var map = new google.maps.Map(document.getElementById("sb-player"), myOptions);
									
									var contentString = '<div id="content">'+
									'<strong>'+title+'</strong><br />'+
									text+
									'</div>';
								
									var infowindow = new google.maps.InfoWindow({
										content: contentString
									});
									
									var marker = new google.maps.Marker({
										position: myLatlng,
										map: map, 
										title: ''
									});

									infowindow.open(map,marker);
									google.maps.event.addListener(marker, 'click', function() {
										infowindow.open(map,marker);
									});
								}
//								,onClose: function(item){}
							}
						});
					});
				});
			});
			
		}
		,
		//-----------------------------------------------------------------
		loadFlash: function()
		{
			$('#FlashRecruitTopMember').each(function()
			{
				$(this).flash(
				{
				swf: 'recruit/member/menu.swf',
				width: 726,
				height: 300,
				wmode: 'transparent',
				hasVersion: 9, // requires Flash 9
				hasVersionFail: function (options) { return false; }
				});
			});
			
			var v = $('#visual')
			var visualW = v.width();

			v.flash({
			swf:'top.swf',
			width:visualW,
			height:304,
			wmode:'opaque',
			hasVersion:9,
			hasVersionFail:function(options){return false;}
			});
			window.onresize = wwc;
			function wwc(){
				visualW = v.width();
				v.find('*').attr('width',visualW);
			}
		}
	//-----------------------------------------------------------------
	};
//---------------------------------------------------------------------
})(jQuery);
