/*
 * jcommon.js 0.1.5.1
 * Copyright (c) 2007 C.M.A. Co.,Ltd.
 *
 * Last Added: 2007-12-25
 *
 */

var ary = location.pathname.split('/');


//階層分、URI生成
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('/');
//	alert("isLinkAry[k] = "+isLinkAry[k]);
}
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
	URI: function(path){
		path = path.replace(/^https[^a-z]*[^\/]*/,"");	//httpからドメインまであったら削除
		path = path.replace(/^[^a-z]*/,"");	//'../'があったら削除
		path = path.replace(/index.*$/,"");	//'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]);
		}
		this.isSelfLink2=(this.absolutePath==location.href);
	}
};


$(function(){

	//リンク画像はロールオーバーを設定
	$('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('.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)/, "_cr$1");
				$(this).attr('src',this.currentSrc);
			});
		}
	});


	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]').add('a[href^="https://"]').not('[href^="http://www.tea-pack.com/"]').not('[href^="http://tea-pack.com/"]').not('[href^="https://teapa956.securesites.com/"]').click(function(){
//	$('a[@href^="http://"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');//*/



	//PDF・ASXを別ウィンドウ-Added 2007-02-26
	$('a[href$=".pdf"]').add('a[href$=".asx"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	})

	//ulのliにoddとevenを追加
	$('ul').each(function(){
		$(this).find('li:odd').addClass('odd');
		$(this).find('li:even').addClass('even');
	});

	//マウスーバー時、画像を半透明にする
	$('a img.alpha').hover(function(){
		$(this).fadeTo(100,0.7);
	},function(){
		$(this).fadeTo(100,1.0);
	});




});