
Nm = {}; Nm.js = "Based on sML JavaScript Library, customized for www.n-keitai.com (late 2008)"; Nm.js.edition = "h/f";

//=========================================================================================================================

UA = {
	WK : ((navigator.userAgent.indexOf("AppleWebKit") > -1) ? 1 : 0),
	Ge : ((navigator.userAgent.indexOf("Gecko/") > -1)      ? 1 : 0),
	Op : ( window.opera                                     ? 1 : 0),
	IE : ((document.all && !this.Op)                        ? 1 : 0)
}

if(UA.WK) UA.WK = (navigator.userAgent.indexOf("AppleWebKit/5") > -1) ? 3 : ((navigator.userAgent.indexOf("AppleWebKit/4") > -1) ? 2 : 1);

//=========================================================================================================================

if(!Array.prototype.push) {
	Array.prototype.push = function() {
		for(var i = 0; i < arguments.length; i ++) this[this.length] = arguments[i];
		return this.length;
	}
}

if(!Array.prototype.forEach) {
	Array.prototype.forEach = function(F, pThis) {
		if(typeof F != "function") throw new TypeError();
		for(var i = 0; i < this.length; i++) if(i in this) F.call(pThis, this[i], i, this);
	}
}

foreach = function(O, F, pThis) {
	if(O.length) for(var i = 0; i < O.length; i ++) F(O[i], i, pThis);
	else         for(var i in O) F(O[i], i, pThis);
}

toArray = function() {
	var A = new Array;
	foreach(arguments, function(i) { foreach(i, function(j) { A.push(j); }); });
	return A;
}

//=========================================================================================================================

if(UA.IE && UA.IE < 9) {
	Nm.eOb = function(e) { this.target = e.srcElement; }
	Nm.ELM = function(a) {
		if(a) return function(Ev, F) { this.attachEvent("on" + Ev, function() { return F(new Nm.eOb(event)); }); }
		else  return function(Ev, F) { this.detachEvent("on" + Ev, F); }
	}
	window.addEventListener    = document.addEventListener    = Nm.ELM(1);
	window.removeEventListener = document.removeEventListener = Nm.ELM(0);
	try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
}

//=========================================================================================================================

Nm.onLoad = {
	eventListeners : new Array,
	executeAll : function() { for(var i = 0; i < this.eventListeners.length; i ++) this.eventListeners[i](); },
	addEventListener : function(F) { this.eventListeners.push(F); }
}

window.addEventListener("load", function() { Nm.onLoad.executeAll(); }, false);

//=========================================================================================================================

allElements = new Array;

getElementsByClassName = function(Cs) {
	var Es = new Array();
	var aEs = this.getElementsByTagName("*") || allElements;
	foreach(Cs.split(","), function(C) {
		foreach(aEs, function(E) {
			var cNs = E.className.split(" ");
			if(C.indexOf(" ") > -1) {
				var cNsStr = " " + cNs.sort().join(" ") + " ";
				var argStr = " " + C.split(" ").sort().join(" ") + " ";
				if(cNsStr.indexOf(argStr) > -1) Es.push(E);
			} else for(var i = 0; i < cNs.length; i ++) if(cNs[i] == C) { Es.push(E); break; }
		});
	});
	return Es;
}

document.getElementsByClassName = getElementsByClassName;

// ========================================================================================================================s

Nm.setButtonInteractions = function(Es, Ts) {
	if(!Es.length) return;
	var fR = function(I, I_src) { return function() { I.src = I_src; }; }
	var As = new Array;
	foreach(Es, function(E) { foreach(E.getElementsByTagName("a"), function(A) { As.push(A); }); });
	foreach(As, function(A) {
		try {
			var img = A.getElementsByTagName("img")[0];
			var h___src = new Image().src = img.src.replace(/(_link|_on|_in)?(\.png|\.gif|\.jpg)/, Ts[0] + "$2");
			A.onmouseover = fR(img, h___src);
			A.onmouseout  = fR(img, img.src);
		} catch(e) {}
	});
	if(Ts.length < 2) return;
	foreach(As, function(A) {
		try {
			var img = A.getElementsByTagName("img")[0];
			var a___src = new Image().src = img.src.replace(/(_link|_on|_in)?(\.png|\.gif|\.jpg)/, Ts[1] + "$2");
			A.onmousedown = fR(img, a___src);
			A.onmouseup   = fR(img, img.src);
			A.onkeydown   = fR(img, a___src);
			A.onkeyup     = fR(img, img.src);
		} catch(e) {}
	});
}

// ========================================================================================================================

Nm.setExternalLinks = function() {
	var As = document.getElementsByClassName("external");
	foreach(As, function(A) {
		A.onclick = A.onkeypress = function() {
			open(this.href);
			return false;
		}
	});
}

// ========================================================================================================================

Nm.setPageTopLinks = function() {
	var ULs = document.getElementsByClassName("toTop");
	foreach(ULs, function(UL) {
		var A = UL.getElementsByTagName("a")[0];
		A.onclick = A.onkeypress = function() {
			window.scrollTo(0, 0);
			return false;
		}
	});
}

// ========================================================================================================================

class_fp = function() {
	this.version = 0;
	if(navigator.plugins && navigator.mimeTypes.length) {
		var fPI = navigator.plugins["Shockwave Flash"];
		if(fPI && fPI.description) this.version = fPI.description.replace(/^[^\d]+(\d+\.\d+)\s*(r(\d+))*\.*$/, "$1.$3").split(".")[0];
	} else {
		var fAX = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
		if(fAX) this.version = fAX.GetVariable("$version").split(" ")[1].split(",")[0];
	}
	this.checkVersion = function(V) {
		if(this.version < V) return 0;
		else                 return 1;
	}
	this.getHTML = function(Ps) {
		return [
			"<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"",
			" width=\"" + Ps["width"] + "\"",
			" height=\"" + Ps["height"] + "\"",
			">",
			"<param name=\"movie\" value =\"" + Ps["movie"]   + "\">",
			"<param name=\"bgcolor\" value =\"" + Ps["bgcolor"] + "\">",
			"<param name=\"quality\" value =\"high\">\n",
			"<embed type=\"application/x-shockwave-flash\"",
			" src=\"" + Ps["movie"] + "\"",
			" width=\"" + Ps["width"] + "\"",
			" height=\"" + Ps["height"] + "\"",
			" bgcolor=\"" + Ps["bgcolor"] + "\"",
			" quality=\"high\"",
			" />",
			"</object>"
		].join("");
	}
	this.setFlash = function(ID, F, V, W, H, B) {
		if(this.checkVersion(V)) {
			var fA = document.getElementById(ID);
			if(!fA) return;
			var sF = function() {
				fA.innerHTML = Nm.fp.getHTML({
					"movie"   : F,
					"width"   : W,
					"height"  : H,
					"bgcolor" : B
				});
			};
			fA.innerHTML = "";
			var dT = UA.WK ? 100 : 10;
			setTimeout(sF, dT);
		}
	}
}

Nm.fp = new class_fp();

//=========================================================================================================================

Nm.onLoad.addEventListener(function() {
	Nm.setExternalLinks();
	Nm.setPageTopLinks();
	Nm.setButtonInteractions(document.getElementsByClassName("globalNav"), ["_hover"]);
});

Nm.setRollOver = function(C, T) { Nm.onLoad.addEventListener(function() { Nm.setButtonInteractions(document.getElementsByClassName(C), [T]); }); }

//=========================================================================================================================
