/* ---------- global variables ---------- */

var TOYOKOINN_SARI_safemode        = 1;
var TOYOKOINN_SARI_safemode_array  = ["img","input"];
var TOYOKOINN_SARI_className       = "SARI";
var TOYOKOINN_mailto_className     = "mailto";
var TOYOKOINN_lightbox_className   = "LB";
var TOYOKOINN_debug_mode           = false;
var TOYOKOINN_debugger             = null;


/*
TOYOKOINN_SARI_safemode:
1 : searching for nodes with "TOYOKOINN_SARI_className" from the nodes that have tag name in "TOYOKOINN_SARI_safemode_array"
0 : searching for it from all of the nodes. but it's so expensive
you'd better choose "1", unless some special reasons can be found.
*/









/* ---------- start up items ----------
when the event "window.onload" is generated, items of "startup_items" will be executed as a function one after another. 
To execute some scripts when the event "onload" is generated, you should make it a function and push it into the "startup_items".
*/
var startup_items = [];
window.onload = function(){ for(var i=0 ; i<startup_items.length ; i++) startup_items[i](); };
var onresize_items = [];
window.onresize = function(){ for(var i=0 ; i<onresize_items.length ; i++) onresize_items[i](); };










/* ---------- switch css ---------- */
if(!document.layers){
	
	if(browser.nav == "Firefox" && browser.plf.major == "MacOSX" ) document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/common/_css/MacFx.css\" media=\"screen,print\">");
	if(browser.nav == "Firefox" && browser.plf.major == "MacOSX" ) document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/MacFx.css\" media=\"screen,print\">");
	
	
	if(browser.nav == "MSIE") document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/common/_css/WinIE.css\" media=\"screen,print\">");
	if(browser.nav == "MSIE") document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/WinIE.css\" media=\"screen,print\">");
	
	if(browser.nav == "Firefox" && browser.plf.major == "Windows") {
		document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/array_02_mod.css\" media=\"screen,print\">");
	}
	else if(browser.nav == "MSIE")
	{
		if(browser.ver.major == "7")
		{
			document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/array_02_mod.css\" media=\"screen,print\">");
		}
		else {
			document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/array_02.css\" media=\"screen,print\">");
		}
	}
	else {
			document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/array_02.css\" media=\"screen,print\">");
	}
	
	if(browser.nav == "Safari") document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/common/_css/safari.css\" media=\"screen,print\">");
	if(browser.nav == "Safari") document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"_css/safari.css\" media=\"screen,print\">");
	
	if ( (browser.nav == "IPhone") || (browser.nav == "Android") ) document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/common/_css/smart.css\"     media=\"screen,print\">");
	else                                                           document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/common/_css/smart_not.css\" media=\"screen,print\">");
}










/* ---------- common library ---------- */

function puWindow(url,nam,wid,hei,prop){
	var offset = 0;
	var w = window.screen.width;
	var h = window.screen.height;
	var l = (w-wid)/2;
	var t = ((h-hei)/2)-offset;
	sty = prop;
	sty+= ",width=";
	sty+= wid;
	sty+= ",height=";
	sty+= hei;
	sty+= ",left=";
	sty+= l;
	sty+= ",top=";
	sty+= t;
	window.open(url,nam,sty);
}

function popup0(url,nam,wid,hei){
	prop = "status=no,scrollbars=no,resizable=no";
	wid = (wid <= window.screen.width)  ? wid : window.screen.width  * 0.8 ;
	hei = (hei <= window.screen.height) ? hei : window.screen.height * 0.8 ;
	puWindow(url,nam,wid,hei,prop);
}

function popup1(url,nam,wid,hei){
	prop = "status=yes,scrollbars=yes,resizable=yes";
	wid = (wid <= window.screen.width)  ? wid : window.screen.width  * 0.8 ;
	hei = (hei <= window.screen.height) ? hei : window.screen.height * 0.8 ;
	puWindow(url,nam,wid,hei,prop);
}





