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

var CJRC_src2name_re          = new RegExp("_f[12]","g");
var CJRC_image_directory_name = "_img/index.html";
var CJRC_swap                 = [];
var CJRC_rest                 = [];
var CJRC_SARI_className       = "SARI";
var CJRC_SARI_safemode        = 1;
var CJRC_SARI_safemode_array  = new Array("img","input");
var CJRC_mailto_className     = "mailto";
var CJRC_lightbox_className   = "LB";

/*
CJRC_SARI_safemode:
1 : searching for nodes with "CJRC_SARI_className" from the nodes that have tag name in "CJRC_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 ----------
the item in the Array "startup_items" will be executed in order as a function, when the document is loaded.
when you want to add an attribute "onload" in body tag (and that sucks), you'd better make it a function and push into the Array "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/new_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 == "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\">");
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/common/_css/new_print.css\" media=\"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 getImageName(obj){
	/*
	this returns a character sequence which deleted the one for rollover effect from the sauce file name.
	this returns false, if "obj" doesn't have a property "src".
	*/
	if(!obj.src) return false;
	return obj.src.split(CJRC_image_directory_name)[1].split(CJRC_src2name_re)[0];
}




function SwapAndRestoreImage(obj){
	/*
	when you want to use the rollover effect in any JavaScript, You'd better use this function.
	you can use any node as the argument.
	if the node is not "IMG" or "INPUT type=image", the 1st Image object of children is recognized as an object of the effect.
	if the sauce file name of an Image object is not a regular form or there is no Image object in children of the node, this will not be executed.
	although you can use this as the onmouseover or onmouseout attribute, i don't reccomend you it.
	*/
	var target;
	if(obj.nodeName == "IMG" || (obj.nodeName == "INPUT" && obj.type == "image")){
		target = obj;
	}
	else{
		if(!obj.getElementsByTagName("img")[0]) return;
		target = obj.getElementsByTagName("img")[0];
	}
	
	if(target.src.indexOf("_f1") == -1 && target.src.indexOf("_f2") == -1) return;
	
	// preload sequence
	var ImageName = getImageName(target);
	CJRC_swap[ImageName] = document.createElement("img");
	CJRC_swap[ImageName].src = target.src.replace(CJRC_src2name_re,"_f2");
	CJRC_rest[ImageName] = document.createElement("img");
	CJRC_rest[ImageName].src = target.src;
	
	// rollover sequence
	target.onmouseover = function(){ if(CJRC_swap[getImageName(this)]) this.src = CJRC_swap[getImageName(this)].src; }
	target.onmouseout  = function(){ if(CJRC_rest[getImageName(this)]) this.src = CJRC_rest[getImageName(this)].src; }
}


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 getPathString(str){
	/*
	this pulls out the PATH part from URL and returns it. 
	*/
	var tmp1 = str.split("index.html");
	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);
}










/* ---------- 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 "CJRC_mailto_className" as class attribute.
	*/
	var tmp = getElementsByTagAndClassName("span",CJRC_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 "CJRC_SARI_className" as the class attribute of the corresponding element.
	you have nothing to do to preload swap images :-)
	*/
	// expensive mode
	if(CJRC_SARI_safemode == 0){
		var tmp = getElementsByTagAndClassName("*",CJRC_SARI_className);
	}
	// normal mode
	else{
		var tmp = [];
		for(var sm=0 ; sm<CJRC_SARI_safemode_array.length ; sm++){
			var tmp_safe = getElementsByTagAndClassName(CJRC_SARI_safemode_array[sm],CJRC_SARI_className);
			if(tmp_safe != false) tmp = tmp.concat(tmp_safe);
		}
	}
	
	for(var i=0 ; i<tmp.length ; i++){
		SwapAndRestoreImage(tmp[i]);
	}
}
startup_items[startup_items.length] = SARI;










/* ---------- global navigation ---------- */

