
// 自身のhtmlファイルを返す
function get_myHTML(target){
	var p1 = target.lastIndexOf('/');
	var p2 = target.lastIndexOf('.');
	var value = target.slice(p1+1, p2) + target.substr(p2, 5);
	return value;
}


//----------------------------------------------------------
// JQuery
//----------------------------------------------------------


// コンフリクトを回避
j$=jQuery.noConflict();

(function($) {

	// boxの高さを揃える
	function setEqualHeight(columns){
		var tallestcolumn = 0;
		columns.each(　function(){
			currentHeight = $(this).height();
			if(currentHeight > tallestcolumn){
				tallestcolumn  = currentHeight;
			}
		});
		// ブラウザ分岐処理
		// （IE7以下＝height適用、それ以外はmin-height適用）
		if ($.browser.msie && $.browser.version < 7){
			columns.css("height",tallestcolumn);
		} else{
			columns.css("min-height",tallestcolumn);
		}
	}

	$(function(){

		//ロールオーバー
		$("img.swap").mouseover(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_o$2").replace("_o_o","_o"));
		}).mouseout(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)_o(\.[a-z]+)$/, "$1$2"));
		}).each(function(){
			$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_o$2"));
		}).click(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)_o(\.[a-z]+)$/, "$1$2"));
		});

		// for /index.php
		var height_array = [60,60,60]
		$("#bestRank dd").each(function(i){
			n=i%3;
			tmpHeight=$(this).height();
			if(height_array[n]<tmpHeight){
				height_array[n]=tmpHeight;
			}
		});
		$("#bestRank dd").each(function(i){
			n=i%3;
			$(this).height(height_array[n]);
		});	
		$(".plan .box + .box").each(function(){
			setEqualHeight($(this).parent().find(".box .pl_detail div"));
		});
		// for plan/index.php
		$(".box_stayplan + .box_stayplan").each(function(){
			setEqualHeight($(this).parent().find(".box_stayplan tr:nth-child(1) h4"));
			setEqualHeight($(this).parent().find(".box_stayplan tr:nth-child(2) div"));
		});
		$(".box_stayplan dl").css("margin-bottom","0");
		$(".box_stayplan dl").css("padding-top","6px");
		$(".box_stayplan dl").css("margin-top","0");
		// for guide/inquiry.html 
		$(".column_l + .column_r").each(function(){ 
			setEqualHeight($(this).parent().find("div.heightLine-1")); 
		});
		// other
		setEqualHeight($(".heightLine"));

		//アンカーリンク
		if(location.href.indexOf("file")==0){
			var url = "file://" + location.hostname + location.pathname + location.search;
		}else if(location.href.indexOf("https")==0){
			var url = "https://" + location.hostname + location.pathname + location.search;
		}else{
			var url = "http://" + location.hostname + location.pathname + location.search;
		}
		$("a[href*=#],area[href*=#]").click(function() {
			var id = this.href.substring(this.href.indexOf('#'),this.href.length);
			var hrefUrl = this.href.split(id);
			if(String(hrefUrl[0]) == String(url)) {
				var hash = this.hash;
				if(!hash || hash == "#")
					return false;
				if(id == '#inbox') { 
					$($.browser.safari ? 'body' : 'html')  
						.animate({scrollTop: 0}, 500, "easeInOutCubic");
					return false;
				}else if(id != "#"){
					$($.browser.safari ? 'body' : 'html')  
						.animate({scrollTop: $(hash).offset().top}, 500, "easeInOutCubic");
					return false;
				}
			}
		});

		//外部リンクアイコン
		$("a[target='_blank']").addClass("external");
		$(".info a[target='_blank'], p.link a[href^='http://'], ul.link a[href^='http://'], td.link a[href^='http://']").append('<span class="icon-external"><img src="/images/icon_external.gif" alt="" width="14" height="9" /></span>');

		$("img.lucent, ul.side_bnr img, #visual a img, .list_price img, .topBnr a img").hover(function() {
			$(this).animate({ opacity: .8 },{ duration: 200, queue: false })
		}, function() {
			$(this).animate({ opacity: 1 }, { duration: 200, queue: false })
		});

		// 干潮時間検索
		function setDays() {
			var url = "/angel/shioji.php";
			var parmyy = "?s_yy=";
			var parmmm = "&amp;s_mm=";
			var parmdd = "&amp;s_dd=";
			var parmetc = "&amp;TB_iframe=true&amp;keepThis=true&amp;width=300&amp;height=150";
			var str = url+parmyy+$("#s_yy").val()+parmmm+$("#s_mm").val()+parmdd+$("#s_dd").val()+parmetc;
			$("#btnshioji").attr({alt:str});
		}
		$("#boxA select").change(setDays);

	});

})(jQuery);

