/*
 * jcommon.js 0.9
 * Copyright (c) 2007 C.M.A. Co.,Ltd.
 *
 * Last Added: 2007-01-15
 *
 */



var ary = location.pathname.split('/');



	//テストサイト用 //本アップ時に削除すること //ホームのcurrentの解除
	// -------------------------------------------------------------------------------
	if(document.domain == "hs20.drive.ne.jp")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++){isLinkAry[k]=ary.slice(0,ary.length-l);isLinkAry[k]=isLinkAry[k].join('/');isLinkAry[k]=isLinkAry[k].replace(/^\//,"");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(/^[^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=="hs20.drive.ne.jp"){testName=location.pathname.split('/');testName=testName.slice(1,2);$('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})})}
	// -------------------------------------------------------------------------------



	//リンク画像はロールオーバーを設定
	$('a img.btn').add('.globalNav li a img').add('.subNav 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('.subNav li a').add('.localNav dd 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);
			});
		}
	});

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href^="http://hmmt.co.jp/"])').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');

	//別ウィンドウを設定
	$('a[href$=".pdf"],a[href$=".asx"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	})

	//するするアニメーション ※要scrollTo.js
	$('a[href^="#"]:not(#surRecycle .pageNav 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を追加
	$('ul').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});

	//h2に連番をクラスとして追加
	var h2count = 0;
	$('#mainContent div.section h2').each(function(){
		h2count++;
		$(this).addClass('num'+h2count);
	});

	//:first-child, :last-childをクラスとして追加
	//$(':first-child').addClass('firstChild');
	$('.globalNav li:last-child').add('.subNav li:last-child').addClass('lastChild');


	//タブ
	$('#surRecycle #mainContent').each(function(){
		var tabWrapper = $(this);
		var targetTab = location.hash;
		if(location.search != ''){
			 targetTab = location.search;
			 targetTab = targetTab.replace('?','#');
		}
		$(this).find('.section').hide();
		if(targetTab == ''||targetTab == '#top'||targetTab == '#content')targetTab = $(this).find('.selected a').attr('href');
		$(targetTab).show();
		$(this).find('.pageNav a').each(function(){
			$(this).parent().removeClass('selected');
			$(this).filter('[href="'+targetTab+'"]').parent().addClass('selected');
		}).click(function() {
			targetTab = $(this).attr('href');
			tabWrapper.find('.section').hide();
			tabWrapper.find('.pageNav dd').removeClass('selected');
			$(this).parent().addClass('selected');
			$(targetTab).show();
			return false;
		});
	});
	
	$('#surRecycle table tr td:first-child').each(function(){
		$(this).addClass($(this).text());
		$(this).filter('[class*="(C)"]').parent().addClass("colorC");
		$(this).filter('[class*="(M)"]').parent().addClass("colorM");
		$(this).filter('[class*="(Y)"]').parent().addClass("colorY");
		$(this).filter('[class*="(Bk)"]').parent().addClass("colorBk");
	});

	//新着情報一覧を読み込む
	$('#home .news dd').load('news/toplist.html');
});