/*
 * yuga.js 0.1.0
 * Copyright (c) 2006 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since:     2006-10-30
 * Modified:  2006-11-15
 */

/* Last Added: 2007-02-26 */

/*
 * jcommon.js 0.1.5.1
 * Copyright (c) 2007 C.M.A. Co.,Ltd.
 *
 * Last Added: 2007-12-17
 *
 */



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('#subNav li a').add('#localNav li a').add('#s-gnavi li a').add('#globalNav2 li a').each(function(){
		//alert("href = "+$(this).attr('href'));
		var href = new jcommon.URI($(this).attr('href'));
		if (href.isSelfLink) {
			$(this).addClass('current');
			//img要素が含まれていたら現在用画像（_cr）に設定
			$(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);
			});
		}
	});
	//
	$('#room #planNav li.planNav001 a').add('#eat #planNav li.planNav002 a').add('#stay #planNav li.planNav003 a').each(function(){
		$(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('http://www.kaneyamaen.com/').click(function(){
		window.open(this.href, '');
		return false;
	}).addClass('externalLink');*/

	//奇数、偶数を自動追加
	$('ul').add('ol').each(function(){			 //Added ol 2007-02-26
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	$('table').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});
	$('dl').each(function(){
		$(this).find('dt:odd').addClass('even'); //Added 2007-02-26
		$(this).find('dt:even').addClass('odd'); //Added 2007-02-26
		$(this).find('dd:odd').addClass('even'); //Added 2007-02-26
		$(this).find('dd:even').addClass('odd'); //Added 2007-02-26
	});

	$('#home #news li:last-child').add('.toTop li:last-child').add('#mainContent table thead th:last-child').addClass('lastChild');

	//ボタンのマウスオーバー
	$('a img.alpha').hover(function(){$(this).fadeTo(100,0.7);},function(){$(this).fadeTo(100,1.0);});

	//dd要素を出したり消したり
	$('#faq dl.list').each(function(){
		$(this).children('dd').hide();
		$(this).before('<p class="alignR"><a>回答をすべて表示</a></p>');
	});
	$('#faq p.alignR a').click(function(){
		if($(this).parent().next().children('dd').is(':visible')){
			$(this).parent().next().children('dd').hide();
			$(this).text('回答をすべて表示');
		}else{
			$(this).parent().next().children('dd').show();
			$(this).text('回答をすべて非表示');
		}
	});
	$('#faq dl.list dt').click(function(){
		if($(this).next().is(':visible')){
			$(this).next().hide();
			if(!$(this).nextAll('dd').is(':visible')){
				$(this).parent().prev().children().text('回答をすべて表示');
			}
		}else{
			$(this).next().show();
			$(this).parent().prev().children().text('回答をすべて非表示');
		}
	});

});
