/*
 * 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(){



	//本番用
	// -------------------------------------------------------------------------------
	if(document.domain=="www.mizumoto.ac.jp" || document.domain=="mizumoto.ac.jp"){
		catName=location.pathname.split('/');
		catName=catName.slice(1,2);
		$('a[href^="/"],link[href^="/"]').each(function(){
			var dirName=$(this).attr('href');
			$(this).attr({href:'/'+catName+dirName});
		});
		$('img[@src^="/"]').each(function(){
			var dirName=$(this).attr('src');
			$(this).attr({src:'/'+catName+dirName});
		});
	}
	// -------------------------------------------------------------------------------



	//リンク画像はロールオーバーを設定
	$('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('#subNav 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('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://www.mizumoto.ac.jp/france/"],[href^="https://www.mizumoto.ac.jp/france/"],[href^="http://mizumoto.ac.jp/france/"],[href^="https://mizumoto.ac.jp/france/"])').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;
	})

	//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');
	});
	
	//lightBox()
	$('[@href$=".jpg"],[href$=".gif"]').lightBox();//,a[href$=".png"]').lightBox();
	
	//ブロック要素の高さを調節
	$('ul.mofChef li,body#eveIndex div#mainContent div#eveSchedule ul li,ul#frenchPhoto li').flatHeights();
	

});
