/* ================================================================================
* 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();
		$.ASconf.rollover();
		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 () {
					var customHref = this.href.replace(/\?.*$/,'');
					if (customHref == parentLocation) {
						$(this).addClass('current');
					} else if (folderException(parentLocation,this.href)) {
						$(this).addClass('current');
					} else {
						$(this).addClass('nocurrent');
					}
				});
				$('li.soubabanner').each(function () {
					if (parentLocation.search(/\/jp\/souba\/all\/index_?.*\.html$/) != -1) {
						$(this).show('fast',function(){window.parent.iFrameAutoHeight();}).addClass('success');
					} else {
						$(this).hide().addClass('success');
					}
				});
				$('li.noTop').each(function () {
					if (parentLocation.search(/\/jp\/index.html$/) != -1) {
						$(this).hide('fast',function(){window.parent.iFrameAutoHeight();}).addClass('success');
					}
					else if (parentLocation.search(/\/jp\/$/) != -1) {
						$(this).hide('fast',function(){window.parent.iFrameAutoHeight();}).addClass('success');
					} else {
						$(this).show().addClass('success');
					}
				});
				$('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,10000);
			})();
		},
		//-------------------------------------------------------------------
		//ロールオーバー
		rollover: function(options) {
			var c = $.extend({
				hoverSelector: '.btn, .allbtn a img',
				groupSelector: '.btngroup',
				postfix: '_o'
			}, options);
			//ロールオーバーするノードの初期化
			var rolloverImgs = $(c.hoverSelector).filter(isNotCurrent);
			rolloverImgs.each(function(){
				this.originalSrc = $(this).attr('src');
				this.rolloverSrc = this.originalSrc.replace(new RegExp('('+c.postfix+')?(\.gif|\.jpg|\.png)$'), c.postfix+"$2");
				this.rolloverImg = new Image;
				this.rolloverImg.src = this.rolloverSrc;
			});
			//グループ内のimg要素を指定するセレクタ生成
			var groupingImgs = $(c.groupSelector).find('img').filter(isRolloverImg);

			//通常ロールオーバー
			rolloverImgs.not(groupingImgs).hover(function(){
				$(this).attr('src',this.rolloverSrc);
			},function(){
				$(this).attr('src',this.originalSrc);
			});
			//グループ化されたロールオーバー
			$(c.groupSelector).hover(function(){
				$(this).find('img').filter(isRolloverImg).each(function(){
					$(this).attr('src',this.rolloverSrc);
				});
			},function(){
				$(this).find('img').filter(isRolloverImg).each(function(){
					$(this).attr('src',this.originalSrc);
				});
			});
			//フィルタ用function
			function isNotCurrent(i){
				return Boolean(!this.currentSrc);
			}
			function isRolloverImg(i){
				return Boolean(this.rolloverSrc);
			}

		}
	//-----------------------------------------------------------------
	};
//---------------------------------------------------------------------
})(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'),
		new Array('jp/souba/sco/index_','jp/souba/sco/index.html'),
		new Array('jp/souba/sco/option_','jp/souba/sco/option.html'),
		new Array('souba/sco/index_','souba/sco/index.html'),
		new Array('souba/sco/option_','souba/sco/option.html'),
		new Array('jp/souba/weekly/index_','jp/souba/weekly/index.html'),
		new Array('souba/weekly/index_','souba/weekly/index.html'),
		new Array('jp/souba/monthly/index_','jp/souba/monthly/index.html'),
		new Array('souba/monthly/index_','souba/monthly/index.html'),
		new Array('jp/souba/yearly/index_','jp/souba/yearly/index.html'),
		new Array('souba/yearly/index_','souba/weekly/yearly.html'),
		new Array('jp/souba/limitmonth/index_','jp/souba/limitmonth/index.html'),
		new Array('souba/limitmonth/index_','souba/limitmonth/index.html'),
		new Array('jp/souba/tocom_index/index_contract/','jp/souba/tocom_index/index_contract/index.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);
}

/*if ((navigator.userAgent.indexOf('iPhone') > 0 && navigator.userAgent.indexOf('iPad') == -1) || navigator.userAgent.indexOf('iPod') > 0 || navigator.userAgent.indexOf('Android') > 0) {
    $(document).ready(function(){
		$('body').append('<div class="iphone vertical"><div class="phone"><div class="display"><div class="screen"><div class="titlebar"></div><div class="scroll iscroll"></div></div></div></div></div>');
		$('#header-wrap, #content, #footerWrap').appendTo(".scroll");
		$('#content h2').appendTo(".titlebar").each(function(){
			$(this).replaceWith($(this).html());
		});;
		$('#header-wrap, iframe, #wrap, link, #searchbox, #visual ,#BreadCrumb, #fNav').remove();
		$('head').append('<link rel="stylesheet" href="/common/css/iphone/style.css" type="text/css" media="all" /><link rel="stylesheet" href="/common/css/iphone/iphone.css" type="text/css" media="all" /><script type="text/javascript" src="/common/js/jquery.js"></script><script type="text/javascript" src="/common/js/iphone/jquery-ui.js"></script><script type="text/javascript" src="/common/js/iphone/jquery.iphone.js"></script><script type="text/javascript" src="/common/js/iphone/other/jquery.mousewheel.js"></script><script type="text/javascript" src="/common/js/iphone/other/jquery.disable.text.select.js"></script><script type="text/javascript" src="/common/js/iphone/ui/ui.iMenu.js"></script><script type="text/javascript" src="/common/js/iphone/ui/ui.iTabs.js"></script><script type="text/javascript" src="/common/js/iphone/ui/ui.iScroll.js"></script>');
		$('#content').append('<a class="back" href="#">back</a><a class="home" href="/jp/iphone.html">Home</a>');
	});
}*/