function globalNavi(){
	
	/*
	this is a controller of Global Navigation.
	*/
	
	var switch_pattern = [
		[(window.location.href.split("index.html")[2].split(".")[0].toLowerCase().indexOf("railway") != -1)],
		[
			(window.location.href.split("index.html")[2].split(".")[0].toLowerCase().indexOf("railway") != -1),
			(window.location.href.split("index.html")[3].indexOf("timetable") != -1)
		],
		[
			(window.location.href.split("index.html")[2].split(".")[0].toLowerCase().indexOf("railway") != -1),
			(window.location.href.split("index.html")[3].indexOf("tickets") != -1)
		],
		[(window.location.href.split("index.html")[2].split(".")[0].toLowerCase().indexOf("recommend") != -1)],
		[(window.location.href.split("index.html")[2].split(".")[0].toLowerCase().indexOf("expy") != -1)],
		[
			(window.location.href.split("index.html")[2].split(".")[0].toLowerCase().indexOf("railway") != -1),
			(window.location.href.split("index.html")[3].indexOf("group") != -1)
		],
		[(window.location.href.split("index.html")[2].split(".")[0].toLowerCase().indexOf("company") != -1)],
		[(window.location.href.split("index.html")[2].split(".")[0].toLowerCase().indexOf("faq") != -1)]
	];
	
	
	if(!document.getElementById("navi")) return;
	var tmp = document.getElementById("navi").getElementsByTagName("ul")[0].getElementsByTagName("img");
	for(var i=0 ; i<tmp.length ; i++){
		if(switch_pattern[i] == null) continue;
		
		var flag = true;
		for(var j=0 ; j<switch_pattern[i].length ; j++){
			if(!switch_pattern[i][j]){
				flag = false;
				break;
			}
		}
		
		if(flag == true){
			tmp[i].src = tmp[i].src.replace("_f1","_f2");
			tmp[i].className = "";
			tmp[i].onmouseover = null;
			tmp[i].onmouseout  = null;
		}
	}
}
startup_items[startup_items.length] = globalNavi;











/* ---------- sub navigation ---------- */

function subNavi(switch_pattern){
	
	/*
	this is a controller of Sub Navigation.
	*/
	
	if(!document.getElementById("sub-navi")) return;
	var tmp = document.getElementById("sub-navi").getElementsByTagName("ul")[0].childNodes;
	var C = [];
	
	function couple(obj){
		this.obj = obj;
		this.grandma = this.obj;
		this.grandma_a = this.obj.getElementsByTagName("a")[0];
		this.grandma_img = this.obj.getElementsByTagName("img")[0];
		this.mother = this.obj.getElementsByTagName("ul")[0];
		this.children = this.mother.getElementsByTagName("li");
		this.stat = "hidden";
	}
	couple.prototype = {
		Show : function(){
			this.grandma_img.src = this.grandma_img.src.replace("_f1","_f2");
			this.grandma_img.onmouseover = null;
			this.grandma_img.onmouseout  = null;
			this.mother.style.display = "block";
			this.stat = "show";
			
			for(var i=0 ; i<this.children.length ; i++){
				
				var wp = getPathString(window.location.href);
				var tp = getPathString(this.children[i].getElementsByTagName("a")[0].href);
				
				if(wp.indexOf(tp) != -1){
					this.children[i].className += (this.children[i].className.length == 0) ? "current" : " current" ;
				}
				
			}
		}
	}
	
	for(var i=0 ; i<tmp.length ; i++){
		if(tmp[i].nodeType == 1 && tmp[i].nodeName == "LI"){
			var n = C.length;
			C[n] = new couple(tmp[i]);
		}
	}
	
	for(var i=0 ; i<C.length ; i++){
		
		var flag = false;
		
		var wp = getPathString(window.location.href);
		var tp = getPathString(C[i].grandma_a.href);
		
		if(wp.indexOf(tp) != -1){
			flag = true;
		}
		else if(switch_pattern[i] != null){
			for(var j=0 ; j<switch_pattern[i].length ; j++){
				if(switch_pattern[i][j] === true){
					flag = true;
					break;
				}
			}
		}
		
		
		
		if(flag == true){
			C[i].Show();
			
			
		}
	}
	
	
	
}