function getElementsByTagAndClassName(tag_name,class_name){
	/*
	this is not a method but a function.
	This returns it as Array, when the corresponding elements are discovered.
	This returns false, when the corresponding tag name or class name is not able to be discovered.
	when you do not want to limit the kind of tag, you can use "*" for the 1st argument but it's so expensive.
	*/
	var return_array = [];
	if(!document.getElementsByTagName(tag_name)) return false;
	
	var tmp = document.getElementsByTagName(tag_name);
	for(var i=0 ; i<tmp.length ; i++){
		var class_array = tmp[i].className.split(" ");
		for(var c=0 ; c<class_array.length ; c++){
			if(class_array[c] == class_name){
				return_array[return_array.length] = tmp[i];
			}
		}
	}
	if(return_array.length < 1) return false;
	return return_array;
}


function getNextElement(obj){
	/*
	this returns the next "element" of the node passed as an argument. 
	*/
	var return_obj = null;
	
	(function (obj){
		if(!obj.nextSibling){
			// do nothing
		}
		else{
			if(obj.nextSibling.nodeType == 1){
				return_obj = obj.nextSibling;
			}
			else{
				arguments.callee(obj.nextSibling);
			}
		}
	})(obj);
	
	return return_obj;
}

function clearChildNodes(obj){
	/*
	this makes the element passed as an argument empty.
	and this returns nothing.
	*/
	if(!obj) return;
	
	for(var i=obj.childNodes.length-1 ; i>=0 ; i--){
		obj.removeChild(obj.childNodes[i]);
	}
}

function createXMLHttpRequest(){
	/*
	this returns new XMLHttpRequest Object.
	*/
	var XMLhttpObject = null;
	try{
		XMLhttpObject = new XMLHttpRequest();
	}
	catch(e){
		try{
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				return null;
			}
		}
	}
	return XMLhttpObject;
}



function getDomainString(str){
	/*
	this pulls out the DOMAIN part from URL and returns it. 
	*/
	return str.split("/")[2];
}



function getPathString(str){
	/*
	this pulls out the PATH part from URL and returns it. 
	*/
	var tmp1 = str.split("/");
	var tmp2 = "";
	for(var w=3 ; w<tmp1.length ; w++){
		tmp2 += "/" + tmp1[w]
	}
	return tmp2;
}



function createGetString(param){
	/*
	this returns the parameter as GET format string.
	*/
	var str = "";
	for(var i in param){
		str += (str == "") ? "" : "&" ;
		str += i + "=" + param[i];
	}
	
	return str;
}


String.prototype.addGetParameter = function(param){
	/*
	this adds the parameter as GET format string and returns it.
	*/
	return (this.indexOf("?") != -1) ? this + "&" + createGetString(param) : this + "?" + createGetString(param) ;
}

String.prototype.untiCache = function(){
	/*
	this adds the timestamp string and returns it.
	*/
	var tmp = new Date();
	var param = { untiCache : tmp.getTime() };
	
	return this.addGetParameter(param);
}











/* ---------- debug ---------- */

function DeBug(){
	
	
	var DBW = null;
	if(TOYOKOINN_debug_mode){
		if(!document.getElementById("debug-window")){
			DBW = document.createElement("textarea");
			DBW.style.position = "absolute";
			DBW.style.width = "300px";
			DBW.style.height = "300px";
			DBW.style.bottom = "0px";
			DBW.style.right = "0px";
			DBW.id = "debug-window";
			
			document.body.appendChild(DBW);
		}
		else{
			DBW = document.getElementById("debug-window");
		}
	}
	
	
	function DB(obj){
		
		this.obj = obj;
		
	}
	DB.prototype = {
		
		write : function(str){
			if(!TOYOKOINN_debug_mode) return;
			this.obj.value += str + "\n";
		},
		
		clear : function(){
			if(!TOYOKOINN_debug_mode) return;
			this.obj.value = "";
		}
		
	}
	
	
	TOYOKOINN_debugger = new DB(DBW);
	
	
	
}
startup_items[startup_items.length] = DeBug;









/* ---------- mailto link ---------- */

