/* ---------- 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 == "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;









function MAP_SARI(){
	if(!getElementsByTagAndClassName("area","MAP_SARI")) return false;
	var obj = getElementsByTagAndClassName("img","MAP_SARI");
	var map = getElementsByTagAndClassName("area","MAP_SARI");
	for(var i = 0 ; i < map.length ; i++){
		var target = map[i];
		target.i = i;
		target.onmouseover = function(){ obj[this.i].src = obj[this.i].src.replace("_f1","_f2"); }
		target.onmouseout  = function(){ obj[this.i].src = obj[this.i].src.replace("_f2","_f1"); }
	}
}
startup_items[startup_items.length] = MAP_SARI;