/* ---------- contents navigation ---------- */

function contentsNavi(){
	
	/*
	this is a controller of Contents Navigation.
	*/
	
	if(!getElementsByTagAndClassName("div","contents-navi")) return;
	
	function cNavi(obj){
		
		this.obj = obj;
		this.articles = obj.getElementsByTagName("li");
		
		this.resize();
	}
	cNavi.prototype = {
		
		resize : function(){
			
			if(browser.nav != "MSIE") return;
			
			var t1 = this.articles[0].offsetTop;
			var t2 = this.articles[this.articles.length -1].offsetTop;
			var h = this.articles[0].clientHeight;
			
			this.obj.style.pixelHeight = h + 4 + (t2 - t1);
		},
		
		init : function(){
			
			for(var i=0 ; i<this.articles.length ; i++){
				var a = this.articles[i].getElementsByTagName("a")[0];
				
				var wp = getPathString(window.location.href).replace("index-2.html","");
				var tp = getPathString(a.href).replace("index-2.html","");
				
				if(wp == tp){
					a.className += (a.className.length == 0) ? "current" : " current" ;
				}
			}
			
			
		}
		
	}
	
	var tmp = getElementsByTagAndClassName("div","contents-navi");
	var CN = [];
	for(var i=0 ; i<tmp.length ; i++){
		CN[i] = new cNavi(tmp[i]);
		CN[i].init();
	}
	
	
	
	
}
startup_items[startup_items.length] = contentsNavi;











/* ---------- font size controll ---------- */

function fontSizeControll(){
	
	/*
	this is a controller of Font Size Utility.
	*/
	
	function button_preload(){
		var obj = document.getElementById("fontsize").getElementsByTagName("img");
		switch(get_cookie("fontsize")){
			case "small":
				obj[1].src = obj[1].src.replace("_f1","_f2");
				break;
				
			case "large":
				obj[3].src = obj[3].src.replace("_f1","_f2");
				break;
				
			default:
				obj[2].src = obj[2].src.replace("_f1","_f2");
				break;
		}
		
		obj[1].onclick = function(){
			buttonRollover(this);
			size_change(0);
		}
		obj[2].onclick = function(){
			buttonRollover(this);
			size_change(1);
		}
		obj[3].onclick = function(){
			buttonRollover(this);
			size_change(2);
		}
		
		
		function buttonRollover(tmp){
			for(var i = 1 ; i < 4 ; i++){
				obj[i].src = obj[i].src.replace("_f2","_f1");
			}
			tmp.src = tmp.src.replace("_f1","_f2");
		}
	}
	button_preload();
	
	var fontsize;
	days = 1;
	
	function size_change(n){
		
		var size = [];
		size[0] = "small";
		size[1] = "";
		size[2] = "large";
		
		
		if(n == 0){
			fontsize = "small";
			set_cookie("fontsize",fontsize);
		}
		else if(n == 1){
			fontsize = "middle";
			set_cookie("fontsize",fontsize);
		}
		else if(n == 2){
			fontsize = "large";
			set_cookie("fontsize",fontsize);
		}
		
		document.body.className = size[n];
	}
	
	
	function get_cookie(cn) {
		get_data = document.cookie;
		cv = [];
		gd = get_data.split(";");
		for (i in gd) {
			a = gd[i].split("=");
			a[0] = a[0].replace(" ","");
			cv[a[0]] = a[1];
		}
		if (cv[cn]) return cv[cn];
		else return "";
	}
	
	
	function set_cookie(cn,val) {
		ex = new Date();
		ex = new Date(ex.getTime() + (1000 * 60 * 60 * 24 * days));
		y = ex.getYear(); if (y < 1900) y += 1900;
		hms = ex.getHours() + ":" + ex.getMinutes() + ":" + ex.getSeconds();
		p = String(ex).split(" ");
		ex = p[0] + ", " + p[2] + "-" + p[1] + "-" + y + " " + hms + " GMT;";
		document.cookie = cn + "=" + val +"; path=/; expires=" + ex;
	}
	
	
	function set(){
		var get_data = get_cookie("fontsize");
		if(get_data != ""){
			if(get_data == "small"){
				size_change(0);
			}
			else if(get_data == "middle"){
				size_change(1);
			}
			else if(get_data == "large"){
				size_change(2);
			}
		}
	}
	set();
}
//startup_items[startup_items.length] = fontSizeControll;