function mailto2link(){
	/*
	the mail address written in html with A element may be collected by fuckin spamers.
	therefore, we should not write the mail address directly in html. 
	you'd better replace "@" with "&#64;" and use SPAN element with "TOYOKOINN_mailto_className" as class attribute.
	*/
	var tmp = getElementsByTagAndClassName("span",TOYOKOINN_mailto_className);
	for(var i=0 ; i<tmp.length ; i++){
		tmp[i].onclick = function(){
			var address = (function(){
				if(this.childNodes[0].nodeName == "IMG"){
					return this.childNodes[0].alt;
				}
				else{
					return this.childNodes[0].nodeValue;
				}
			})();
			
			window.location.href = "mailto:" + address;
		}
	}
}
startup_items[startup_items.length] = mailto2link;










/* ---------- image rollover ---------- */

function SARI(){
	/*
	when you want to use the rollover effect in html coding, you'd better set "TOYOKOINN_SARI_className" as the class attribute of the corresponding element.
	you have nothing to do to preload swap images :-)
	*/
	
	
	function SR(obj){
		
		var SR = this;
		
		this.obj = obj;
		this.f1 = document.createElement("img");
		this.f2 = document.createElement("img");
		
		var pattern = /_f[12]\./;
		
		this.f1.src = this.obj.src;
		this.f2.src = this.obj.src.replace(pattern,"_f2.");
		
		function setEvent(){
			if(SR.obj.className.indexOf(TOYOKOINN_SARI_className) == -1) return;
			
			SR.obj.onmouseover = function(){
				this.src = SR.f2.src;
			}
			SR.obj.onmouseout = function(){
				this.src = SR.f1.src;
			}
		}
		
		
		if(browser.nav == "MSIE"){
			setEvent();
		}
		else{
			this.f2.onload = setEvent;
		}
		
		
	}
	
	// expensive mode
	if(TOYOKOINN_SARI_safemode == 0){
		var tmp = getElementsByTagAndClassName("*",TOYOKOINN_SARI_className);
	}
	// normal mode
	else{
		var tmp = [];
		for(var sm=0 ; sm<TOYOKOINN_SARI_safemode_array.length ; sm++){
			var tmp_safe = getElementsByTagAndClassName(TOYOKOINN_SARI_safemode_array[sm],TOYOKOINN_SARI_className);
			if(tmp_safe != false) tmp = tmp.concat(tmp_safe);
		}
	}
	
	var SR_set = [];
	for(var i=0 ; i<tmp.length ; i++){
		SR_set[i] = new SR(tmp[i]);
	}
}
startup_items[startup_items.length] = SARI;











/* ---------- light box ---------- */

