/*
 * yuga.js 0.3.0 - 優雅なWeb制作のためのJS
 *
 * Copyright (c) 2007 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since:     2006-10-30
 * Modified:  2007-06-18
 * Modified:  2007-10-26 by TA
 * Modified:  2009-11-13 by KI
 *
 */

/* common.js内で使っているfunction群 */
myDate = new Date();
var $thisYear = myDate.getFullYear();
var yuga = {
	// imageのプリローダー
	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(s){
		this.originalPath = s;
		
		// 絶対パスを取得
		this.getAbsolutePath = function(path){
			var img = new Image();
			img.src = path;
			path = img.src;
			img.src = '#';
			return path;
		};
	
		this.absolutePath = this.getAbsolutePath(s);
	
		// 同じ文書にリンクしているかどうか
		this.isSelfLink = (this.absolutePath == location.href);
	
		// 絶対パスを分解
		var a = this.absolutePath.split('://');
		this.schema = a[0];
		var d = a[1].split('/');
		this.host = d.shift();
		var f = d.pop();
		this.dirs = d;
		this.file = f.split('?')[0].split('#')[0];
		var fn = this.file.split('.');
		this.fileExtension = (fn.length == 1) ? '' : fn.pop();
		this.fileName = fn.join('.');
		var fq = f.split('?');
		this.query = (fq[1]) ? fq[1].split('#')[0] : '';
		var ff = f.split('#');
		this.fragment = (ff[1]) ? ff[1].split('?')[0] : '';	
	}
};

$(function(){
		
	// フッターコピーライト西暦自動表示
	var $copyright = "Copyright " + $thisYear + " HOSHI to MIDORI no ROMANKAN, All rights reserved."
	$('#copyright img').attr('alt',$copyright);
	
	// TOP メイン画像 [innerfade]
	$('#img-main li').css('display','block');
	$('#img-main').innerfade({
		speed : 2000,
		timeout : 5000,
		containerheight : 315		
	});
	
	// titstar タイトル画像
	$('.titstar').wrap($('<div class="titstar-wrap"></div>'));
	
	// 関連リンク
	$('#link li').hover(function(){
		$(this).css('opacity','0.7');
	},function(){
		$(this).css('opacity','1');
	});
	
	// class="btn"はロールオーバーを設定（src属性を_on付きのものに差し替える）
	$('.over').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
		yuga.preloader.load(this.rolloverSrc);
	}).hover(function(){
		$(this).attr('src',this.rolloverSrc);
	},function(){
		$(this).attr('src',this.originalSrc);
	});
	
		//PDF,Word,Exelファイルを別ウィンドウで表示
	$("a[href^='http://'],a[href^='https://']").each(function(){
		var $ThisLink = $(this).attr('href');
		var $SearchResult1 = $ThisLink.indexOf("http://www.roman-kan.net/",0);
		var $SearchResult2 = $ThisLink.indexOf("http://roman-kan.sakura.ne.jp/",0);
		var $SearchResult3 = $ThisLink.indexOf("https://roman-kan.sakura.ne.jp/",0);
		var $SearchResult4 = $ThisLink.indexOf("https://secure1839.sakura.ne.jp/roman-kan.net/",0);
	if($SearchResult1 < 0 && $SearchResult2 < 0 && $SearchResult3 < 0 && $SearchResult4 < 0 ){
			$(this).attr("target", "_blank");
		}
	})
	
	// ページ内リンクはするするアニメーション
	var pageUrl = location.href.split('#')[0];
	$('#wrapper a[href]').each(function() {
	if (this.href.indexOf(pageUrl + '#') == 0) {
	    var id = this.href.split('#')[1];
	    $(this).click(function() {
	      var idLink = '#' + id;
		  $.scrollTo( idLink , {duration: 1000, axis:"y",easing:"easeOutQuart"});
	      return false;
	    });  
	  }
	});

});

//【ポップアップ】予約フォーム
function reservation(html) {
	SubWindow=window.open(html,"reservation","width=700,height=740,left=50,top=50,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1");
	SubWindow.focus();
}


