/**
*
* PRART_JS_FILE For www.tokyustay.co.jp
* 
**/


/* default variables
============================================================*/

window.onerror = null;

var d = document;

var isIE = d.all;            // IE
var isN6 = d.getElementById; // N6
var isN4 = d.layers;         // N4


/* client variables
============================================================*/

var agent = navigator.userAgent.toLowerCase();

var win = (agent.indexOf("windows") != -1);
var mac = (agent.indexOf("mac") != -1);
var gecko = agent.indexOf("gecko") != -1;
var opera = agent.indexOf("opera",0) != -1;
var safari = agent.indexOf("safari") != -1;
var ie = agent.indexOf("msie") != -1 && !opera;
var ie5win = (agent.indexOf("msie 5.") != -1) && win;
var ie6win = (agent.indexOf("msie 6.") != -1) && win;
var ie7win = (agent.indexOf("msie 7.") != -1) && win;
var ie5mac = (agent.indexOf("msie") != -1) && mac;
var ns = agent.indexOf("netscape") != -1 && !opera;
var ns6 = (agent.indexOf("netscape6/6.") != -1) && ns;


/* PNG Image for IE5.x,6.x
============================================================*/
d.open();
if(ie6win){ d.write('<script type="text/javascript" src="/e/matrix/js/DD_belatedPNG.js"></script>')}
d.close();


/* scroll function
============================================================*/

function CurrLeft() {
	if (isIE) {
		if(d.compatMode){
			return d.documentElement.scrollLeft;
		} else {
			return d.body.scrollLeft;
		}
	} else if (window.pageXOffset) {
		return window.pageXOffset;
	} else {
		return 0;
	}
}

function CurrTop() {
	if (isIE) {
		if(d.compatMode=="CSS1Compat"){
			return d.documentElement.scrollTop;
		} else {
			return d.body.scrollTop;
		}
	} else if (window.pageYOffset) {
		return window.pageYOffset;
	} else {
		return 0;
	}
}

function PageScroll(){

	var scrolledX = null;
	var scrolledY = null;
	var targetX = null;
	var targetY = null;
	var scrollX,scrollY;
	var url = location.href.replace(location.hash,"");
	var ScrollBtns = d.getElementsByTagName("a");

	for(var i=0;i<ScrollBtns.length;i++){
		if(ScrollBtns[i].getAttribute("Href").match("#")){
			var btn = ScrollBtns[i];
			btn.onclick = function(){
				var TargetId = (this.getAttribute('href').replace(url,"")).substr(1);
				if (d.getElementById(TargetId)){
					var Target = d.getElementById(TargetId);
					targetX = Target.offsetLeft , targetY = Target.offsetTop;
					scrollX = CurrLeft() , scrollY = CurrTop();
					scrolling();
					return false;
				}
			}
		}
	}

	if (d.getElementsByTagName("area")){
		var ScrollBtns = d.getElementsByTagName("area");
		for(var i=0;i<ScrollBtns.length;i++){
			if(ScrollBtns[i].getAttribute("Href").match("#")){
				var btn = ScrollBtns[i];
				btn.onclick = function(){
					var TargetId = (this.getAttribute('href').replace(url,"")).substr(1);
					if (d.getElementById(TargetId)){
						var Target = d.getElementById(TargetId);
						targetX = Target.offsetLeft , targetY = Target.offsetTop;
						scrollX = CurrLeft() , scrollY = CurrTop();
						scrolling();
						return false;
					}
				}
			}
		}
	}

	function scrolling(){
		var X = CurrLeft();
		var Y = CurrTop();
		scrollX += Math.floor((targetX - X) / 6);
		scrollY += Math.floor((targetY - Y) / 6);
		if((targetY === scrollX && targetY === scrollY) || (X === scrolledX && Y === scrolledY)) {
			scrolledX = scrolledY = null;
		} else {
			window.scrollTo(scrollX, scrollY);
			scrolledX = X , scrolledY = Y;
			setTimeout(function(){scrolling()},2);
		}
	}
}