function LBox(){
	
	/*
	this is a controller of Light Box.
	this is a different thing though looked like the light box.
	*/
	
	
	
	function lightbox(smallimg){
		
		var LB = this;
		
		this.min_width = 381;
		this.timerID = null;
		
		this.p_image = document.createElement("p");
		this.p_image.className = "image";
		
		this.img_print_f1 = document.createElement("img");
		this.img_print_f1.src = TOYOKOINN_source_server+"/common/_img/_lig_foo_but_01_lod.gif";
		this.img_print_f2 = document.createElement("img");
		this.img_print_f2.src = TOYOKOINN_source_server+"/common/_img/_lig_foo_but_01.gif";
		this.img_print_f3 = document.createElement("img");
		this.img_print_f3.src = TOYOKOINN_source_server+"/common/_img/_lig_foo_but_01_err.gif";
		this.img_print = document.createElement("img");
		this.img_print.src = this.img_print_f1.src
		this.p_print = document.createElement("p");
		this.p_print.className = "print";
		this.p_print.appendChild(this.img_print);
		
		this.img_close = document.createElement("img");
		this.img_close.src = TOYOKOINN_source_server+"/common/_img/_lig_foo_but_02.gif";
		this.p_close = document.createElement("p");
		this.p_close.className = "close";
		this.p_close.appendChild(this.img_close);
		
		this.img_copy = document.createElement("img");
		this.img_copy.src = TOYOKOINN_source_server+"/common/_img/_lig_foo_cop.gif";
		this.p_copy = document.createElement("p");
		this.p_copy.className = "copylight";
		this.p_copy.appendChild(this.img_copy);
		
		this.foot = document.createElement("div");
		this.foot.className = "foot";
		this.foot.appendChild(this.p_close);
		this.foot.appendChild(this.p_copy);
		
		this.stage = document.createElement("div");
		this.stage.className = "lightbox-stage";
		this.stage.appendChild(this.p_image);
		this.stage.appendChild(this.p_print);
		this.stage.appendChild(this.foot);
		
		this.curtain = document.createElement("div");
		this.curtain.className = "lightbox-curtain";
		
		
		this.S_img = smallimg;
		this.L_img = document.createElement("img");
		
		this.S_img.onclick = function(){
			LB.Show();
		}
		
		this.curtain.onclick = this.img_close.onclick = function(){
			LB.Hide();
		}
		
		onresize_items[onresize_items.length] = function(){ LB.SetStyle(LB.L_img.width,LB.L_img.height) };
		
		
	}
	lightbox.prototype = {
		
		SetStyle : function(wid,hei){
			if(browser.nav == "MSIE"){
				this.curtain.style.pixelWidth  = getScreenInfo()["screen_width"];
				this.curtain.style.pixelHeight = (getScreenInfo()["screen_height"] >= document.body.clientHeight) ? getScreenInfo()["screen_height"] : document.body.clientHeight ;
				this.stage.style.pixelWidth    = (wid > this.min_width) ? wid + 20 : this.min_width + 20;
				this.stage.style.pixelLeft     = ((getScreenInfo()["window_width"] - wid) > 0) ? Math.floor((getScreenInfo()["window_width"] - wid) / 2) : 0;
				this.stage.style.pixelTop      = getScreenInfo()["scroll_top"] + 30;
				this.p_copy.style.pixelWidth   = (wid > 381) ? wid - 129 : 252;
			}
			else{
				this.curtain.style.width  = getScreenInfo()["screen_width"]  + "px";
				this.curtain.style.height = (getScreenInfo()["screen_height"] >= window.innerHeight) ? getScreenInfo()["screen_height"] + "px" : window.innerHeight + "px" ;
				this.stage.style.width    = (wid > this.min_width) ? wid + 20 + "px" : this.min_width + 20 + "px";
				this.stage.style.left     = ((getScreenInfo()["window_width"] - wid) > 0) ? Math.floor((getScreenInfo()["window_width"] - wid) / 2) + "px" : "0px";
				this.stage.style.top      = getScreenInfo()["scroll_top"] + 30 + "px";
				this.p_copy.style.width   = (wid > 381) ? wid - 129 + "px" : "252px";
			}
		},
		
		Show : function(){
			
			var LB = this;
			
			document.body.className = (document.body.className.length > 0) ? document.body.className + " lightboxed" : "lightboxed" ;
			this.L_img.src = this.S_img.src.replace("_S","_L").untiCache();
			this.L_img.onload = function(){
				
				var LIMG = this;
				
				LB.p_image.appendChild(this);
				LB.SetStyle(this.width,this.height);
				
				var H = this.height;
				var a = 1 / 8;
				var p = 0;
				
				LB.timerID = setTimeout(function(){
					LB.img_print.src = LB.img_print_f2.src;
					
					p += (100 - p) * a;
					if(browser.nav == "MSIE"){
						LB.p_image.style.pixelHeight = H * p / 100;
					}
					else{
						LB.p_image.style.height = H * p / 100 + "px";
					}
					
					var ff = arguments.callee;
					if(p <= 99){
						setTimeout(function(){ ff() }, 10);
					}
					else{
						if(browser.nav == "MSIE"){
							LB.p_image.style.pixelHeight = H;
						}
						else{
							LB.p_image.style.height = H + "px";
						}
						
						LB.SetStyle(LIMG.width,LIMG.height);
						
						LB.img_print.onclick = function(){
							window.print();
						}
					}
					
				},1 * 1000);
				
				
			}
			
			this.L_img.onerror = function(){
				LB.SetStyle(LB.min_width,0);
				LB.img_print.src = LB.img_print_f3.src;
				LB.img_print.onclick = null;
				
				LB.timerID = setTimeout(function(){
					LB.Hide();
				},5 * 1000);
			}
			
			document.body.appendChild(this.curtain);
			document.body.appendChild(this.stage);
		},
		
		Hide : function(){
			
			document.body.className = document.body.className.replace("lightboxed","");
			clearTimeout(this.timerID);
			
			if(browser.nav == "MSIE"){
				this.p_image.style.pixelHeight = 0;
			}
			else{
				this.p_image.style.height = "0px";
			}
			this.img_print.src = this.img_print_f1.src;
			document.body.removeChild(this.curtain);
			document.body.removeChild(this.stage);
			
		}
		
	}
	
	function getScreenInfo(){
		
		var return_array = [];
		
		if(self.pageYOffset){
			return_array["scroll_left"] = self.pageXOffset;
			return_array["scroll_top"]  = self.pageYOffset;
		}
		else if(document.documentElement && document.documentElement.scrollTop){
			return_array["scroll_left"] = document.documentElement.scrollLeft;
			return_array["scroll_top"]  = document.documentElement.scrollTop;
		}
		else{
			return_array["scroll_left"] = document.body.scrollLeft;
			return_array["scroll_top"]  = document.body.scrollTop;
		}
		
		if(self.innerWidth){
			return_array["window_width"]  = self.innerWidth;
			return_array["window_height"] = self.innerHeight;
		}
		else if(document.documentElement && document.documentElement.clientWidth){
			return_array["window_width"]  = document.documentElement.clientWidth;
			return_array["window_height"] = document.documentElement.clientHeight;
		}
		else{
			return_array["window_width"]  = document.body.clientWidth;
			return_array["window_height"] = document.body.clientHeight;
		}
		
		if (window.innerHeight && window.scrollMaxY) {	
			return_array["screen_width"]  = document.body.scrollWidth;
			return_array["screen_height"] = window.innerHeight + window.scrollMaxY;
		}
		else if (document.body.scrollHeight > document.body.offsetHeight){
			return_array["screen_width"]  = document.body.scrollWidth;
			return_array["screen_height"] = document.body.scrollHeight;
		}
		else {
			return_array["screen_width"]  = document.body.offsetWidth;
			return_array["screen_height"] = document.body.offsetHeight;
		}
		
		return return_array;
	}
	
	
	// exec
	
	var LB_set = [];
	var tmp = getElementsByTagAndClassName("img",TOYOKOINN_lightbox_className);
	for(var i=0 ; i<tmp.length ; i++){
		LB_set[i] = new lightbox(tmp[i]);
	}
	
	
	
	
}
startup_items[startup_items.length] = LBox;