/* ---------- service info ---------- */

function serviceInfo(){
	
	/*
	this is a controller of Service Info.
	*/
	
	var SI = this;
	
	// icon and text CLASS
	function Couple(obj,labelsrc){
		
		this.obj = obj;
		this.label = obj.getElementsByTagName("img")[0];
		this.area  = getNextElement(obj);
		this.labelsrc = labelsrc;
		this.label_img = [];
		for(var i=0 ; i<this.labelsrc.length ; i++){
			this.label_img[i] = new Image();
			this.label_img[i].src = this.labelsrc[i];
		}
		this.label_def = this.label.src;
		this.comment_def = this.area.childNodes[0];
		
	}
	Couple.prototype = {
		
		Show : function(stat,str){
			
			this.label.src = (this.label_img[stat]) ? this.label_img[stat].src : this.label_def ;
			if(str){
				clearChildNodes(this.area);
				this.area.appendChild(document.createTextNode(str));
			}
		},
		
		Hide : function(){
			this.label.src = this.label_def;
			clearChildNodes(this.area);
			this.area.appendChild(this.comment_def);
		}
	}
	
	// whole object CLASS
	function Obj(obj,labelsrc){
		
		this.obj = obj;
		this.shinkansen = new Couple(obj.getElementsByTagName("dt")[0],labelsrc.shinkansen);
		this.zairaisen  = new Couple(obj.getElementsByTagName("dt")[1],labelsrc.zairaisen);
		
	}
	
	// main CLASS
	function Main(url,obj,labelsrc,styleString){
		
		this.data = {};
		this.XHR = createXMLHttpRequest();
		this.url = url;
		this.obj = new Obj(obj,labelsrc);
		this.styleString = styleString;
		
	}
	Main.prototype = {
		update : function(){
			
			// reload XML file
			var M = this;
			this.XHR.open("http://nara.jr-central.co.jp/GET",this.url.untiCache(),true);
			this.XHR.send("null");
			
			this.XHR.onreadystatechange = function(){
				if(M.XHR.readyState == 4 && M.XHR.status == 200){
					
					// parse XML data
					M.data = {};
					var xml = M.XHR.responseXML;
					
					if(xml.getElementsByTagName("zairaisen")){
						M.data.zairaisen = {};
						var zairaisen = xml.getElementsByTagName("zairaisen")[0];
						
						if(
							zairaisen.getElementsByTagName("flag") && 
							zairaisen.getElementsByTagName("flag").length > 0 && 
							zairaisen.getElementsByTagName("flag")[0].childNodes.length > 0
						){
							M.data.zairaisen.flag = zairaisen.getElementsByTagName("flag")[0].childNodes[0].nodeValue;
						}
						
						if(
							zairaisen.getElementsByTagName("comment") && 
							zairaisen.getElementsByTagName("comment").length > 0 && 
							zairaisen.getElementsByTagName("comment")[0].childNodes.length > 0
						){
							M.data.zairaisen.comment = zairaisen.getElementsByTagName("comment")[0].childNodes[0].nodeValue;
						}
					}
					
					if(xml.getElementsByTagName("shinkansen")){
						M.data.shinkansen = {};
						var shinkansen = xml.getElementsByTagName("shinkansen")[0];
						
						if(
							shinkansen.getElementsByTagName("flag") && 
							shinkansen.getElementsByTagName("flag").length > 0 && 
							shinkansen.getElementsByTagName("flag")[0].childNodes.length > 0
						){
							M.data.shinkansen.flag = shinkansen.getElementsByTagName("flag")[0].childNodes[0].nodeValue;
						}
						
						if(
							shinkansen.getElementsByTagName("comment") && 
							shinkansen.getElementsByTagName("comment").length > 0 && 
							shinkansen.getElementsByTagName("comment")[0].childNodes.length > 0
						){
							M.data.shinkansen.comment = shinkansen.getElementsByTagName("comment")[0].childNodes[0].nodeValue;
						}
					}
					
					// refresh icon and text
					if(M.data != {}){
						
						if(
							!M.data.zairaisen || 
							M.data.zairaisen.flag == undefined || 
							!M.data.zairaisen.comment || 
							M.data.zairaisen.comment == undefined
						){
							M.obj.zairaisen.Hide();
						}
						else{
							M.obj.zairaisen.Show(M.data.zairaisen.flag,M.data.zairaisen.comment);
							
							
							if(
								!M.data.shinkansen || 
								M.data.shinkansen.flag == undefined || 
								!M.data.shinkansen.comment || 
								M.data.shinkansen.comment == undefined
							){
								M.obj.shinkansen.obj.style.display = "none";
								M.obj.shinkansen.area.style.display = "none";
								M.obj.zairaisen.area.style.width = M.styleString[1].width;
								M.obj.obj.style.backgroundImage = M.styleString[1].bg;
							}
							else{
								M.obj.shinkansen.obj.style.display = "block";
								M.obj.shinkansen.area.style.display = "block";
								M.obj.zairaisen.area.style.width = M.styleString[0].width;
								M.obj.obj.style.backgroundImage = M.styleString[0].bg;
								M.obj.shinkansen.Show(M.data.shinkansen.flag,M.data.shinkansen.comment);
							}
						}
					}
				}
			}
		}
	}
	
	
	
	// static vars
	this.span = 15;
	this.file = "http://nara.jr-central.co.jp/service-info/_xml/service.xml";
	this.labelsrc = {
		shinkansen : [
			"/common/_img/_sep_cap_01_00.gif",
			"http://nara.jr-central.co.jp/common/_img/_sep_cap_01_01.gif"
		],
		zairaisen : [
			"/common/_img/_sep_cap_02_00.gif",
			"http://nara.jr-central.co.jp/common/_img/_sep_cap_02_01.gif"
		]
	}
	this.styleString = [
		{
			width : "236px",
			bg    : "url(/common/_img/_sep_bg_01.jpg)"
		},
		{
			width : "549px",
			bg    : "url(/common/_img/_sep_bg_02.jpg)"
		}
	]
	
	
	
	// exec
	if(!document.getElementById("sep")){
		// do nothing
	}
	else{
		this.main = new Main(this.file,document.getElementById("sep"),this.labelsrc,this.styleString);
		(function(){
			
			SI.main.update();
			
			var f = arguments.callee;
			setTimeout(function(){ f(); },SI.span * 1000)
			
		})()
	}
	
	
}
startup_items[startup_items.length] = serviceInfo;











/* ---------- 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){
		
		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 = "http://nara.jr-central.co.jp/common/_img/_lig_foo_but_01_lod.gif";
		this.img_print_f2 = document.createElement("img");
		this.img_print_f2.src = "http://nara.jr-central.co.jp/common/_img/_lig_foo_but_01.gif";
		this.img_print_f3 = document.createElement("img");
		this.img_print_f3.src = "http://nara.jr-central.co.jp/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 = "http://nara.jr-central.co.jp/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 = "http://nara.jr-central.co.jp/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.src);
		}
		
		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(src){
			
			var LB = this;
			
			document.body.className = (document.body.className.length > 0) ? document.body.className + " lightboxed" : "lightboxed" ;
			this.L_img.src = src.replace("_S.","_L.").untiCache();
			this.L_img.onload = function(){
				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.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",CJRC_lightbox_className);
	for(var i=0 ; i<tmp.length ; i++){
		LB_set[i] = new lightbox(tmp[i]);
	}
	
	
	
	
}
startup_items[startup_items.length] = LBox;
