/* ================================================================================
* Title: Jquery Function
*
* Copyright (c) 2009 Astra The Studio Inc.
* http://www.studio.co.jp/
* Date: Feb.16, 2009
* @author: Chihiro Mori
* @version: 1.0.2
*
* jQuery 1.3.1
* jQuery.ScrollTo 1.4
*
* 確認済ブラウザ: [Mac] FireFox3.0, Safari3.1.2 [Win] IE6.0, 7.0
* Macで作業するときの注意：バックスラッシュ\を入力するときはoptionを押しながらエンマーク
================================================================================ */
/* 目次
selfLink()  :自ページリンクにクラス付与
menuRollover()  :透明効果を使ったナビゲーションのマウスオーバー
topTeaser() :トップページ用マウスオーバー BACKGROUND-POSITION ANIMATIONS を使用
*/

var isIFrameAnimating=0;
var isLoaded=0;

(function($)
{
//---------------------------------------------------------------------
	$(function()
	{
jQuery.fx.off  = 1;
		$.ASconf.menuRollover();
		$.ASconf.mobileText();
		$.ASconf.selectMenu();
		$.ASconf.zebraTable();
		$.ASconf.menuInit();
		$.ASconf.swapImageSetting();
		isLoaded=1;
	});
//---------------------------------------------------------------------
	$.ASconf =
	{
	//---------------------------------------------------------------------
		//-----------------------------------------------------------------
		menuRollover: function()
		{
			var c = $.extend(
			{
				selector:'#cNav ul li'
			});
			
			$(c.selector).hover(function()
			{
				if (!$(this).hasClass('current')) $(this).find('img').stop().fadeOut();
			}
			,function()
			{
				if (!$(this).hasClass('current')) $(this).find('img').stop().fadeTo(0,1).fadeIn();
			});
		}
		,
		//-----------------------------------------------------------------
		mobileText: function()
		{
			
				$("#gNav li:has(a:contains('ケータイ'))").remove();
		}
		,
		//-----------------------------------------------------------------
		selectMenu: function()
		{
			$(document).ready(function()
									   {
				$("div#cNav ul li").hover(
					 function ()
					 {
						 $(this).find('iframe').show("fast",function(){window.parent.iFrameAutoHeight();});
					 },
					
					 function ()
					 {
						 $(this).find('iframe').hide("fast");
					 });
				});
		}
		,
		//-------------------------------------------------------------------
		zebraTable: function()
		{
			$(document).ready(function(){
				$("table.zebraEven").each(function(){
						jQuery(this).find("tr:even").addClass("two");	
				});
				$("table.zebraOdd").each(function(){
						jQuery(this).find("tr:odd").addClass("two");	
				});
			});
		},
		//-------------------------------------------------------------------
		menuInit: function()
		{
			$('iframe.autoHeight').each(function()
			{
				$(this).attr('scrolling','no');
			});
			var parentLocation = parent;
			if (parentLocation && parentLocation.location.href!=location.href) {
				parentLocation = parentLocation.location.href;
				parentLocation = parentLocation.replace(/\?.*$/,'');
				$('a').each(function () {
					if (this.href == parentLocation) {
						$(this).addClass('current');
					} else if (folderException(parentLocation,this.href)) {
						$(this).addClass('current');
					} else {
						$(this).addClass('nocurrent');
					}
				});
				$('ul li:has(ul)').each(function () {
					$(this).removeClass('open');
					$(this).addClass('close');
					$(this).find('>ul').hide();
				});
				$('ul li:has(a[class=current])').each(function () {
					$(this).find('>a').addClass('current');
				});
				$('ul li:has(a[class=current]+ul)').each(function () {
					$(this).removeClass('close');
					$(this).addClass('open');
				});
				$('ul li:has(ul a[class=current])').each(function () {
					$(this).removeClass('close');
					$(this).addClass('open');
					$(this).find('ul:has(a[class=current])').show('slow',function(){window.parent.iFrameAutoHeight();});
				});
				$('ul:has(a[class=current])').each(function () {
					$(this).show('slow');
				});
				$('ul li a[class=current]').each(function () {
					$(this).find('+ul').show('fast',function(){window.parent.iFrameAutoHeight();});
				});
				$('a[href="#"]').each(function () {
					this.href='#open';
					if ($(this.parentNode).find('a[class=current]').length != 0) return;
					$(this).click(function()
					{
						if ($(this.parentNode).hasClass('open')) {
							$(this.parentNode).removeClass('open');
							$(this.parentNode).addClass('close');
							$(this).find('+ul').hide('fast',function(){window.parent.isIFrameAnimating=0;window.parent.iFrameAutoHeight();});
							window.parent.iFrameAnimateHeight();
						} else {
							$('a[href="#open"]+ul').each(function () {
								if ($(this).find('a[class=current]').length != 0) return;
								$(this.parentNode).removeClass('open');
								$(this.parentNode).addClass('close');
								$(this).hide('fast',function(){window.parent.iFrameAutoHeight();});
							});
							$(this.parentNode).removeClass('close');
							$(this.parentNode).addClass('open');
							$(this).find('+ul').show('fast',function(){window.parent.isIFrameAnimating=0;window.parent.iFrameAutoHeight();});
							window.parent.iFrameAnimateHeight();
						}
						window.parent.iFrameAutoHeight();
						return false;
					});
				});
				window.parent.iFrameAutoHeight();
			}
		},
		//-------------------------------------------------------------------
		swapImageSetting: function()
		{
			var z=0;
			$('#ad p').each(function () {
				$(this).hide();
				z++;
				$(this).css('z-index',z);
			});
			(function() {
				$('#ad p.currentview').each(function() {
					$(this).next().addClass('currentview').show();
					$(this).removeClass('currentview').hide();
				});
				if ($('#ad p.currentview').length==0) {
					$('#ad p:first').addClass('currentview').show();
				}
				// ↓の行の数字が画像切り替えのミリ秒数です
				setTimeout(arguments.callee,5000);
			})();
		}
	//-----------------------------------------------------------------
	};
//---------------------------------------------------------------------
})(jQuery);
function folderException (parent,target) {
	var folders = new Array(
		new Array('jp/news/2002/','jp/news/2002-2004.html'),
		new Array('jp/news/2003/','jp/news/2002-2004.html'),
		new Array('jp/news/2004/','jp/news/2002-2004.html'),
		new Array('jp/news/2005/','jp/news/2005.html'),
		new Array('jp/news/2006/','jp/news/2006.html'),
		new Array('jp/news/2007/','jp/news/2007.html'),
		new Array('jp/news/2008/','jp/news/2008.html'),
		new Array('jp/news/2009/','jp/news/index.html'),
		new Array('jp/news/2010/','jp/news/index.html'),
		new Array('guide/youkou/aluminum/','guide/youkou/aluminum/index.html'),
		new Array('historical/geppo/','historical/geppo/index.html'),
		new Array('profile/gaiyou/access/','profile/gaiyou/access.html'),
		new Array('jp/profile/service/','jp/profile/service.html'),
		new Array('jp/profile/subscription/member/','jp/profile/subscription/member/login.html'),
		new Array('jp/souba/all/index_','jp/souba/all/index.html'),
		new Array('jp/souba/all/option_','jp/souba/all/option.html'),
		new Array('souba/all/index_','souba/all/index.html'),
		new Array('souba/all/option_','souba/all/option.html'),
		new Array('jp/souba/souba_sx/index_','jp/souba/souba_sx/index.html'),
		new Array('jp/souba/souba_sx/option_','jp/souba/souba_sx/option.html'),
		new Array('souba/souba_sx/index_','souba/souba_sx/index.html'),
		new Array('souba/souba_sx/option_','souba/souba_sx/option.html'),
		new Array('jp/souba/torihiki/index_','jp/souba/torihiki/index.html'),
		new Array('jp/souba/torihiki/option_','jp/souba/torihiki/option.html'),
		new Array('souba/torihiki/index_','souba/torihiki/index.html'),
		new Array('souba/torihiki/option_','souba/torihiki/option.html')
	);
	for (var i=0;i<folders.length;i++) {
		if (parent.match(folders[i][0]) && target.match(folders[i][1])) {return true;}
	}
	return false;
}
function iFrameAutoHeight() {
	if (!isLoaded) {
		setTimeout(iFrameAutoHeight,50);
		return;
	}
	$('iframe.autoHeight').each(function()
	{
		try {
			$(this).height($(this.contentWindow.document).find('body').outerHeight());
		} catch (e) {
		}
	});
}
function iFrameAnimateHeight() {
	isIFrameAnimating = 1;
	setTimeout(function() {
		iFrameAutoHeight();
		if (isIFrameAnimating) {
			iFrameAnimateHeight();
		}
	},50);
}