function ieBackgroundPrint(){
	
	if(browser.nav != "MSIE") return;
	if(browser.ver.major != 6) return;
	
	var col = [];
	var tmp = [];
	
	if(getElementsByTagAndClassName("div","main-contents")) col[col.length] = getElementsByTagAndClassName("div","main-contents")[0].getElementsByTagName("*");
	
	for(var i=0 ; i<col.length ; i++){
		for(var j=0 ; j<col[i].length ; j++){
			tmp[tmp.length] = col[i][j];
		}
	}
	
	var count = 0;
	
	
	
	(function(){
		
		var obj = tmp[count];
		if(
			obj && 
			obj.currentStyle.backgroundImage && 
			obj.currentStyle.backgroundImage != "none" && 
			obj.currentStyle.backgroundRepeat != "repeat" && 
			obj.currentStyle.width == "auto"
		){
			
			var oW = obj.offsetWidth;
			var pL = obj.currentStyle.paddingLeft.replace("px","").toString(10);
			var pR = obj.currentStyle.paddingRight.replace("px","").toString(10);
			obj.style.pixelWidth = oW - pL - pR;
			
			
		}
		
		var f = arguments.callee;
		
		if(count < tmp.length){
			count++;
			f();
		}
		else{
			TOYOKOINN_debugger.write("finish");
		}
	})();
	
}
startup_items[startup_items.length] = ieBackgroundPrint;












/*
common script lib. Ver.4.0.1
toyoko-inn.com custom
2008.03.18.
*/

