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



var SARI_safemode        = 1;

var SARI_safemode_array  = ["img","input"];

var SARI_className       = "SARI";

var mailto_className     = "mailto";

var lightbox_className   = "LB";



/*

SARI_safemode:

1 : searching for nodes with "SARI_className" from the nodes that have tag name in "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=\"_css/WinIE.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=\"_css/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;

}



















/* ---------- 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 "mailto_className" as class attribute.

	*/

	var tmp = getElementsByTagAndClassName("span",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 "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(){

			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(SARI_safemode == 0){

		var tmp = getElementsByTagAndClassName("*",SARI_className);

	}

	// normal mode

	else{

		var tmp = [];

		for(var sm=0 ; sm<SARI_safemode_array.length ; sm++){

			var tmp_safe = getElementsByTagAndClassName(SARI_safemode_array[sm],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 = "/common/_img/_lig_foo_but_01_lod.gif";

		this.img_print_f2 = document.createElement("img");

		this.img_print_f2.src = "/common/_img/_lig_foo_but_01.gif";

		this.img_print_f3 = document.createElement("img");

		this.img_print_f3.src = "/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 = "/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 = "/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",lightbox_className);

	for(var i=0 ; i<tmp.length ; i++){

		LB_set[i] = new lightbox(tmp[i]);

	}

	

	

	

	

}

startup_items[startup_items.length] = LBox;

























/*

common script lib. Ver.4.0.1

company.jr-central.co.jp custom

2008.01.24.

*/