/* rollover function
============================================================*/
function setRollOver(){

	if(!d.getElementsByTagName) return false;

	var ovrImgList = d.getElementsByTagName("img");
	var sizeList = new Array();

	for(var i=0;i<ovrImgList.length;i++){
		if(ovrImgList[i].src.match("_off")){
			preloadImage(ovrImgList[i].src.replace(/_off./i,"_on."));
			if( ovrImgList[i].src.match(/textSize/) ){
				sizeList[sizeList.length] = ovrImgList[i];
			} else {
				if(ovrImgList[i].className.match("alpha")){
					ovrImgList[i].onmouseover = function(){
						this.src = this.src.replace(/_off./i,"_on.");
						new Effect.Opacity(this, { from:0.5, to:1, duration: 0.7 });
						return false;
					}
				} else {
					ovrImgList[i].onmouseover = function(){
						this.src = this.src.replace(/_off./i,"_on.");
						return false;
					}
				}
				ovrImgList[i].onmouseout = function(){
					this.src = this.src.replace(/_on./i,"_off.");
					return false;
				}
			}
		} else if(ovrImgList[i].className.match("alpha")){
			ovrImgList[i].onmouseover = function(){
				new Effect.Opacity(this, { from:0.7, to:1, duration: 1 });
			}
		}
	}
	if (sizeList[0]) {
		sizeList[0].onclick = function(){
			setCSS('medium');
			sizeList[1].src = "/e/matrix/img/portal/textSize_l_off.gif";
		}
		sizeList[1].onclick = function(){
			setCSS('large');
			sizeList[0].src = "/e/matrix/img/portal/textSize_m_off.gif";
		}
	}
}


/* preload function
============================================================*/
function preloadImage(url){
	var preloadedImages = [];
	var l = preloadedImages.length;
	preloadedImages[l] = new Image();
	preloadedImages[l].src = url;
}


/* stripe table function
============================================================*/
function stripeTable(){

	if ( d.getElementsByTagName("table") ){

		var tables = d.getElementsByTagName("table");
		for (var i=0, len=tables.length; i<len; i++){
			var table = tables[i];			
			var lines = table.getElementsByTagName("tr");
			for (var j=0, llen=lines.length; j<llen; j++){
				var node = lines[j];
				if(j%2==0) {
					node.className = "odd";
				} else {
					node.className = "even";
				}
			}
		}
	}
}


/* Best Rate Offer
============================================================*/
function BRO(){

	if ( d.getElementById("BRO") ){
		var btns = [];
		var originalSrc;
		btns[0] = d.getElementById("BRObtn01");
		btns[1] = d.getElementById("BRObtn02");
		btns[2] = d.getElementById("BRObtn03");
		for (var i=0, len=btns.length; i<len; i++){
			preloadImage(btns[i].src.replace(/_close./i,"_open."));
			btns[i].onclick = function(){
				var node = d.getElementById(this.getAttribute('id').replace(/btn/,"body"));
				if ( this.src.match("_close") ) {
					this.src = this.src.replace(/_close./i,"_open.");
					node.className = "";
				} else {
					this.src = this.src.replace(/_open./i,"_close.");
					node.className = "close";
				}
			}
		}
	}
}


/* show & hide
============================================================*/

function showMenu(){
	var node = d.getElementById("hotelsNaviInner");
	var selectList = d.getElementsByTagName("select");
	if( ie6win ){
		for(var i=0;i<selectList.length;i++){
			selectList[i].style.visibility = 'hidden';
		}
	}
	node.className = "";
}
function hideMenu(){
	var node = d.getElementById("hotelsNaviInner");
	var selectList = d.getElementsByTagName("select");
	if( ie6win ){
		for(var i=0;i<selectList.length;i++){
			selectList[i].style.visibility = 'visible';
		}
	}
	node.className = "hide";
}
function rollOver(node){
	node = node.replace(/_off./i,"_on.");
}
function rollOut(node){
	node = node.replace(/_on./i,"_off.");
}


/* searchBtn
============================================================*/
function searchBtn(){

	if(!d.getElementsByTagName) return false;
	var inputList = d.getElementsByTagName("input");
	
	for(var i=0,len=inputList.length; i<len;i++){
		if(inputList[i].className.match("alpha")){
			inputList[i].onmouseover = function(){
				new Effect.Opacity(this, { from:0.7, to:1, duration: 1 });
				return false;
			}
		}
	}
}


/* TextSize function
============================================================*/

var sizeM = "100%";    // 12px
var sizeL = "108.3%";  // 13px

var sizeNameM = "medium";
var sizeNameL = "large";

