/*
 * jcommon.js 1.01
 * Copyright (c) 2007 C.M.A. Co.,Ltd.
 *
 * Last Added: 2008-05-14
 *
 */



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])}}};

/*ロールオーバー*/			$.fn.addRollOver=function(add){$(this).filter('img').each(function(){$(this).runRollOver(add,$(this));}).end().not('img').each(function(){$(this).runRollOver(add,$(this).find('img'));});};
							$.fn.runRollOver=function(add,target){$(this).each(function(num){this.originalSrc=String(target.attr('src'));this.rolloverSrc=this.originalSrc.replace(/(\.gif|\.jpg|\.png)/,add+"$1");}).hover(function(){target.attr('src',this.rolloverSrc);},function(){target.attr('src',this.originalSrc);});};
/*現在のページへのリンク*/	$.fn.addCurrentImages=function(add){$(this).each(function(){var href=new jcommon.URI($(this).attr('href'));if(href.isSelfLink){$(this).addClass('current');$(this).unbind('mouseenter');$(this).unbind('mouseleave');$(this).find('img').each(function(){$(this).unbind('mouseenter');$(this).unbind('mouseleave');this.currentSrc=this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/,add+"$1");$(this).attr('src',this.currentSrc)});}});};

$(function(){

	//フォントの大きさ変更
	$("#fontresize")
		.html('<a href="#" class="smallFont"><img src="/shared/img/fig_size_s.gif" width="24" height="23" alt="小" class="btn" /></a><a href="#" class="medFont"><img src="/shared/img/fig_size_m.gif" width="24" height="23" alt="中" class="btn" /></a><a href="#" class="largeFont"><img src="/shared/img/fig_size_l.gif" width="24" height="23" alt="大" class="btn" /></a>')
		.find('.smallFont').click(function(){
			$('body').css({fontSize:'83%'});
			return false;
		}).end()
		.find('.medFont').click(function(){
			$('body').css({fontSize:'100%'});
			return false;
		}).end()
		.find('.largeFont').click(function(){
			$('body').css({fontSize:'120%'});
			return false;
		});
		
	//ロールオーバー
	$('a img.btn,#globalNav li a img').addRollOver('_on');

	//現在のページへのリンク
	$('#globalNav li a,#localNav li a').addCurrentImages('_cr');	

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href^="https://jashizuoka-keizairen.net/"],[href^="http://jashizuoka-keizairen.net/"])').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');

	//別ウィンドウを設定
	$('a[href$=".pdf"],a[href$=".asx"],a[href^="http://jashizuoka-keizairen.net/recruit/"],a[href^="http://jashizuoka-keizairen.net/ichigo/ichigo.htm"],a[href^="http://jashizuoka-keizairen.net/chainfo/index.html"],a[href^="http://jashizuoka-keizairen.net/pearl/p-top.htm"],a[href^="http://jashizuoka-keizairen.net/beef/top.htm"],a[href^="https://www.ek-system.ne.jp/www/toppage/0000000000000/APM03000.html"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	})
	
	//スタイル消去
	$('#globalNav li#ghome a').removeAttr('class');


	//するするアニメーション ※要scrollTo.js
	if(!$.browser.opera){
		$('a[href^="#"]:not([href^="#TAB"])','#wrapperIn').each(function(){
			this.target = $(this).attr('href');
		}).click(function(){
			$.scrollTo( this.target, {speed:800} );
			return false;
		});
	}//opera対策
	else if($.browser.opera){$('.toTop 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');
	});

	//ulのliにoddとevenを追加
	$('#mainContent .listBtn').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	
		//n段組み
	$('.col3 li:nth-child(3n)').add('.col4 li:nth-child(4n)').addClass('clearMargin');
	
	

	//:first-child, :last-childをクラスとして追加
	$('#globalNav li:first-child').addClass('firstChild');
	$('#globalNav li:last-child').add('#txtNav li:last-child').add('div#subContent #subBox p:last-child').add('#sitemap div#mainContent li:last-child').addClass('lastChild');

	//マウスオーバー追加用
	$('input')
	.add('label')
	.add('textarea')
	.removeClass('hover').hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover')});


});
