/*
 * jcommon.js 1.0RC
 * Copyright (c) 2007 C.M.A. Co.,Ltd.
 *
 * Last Added: 2007-12-25
 *
 */



var ary = location.pathname.split('/');



	//テストサイト用 //本アップ時に削除すること
	// -------------------------------------------------------------------------------
	if(document.domain == "test.akindo2000.net")ary = ary.slice(2,ary.length);
	// -------------------------------------------------------------------------------



var l=0;var isLinkAry=new Array;for(i=0;i<=ary.length-1;i++){isLinkAry[i]=ary.slice(i,i+1);isLinkAry[i]=isLinkAry[i].join('/')}for(k=i+1;k<=i+ary.length;k++){l++;isLinkAry[k]=ary.slice(0,ary.length-l);isLinkAry[k]=isLinkAry[k].join('/')}isLinkAry[0]=isLinkAry[0].replace(/\#.*$/,"");var jcommon={preloader:{loadedImages:[],load:function(url){var img=this.loadedImages;var l=img.length;img[l]=new Image();img[l].src=url}},URI:function(path){path=path.replace(/^https[^a-z]*[^\/]*/,"");path=path.replace(/^[^a-z]*/,"");path=path.replace(/index.*$/,"");path=path.replace(/\/$/,"");this.absolutePath=path;this.len=isLinkAry.length;this.isSelfLink=false;while(this.len--){this.isSelfLink=this.isSelfLink||(this.absolutePath==isLinkAry[this.len])}}};


$(function(){

	//テストサイト＆ローカル用 //本アップ時に削除すること
	// -------------------------------------------------------------------------------
	if(document.domain == "test.akindo2000.net"){
		var testName = isLinkAry[3];
		$('a[href^="/"],link[href^="/"]').each(function(){
			var dirname = $(this).attr('href');
			$(this).attr({ href: '/'+testName+dirname });
		});					 
		$('img[@src^="/"]').each(function(){
			var dirname = $(this).attr('src');
			$(this).attr({ src: '/'+testName+dirname });
		});
	}else if(!isLinkAry[0]){
		var testName = isLinkAry[3];
		$('a[href^="/"],link[href^="/"]').each(function(){
			var dirname = $(this).attr('href');
			$(this).attr({ href: 'file:///Y|/Htdocs/'+testName+'/www/%E4%BD%9C%E6%A5%AD%E7%94%A8'+dirname });
		});					 
		$('img[@src^="/"]').each(function(){
			var dirname = $(this).attr('src');
			$(this).attr({ src: 'file:///Y|/Htdocs/'+testName+'/www/%E4%BD%9C%E6%A5%AD%E7%94%A8'+dirname });
		});
		$('a[href$="/"]').each(function(){
			var dirname = $(this).attr('href');
			$(this).attr({ href: dirname+'index.html' });
		});					 
	}
	// -------------------------------------------------------------------------------



	//リンク画像はロールオーバーを設定
	$('a img.btn').add('#globalNav a img').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
		jcommon.preloader.load(this.rolloverSrc);
	}).hover(function(){
		$(this).attr('src',this.rolloverSrc);
	},function(){
		$(this).attr('src',this.originalSrc);
	});

	//現在のページへのリンク
	$('#globalNav a').add('#subNav a').add('.localNav a').each(function(){
		var href = new jcommon.URI($(this).attr('href'));
		if (href.isSelfLink) {
			$(this).addClass('current');
			$(this).find('img').each(function(){
				$(this).unbind('mouseover');
				$(this).unbind('mouseout');
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_cr$1");
				$(this).attr('src',this.currentSrc);
			});
		}
	});

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]').not('a[href^="http://www/"]').not('a[href^="https://www/"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');



	//以下適宜コメントアウトはずして使用すること


	//するするアニメーション ※要scrollTo.js
	$('a[href^="#"]').each(function(){
		this.target = $(this).attr('href');
		$(this).removeAttr('href').css({cursor:"pointer"});
	}).click(function(){
		$.scrollTo( this.target, {speed:800} );
	});


/*
	//PDF・ASXを別ウィンドウ-Added 2007-02-26
	$('a[href$=".pdf"]').add('a[href$=".asx"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	})
*/


	//tableのtrにoddとevenを追加
	$('table').each(function(){
		$(this).find('tr:odd').addClass('odd');
		$(this).find('tr:even').addClass('even');
	});


/*
	//dlのdt,ddにoddとevenを追加
	$('dl').each(function(){
		$(this).find('dt:odd').addClass('odd');
		$(this).find('dt:even').addClass('even');
		$(this).find('dd:odd').addClass('odd');
		$(this).find('dd:even').addClass('even');
	});
*/


	//ulのliにoddとevenを追加
	$('ul').each(function(){
		$(this).find('li:odd').addClass('odd');
		$(this).find('li:even').addClass('even');
	});


/*
	//:first-child(x) :連番nxxxをクラスとして追加 ver0.1 *未完成
	$('#mainContent li:nth-child(1)').add('#mainContent dt:nth-child(1)').addClass('n001');
	$('#mainContent li:nth-child(2)').add('#mainContent dt:nth-child(2)').addClass('n002');
	$('#mainContent li:nth-child(3)').add('#mainContent dt:nth-child(3)').addClass('n003');
	$('#mainContent li:nth-child(4)').add('#mainContent dt:nth-child(4)').addClass('n004');
	$('#mainContent li:nth-child(5)').add('#mainContent dt:nth-child(5)').addClass('n005');
*/


	//:first-child, :last-childをクラスとして追加
	$(':first-child').addClass('firstChild');
	$(':last-child').addClass('lastChild');


/*
	//マウスーバー時、画像を半透明にする
	$('a img.alpha').hover(function(){
		$(this).fadeTo(100,0.7);
	},function(){
		$(this).fadeTo(100,1.0);
	});
*/

/*
	//タブ ver1.0.1 *thisを上手に使用し軽量化を図る
	$('.tabs').each(function(){
		var url = document.URL.match(/#/);
		$('.tabs .tabPage').hide();
		if(url == null){
			var tabDefault = $('.tabs .selected a').attr('href').split('#');
			$('.tabs .selected a').parent().addClass('selected');
			$('#'+tabDefault[tabDefault.length-1]).show();
		}else{
			window.scrollTo(0,0);
			$('.tabs .tabList li').removeClass();
			$('.tabs .tabList li a[href^="'+url+'"]').parent().addClass('selected');
			$(''+url).show();
		}
		$('#menu .tabControl li a').add('a[href^="#"]').click(function() {
			splitID = $(this).attr('href').split('#');
			targetID = '#'+splitID[splitID.length-1];
			$('.tabs .tab').hide();
			$('.tabs .tabList li').removeClass();
			$('.tabs .tabList li a[href^="'+targetID+'"]').parent().addClass('selected');
			$(targetID).show();
			return false;
		});
	});
*/


	//dd要素の非表示 ver1.0 *課題 すべて表示の動作修正の必要あり
	$('dl.faq').each(function(){
		$(this).children('dd').hide();
		$(this).before('<p class="faq alignR"><a>回答をすべて表示</a></p>');
	});
	$('p.faq a').click(function(){
		if($(this).parent().next().children('dd').is(':visible')){
			$(this).parent().next().children('dd').hide();
			$(this).text('回答をすべて表示');
		}else{
			$(this).parent().next().children('dd').show();
			$(this).text('回答をすべて非表示');
		}
	});
	$('dl.faq dt').click(function(){
		if($(this).next().is(':visible')){
			$(this).next().hide();
			if(!$(this).nextAll('dd').is(':visible')){
				$(this).parent().prev().children().text('回答をすべて表示');
			}
		}else{
			$(this).next().show();
			$(this).parent().prev().children().text('回答をすべて非表示');
		}
	}).hover(function(){
		$(this).css({textDecoration:"underline"});
	},function(){
		$(this).css({textDecoration:"none"});
	});



	//googlemapをiframeで表示 ver1.0
	$('a.map').each(function(){
		this.gmapURI = $(this).attr('href');
		$(this).removeAttr('href');
	}).click(function(){
		if($(this).hasClass('show')){
			$(this).next().remove();
			$(this).text('地図を表示');
			$(this).removeClass('show')
		}else{
			$(this).after('<iframe frameborder="0" src="'+this.gmapURI+'"></iframe>');
			$(this).text('地図を非表示');
			$(this).addClass('show')
		}
	});

/*フォントサイズ変更
Written by http://blog.4galaxy.net/
*/
/*	$("#mainContent").add('#subContent').add('#textNav').css("font-size",$.cookie('fsize'));
	
	if($.cookie('fclass') == null){
		$("#fontSize a.fSmall").find('img').each(function(){
			this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_cr$1");
			$(this).src(this.currentSrc);
		});
	}
	$("#fontSize a").each(function(){
		if($(this).attr('class') == $.cookie('fclass')){
			$(this).find('img').each(function(){
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_cr$1");
				$(this).src(this.currentSrc);
			});
		}
	});


});

/*フォントサイズ*/

/*function font(size,c){
	if(c != $.cookie('fclass')){
		$("#mainContent").add('#subContent').add('#textNav').css("font-size",size);
		$.cookie("fsize",size,{expires:30,path:'/'});//※1
		$.cookie("fclass",c,{expires:30,path:'/'});//※1
	
		$("#fontSize a").each(function(){
			if($(this).attr('class') == $.cookie('fclass')){
				//alert($(this)+" to "+$.cookie('fclass'));
				$(this).find('img').each(function(){
					this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_cr$1");
					$(this).src(this.currentSrc);
				});
			}else if($(this).attr('class') != $.cookie('fclass')){
				$(this).find('img').each(function(){
					this.currentSrc = this.getAttribute('src').replace(/_cr(\.gif|\.jpg|\.png)/, "$1");
					$(this).src(this.currentSrc);
				});
			}
		});
	}
}
*/
});