function setCSS(title) {

	if(!title){
		var title = readCookie();
	}

	var obj = d.getElementById('main');

	switch(title){
		case sizeNameM: obj.style.fontSize = sizeM;
			if ( d.getElementById("btnM") ) {
				d.getElementById("btnM").src = d.getElementById("btnM").src.replace(/_off./i,"_on.");
			} break;
		case sizeNameL: obj.style.fontSize = sizeL;
			if ( d.getElementById("btnL") ) {
				d.getElementById("btnL").src = d.getElementById("btnL").src.replace(/_off./i,"_on.");
			} break;
		default: obj.style.fontSize = sizeM;
			if ( d.getElementById("btnM") ) {
				d.getElementById("btnM").src = d.getElementById("btnM").src.replace(/_off./i,"_on.");
			} break;
	}
}

function getCSS() {
	var obj = d.getElementById('main');

	if(obj.style.fontSize != ""){
		switch(obj.style.fontSize){
			case sizeM: return sizeNameM; break;
			case sizeL: return sizeNameL; break;
			default: return null;
		}
	} else return null;
}

function createCookie() {
	var title = getCSS();
	var date = new Date();
	date.setTime(date.getTime()+(365*24*60*60*1000));
	var expires = "; expires=" + date.toGMTString();
	d.cookie = "style=" + title + expires + "; path=/";
}

function readCookie(name) {
	var ca = d.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf("style=") == 0) return c.substring("style=".length,c.length);
	}
	return null;
}


/* Popup setting
============================================================*/

function popup1(path){
	var conf = "width=840";
	conf += ",height=500";
	conf += ",scrollbars=no";
	conf += ",resizable=no";
	conf += ",toolbar=no";
	conf += ",directories=no";
	conf += ",location=no";
	conf += ",menubar=no";
	conf += ",status=no";
	window.open(path,"subwin",conf);
}

function popup2(path){
	var conf = "width=500";
	conf += ",height=610";
	conf += ",scrollbars=no";
	conf += ",resizable=no";
	conf += ",toolbar=no";
	conf += ",directories=no";
	conf += ",location=no";
	conf += ",menubar=no";
	conf += ",status=no";
	window.open(path,"subwin",conf);
}

function openPanorama(url){
	var conf = "width=840";
	conf += ",height=610";
	conf += ",scrollbars=no";
	conf += ",resizable=no";
	conf += ",toolbar=no";
	conf += ",directories=no";
	conf += ",location=no";
	conf += ",menubar=no";
	conf += ",status=no";
	window.open(url,"panorama",conf);
}

function openPcinfo(url){
	var conf = "width=456";
	conf += ",height=487";
	conf += ",scrollbars=no";
	conf += ",resizable=no";
	conf += ",toolbar=no";
	conf += ",directories=no";
	conf += ",location=no";
	conf += ",menubar=no";
	conf += ",status=no";
	window.open(url,"pcwin",conf);
}

/* mail function
============================================================*/
function mail_NS(i_1,i_2) { eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + i_1 + String.fromCharCode(60,110,105,115,104,105,45,115,104,105,110,106,117,107,117,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  i_2 + "'");}
function mail_AO(i_1,i_2) { eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,97,111,121,97,109,97,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_YU(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,109,101,103,117,114,111,45,121,117,116,101,110,106,105,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_SUI(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,115,117,105,100,111,98,97,115,104,105,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_YOT(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,121,111,116,115,117,121,97,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_YO(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,121,111,103,97,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_MON(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,109,111,110,122,101,110,45,110,97,107,97,99,104,111,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_GO(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,103,111,116,97,110,100,97,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_SIB(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,115,104,105,98,117,121,97,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_NI(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,110,105,104,111,109,98,97,115,104,105,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_HIG(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,104,105,103,97,115,104,105,45,103,105,110,122,97,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_SIM(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,115,104,105,98,117,121,97,50,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}
function mail_SHI(i_1,i_2){ eval(String.fromCharCode(108,111,99,97,116,105,111,110,46,104,114,101,102,32,61,32,39,109,97,105,108,116,111,58) + escape(i_1) + String.fromCharCode(60,115,104,105,109,98,97,115,104,105,64,116,111,107,121,117,115,116,97,121,46,99,111,46,106,112,62,63,115,117,98,106,101,99,116,61) +  escape(i_2) + "'")}


/* onload function
============================================================*/
function setOnLoad(){
	setRollOver();
	PageScroll();
	BRO();
	setCSS();
	searchBtn();
}

window.onload = setOnLoad;

window.onunload = function() {
	createCookie();
}

// E N D