/*
 * jcommon.js 1.0
 * Copyright (c) 2007 C.M.A. Co.,Ltd.
 *
 * Last Added: 2008-02-25
 *
 */



var ary = location.pathname.split('/');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('/');isLinkAry[i]=isLinkAry[i].replace(/index.*$/,"")}for(k=i+1;k<=i+ary.length;k++){isLinkAry[k]=ary.slice(0,ary.length-l);isLinkAry[k]=isLinkAry[k].join('/');isLinkAry[k]=isLinkAry[k].replace(/^\//,"");isLinkAry[k]=isLinkAry[k].replace(/index.*$/,"");l++}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(/^http[^a-z]*/,"");path=path.replace(document.domain,"");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(){



	//リンク画像はロールオーバーを設定
	$('a img.btn').add('#globalNav li 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 li a').add('div.localNavi ul li a').each(function(){
		var href = new jcommon.URI($(this).attr('href'));
		if (href.isSelfLink) {
			$(this).addClass('current');
			$(this).find('img').each(function(){
				$(this).unbind('mouseenter');
				$(this).unbind('mouseleave');
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_cr$1");
				$(this).attr('src',this.currentSrc);
			});
		}
	});

	//外部リンクは別ウインドウを設定
	//除外が必要ない場合は:notから"])まで削除
	//追加はカンマで続ける ex. :not([href^="除外したいURL"],[href^="除外したいURL2"])
	$('a[href^="http://"]:not([href^="http://www.dg-human.jp/"],[https://dghum587.securesites.com/])').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');

	//別ウィンドウを設定
	//追加はカンマで続ける ex. $('a[href$=".pdf"],a[href$=".asx"]')
	$('a[href$=".pdf"],a[href$=".asx"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	})



	//以下適宜コメントアウトはずして使用すること

/*
	//ポップアップ ※href="[表示するURL]?width=000&amp;height=000"
	$('a.popup').each(function(){
		this.param = $(this).attr("href");
		this.param = this.param.split('?');
		this.param[1] = this.param[1].split('&');
		this.param[1] = this.param[1].join(',')
		$(this).attr("href","");
	}).click(function(){
		this.pu = window.open(this.param[0], 'popup', "menubar=1,location=1,resizable=1,status=1,"+this.param[1]);
		return false;
	});
*/


	//するするアニメーション ※要scrollTo.js
	$('a[href^="#"]').each(function(){
		this.target = $(this).attr('href');
	}).click(function(){
		$.scrollTo( this.target, {speed:800} );
		return false;
	});


/*
	//tableのtrにoddとevenを追加
	$('table').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});
*/

/*
	//dlのdt,ddにoddとevenを追加
	$('dl').each(function(){
		$(this).find('dt:odd').addClass('even');
		$(this).find('dt:even').addClass('odd');
		$(this).find('dd:odd').addClass('even');
		$(this).find('dd:even').addClass('odd');
	});
*/


	//ulのliにoddとevenを追加
	$('ul').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	

/*
	//:first-child(x) :連番nxxxをクラスとして追加
	$('#mainContent li:nth-child(1),#mainContent dt:nth-child(1)').addClass('n001');
	$('#mainContent li:nth-child(2),#mainContent dt:nth-child(2)').addClass('n002');
	$('#mainContent li:nth-child(3),#mainContent dt:nth-child(3)').addClass('n003');
	$('#mainContent li:nth-child(4),#mainContent dt:nth-child(4)').addClass('n004');
	$('#mainContent li:nth-child(5),#mainContent dt:nth-child(5)').addClass('n005');
*/


	//:first-child, :last-childをクラスとして追加
	$(':first-child').addClass('firstChild');
	$(':last-child').addClass('lastChild');

	//角丸処理
	$('.boxInW,.boxInY,.boxInP').append('<div class="boxFoot"></div>').children(':first-child').addClass('boxHead');
	
/*
	//マウスーバー時、画像を半透明にする
	$('a img.alpha').hover(function(){
		$(this).fadeTo(100,0.7);
	},function(){
		$(this).fadeTo(100,1.0);
	});
*/

/*
	//タブ
	$('#tabs').each(function(){
		var tabWrapper = $(this);
		var targetTab = location.hash;
		$(this).find('.tabPage').hide();
		if(targetTab == ''||targetTab == '#top'||targetTab == '#content')targetTab = $(this).find('.selected a').attr('href');
		else window.scrollTo(0,0); $(this).find('.tabControl li').removeClass('selected').find('a[href="'+targetTab+'"]').parent().addClass('selected');
		$(targetTab).show();
		$(this).find('.tabControl a').click(function() {
			targetTab = $(this).attr('href');
			tabWrapper.find('.tabPage').hide();
			tabWrapper.find('.tabControl li').removeClass('selected');
			$(this).parent().addClass('selected');
			$(targetTab).show();
			if(location.hash != targetTab)location.hash = targetTab;
			window.scrollTo(0,0);
			return false;
		});
	});
*/


	//dd要素の非表示 ver1.0
	$('dl.faqList').each(function(){
		$(this).children('dd').hide();
		$(this).before('<p class="faqall alignR"><a href="#faq001">回答をすべて表示</a></p>');
	});
	$('p.faqall a').click(function(){
		$(this).removeAttr("href");
		if($(this).html() == '回答をすべて非表示'){
			$(this).parent().next().children('dd').hide();
			$(this).text('回答をすべて表示');
		}else{
			$(this).parent().next().children('dd').show();
			$(this).text('回答をすべて非表示');
		}
		return false;
	});
	$('dl.faqList dt a').click(function(){
		if($(this).parent().next().is(':visible')){
			$(this).parent().next().hide();
			if(!$(this).parent().nextAll('dd').is(':visible')&&!$(this).prevAll('dd').is(':visible'))$(this).parent().prev().children().text('回答をすべて表示');
		}else{
			$(this).parent().next().show();
			$(this).parents('dl').prev().children().text('回答をすべて非表示');
		}
		return false;
	});


/*
	//googlemapをiframeで表示 ver1.0
	$('a.map').each(function(){
		this.gmapURI = $(this).attr('href');
		$(this).ayyr('href','');
	}).click(function(){
		$(this).removeAttr('href');
		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')
		}
	});
*/

	//#repIndex 詳細のオープン
	$('#repIndex').each(function(){
 		$(this).find('h2 a').toggle(function(){
			$(this).parent('h2').next('.repList').show(500,function(){
				$.scrollTo( $(this), {speed:500} );
				$(this).prev('h2').find('.more').attr('src','../shared/img/btn_close.gif');
			});
			return false;
		},function(){
			$(this).parent('h2').next('.repList').hide(500,function(){
				$.scrollTo( $(this).prev('h2'), {speed:500} );
				$(this).prev('h2').find('.more').attr('src','../shared/img/btn_open.gif');
			});
			return false;
		}).hover(function(){
			var onSrc = $(this).find('.more').attr('src');
			onSrc = onSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
			$(this).find('.more').attr('src',onSrc);
		},function(){
			var onSrc = $(this).find('.more').attr('src');
			onSrc = onSrc.replace(/_on/, "");
			$(this).find('.more').attr('src',onSrc);
		});
		$(this).find('.repList').css({cursor:'pointer'}).each(function(){
			$(this).hide(500);
		}).click(function(){
			location.href = $(this).find('a').attr('href');
		});
	});
});