/*
 * jcommon.js 1.0RC
 * Copyright (c) 2007 C.M.A. Co.,Ltd.
 *
 * Last Added: 2007-12-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('/')}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(){



	//リンク画像はロールオーバーを設定
	$('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('#localNav 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('mouseover');
				$(this).unbind('mouseout');
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_on$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} );
	});



	//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, :last-childをクラスとして追加
	$(':first-child').addClass('firstChild');
	$(':last-child').addClass('lastChild');
});
