
sekaimon = {} // common.js : Based on sML JavaScript Library, customized for www.sekaimon.com (renewal 2008)

// ========================================================================================================================

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.replace(/.+AppleWebKit\/([\d]+).+/, "$1");
}

if(UA.IE) {
	     if(document.documentMode)                      UA.IE = parseInt(document.documentMode);
	else if(navigator.userAgent.indexOf("MSIE 7") > -1) UA.IE = 7;
	else if(navigator.userAgent.indexOf("MSIE 6") > -1) UA.IE = 6;
}

// ------------------------------------------------------------------------------------------------------------------------

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;
}

// ------------------------------------------------------------------------------------------------------------------------

sekaimon.onRead = {
	compatible : (((UA.WK > 525) || UA.Ge || UA.Op) ? 1 : 0),
	eventListeners : new Array,
	executeAll : function() { for(var i = 0; i < this.eventListeners.length; i ++) this.eventListeners[i](); },
	addEventListener : function(F) {
		if(this.compatible) document.addEventListener('DOMContentLoaded', F, false);
		else                this.eventListeners.push(F);
	}
}

if(UA.IE) sekaimon.onRead.IE = document.documentElement.addBehavior('res/js/common.onRead.IE.htc');

if(!sekaimon.onRead.compatible && !UA.IE) window.onload = function() { sekaimon.onRead.executeAll(); }

//========================================================================================================================

if(UA.IE) {
	sekaimon.eOb = function(e) { this.target = e.srcElement; }
	sekaimon.ELM = function(a) {
		if(a) return function(Ev, F) { this.attachEvent("on" + Ev, function() { return F(new sekaimon.eOb(event)); }); }
		else  return function(Ev, F) { this.detachEvent("on" + Ev, F); }
	}
	window.addEventListener    = document.addEventListener    = sekaimon.ELM(1);
	window.removeEventListener = document.removeEventListener = sekaimon.ELM(0);
	try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
}

//------------------------------------------------------------------------------------------------------------------------

allElements = new Array;

getElementsByClassName = function(Cs) {
	var Es = new Array();
	var aEs = this.getElementsByTagName("*") || allElements;
	Cs.split(",").forEach(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;
}

sekaimon.extendElements = function(O) {
	if(!allElements.length) allElements = toArray(document.getElementsByTagName("*"));
	var Es = O ? [O].concat(toArray(O.getElementsByTagName("*"))) : [window, document].concat(allElements);
	if(UA.Ge) Es.forEach(function(E) { if(E.tagName != "OBJECT" && E.tagName != "PARAM" && E.tagName != "EMBED") E.getElementsByClassName = getElementsByClassName; });
	else      Es.forEach(function(E) { E.getElementsByClassName = getElementsByClassName; });
	if(UA.IE) {
		Es.forEach(function(E) {
			if(!E.addEventListener) {
				E.addEventListener    = sekaimon.ELM(1);
				E.removeEventListener = sekaimon.ELM(0);
			}
		});
	}
}

//========================================================================================================================

sekaimon.setRollOver = function(C, Pf){
	var Es = document.getElementsByClassName(C);
	var fR = function(I, I_src){ return function(){ I.src = I_src; }; }
	Es.forEach(function(i) {
		var moImg_src = new Image().src = i.src.replace(/(\.png|\.gif|\.jpg)/, Pf + "$1");
		i.addEventListener("mouseover", fR(i, moImg_src), false);
		i.addEventListener("mouseout",  fR(i, i.src), false);
	});
}

sekaimon.setRollOver_forCatNav = function(Pf){
	if(!document.getElementById("category")) return;
	var catNav = document.getElementById("category");
	var LIs = catNav.getElementsByClassName("list")[0].getElementsByTagName("li");
	var fR = function(I, I_src){ return function(){ I.src = I_src; }; }
	for(var i = 0; i < LIs.length; i ++) {
		try {
			var A = LIs[i].getElementsByTagName("a")[0];
			var I = LIs[i].getElementsByTagName("img")[0];
			var moImg_src = new Image().src = I.src.replace(/(_white)?(\.png|\.gif|\.jpg)/, Pf + "$2");
			A.addEventListener("mouseover", fR(I, moImg_src), false);
			A.addEventListener("mouseout",  fR(I, I.src), false);
		} catch(e) {}
	}
}

//========================================================================================================================

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, V, F, W, H, B) {
		if(this.checkVersion(V)) {
			var fA = document.getElementById(ID);
			if(!fA) return;
			var sF = function() {
				fA.innerHTML = sekaimon.fp.getHTML({
					"movie"   : F,
					"width"   : W,
					"height"  : H,
					"bgcolor" : B
				});
			};
			fA.innerHTML = "";
			var dT = UA.WK ? 100 : 10;
			setTimeout(sF, dT);
		}
	}
	this.set = function() {
		if(arguments[0] == "sekaimon_ebay") {
			var eDiv = document.getElementById("eyecatch");
			eDiv.style.height = "270px";
			if(this.checkVersion(8)) {
				eDiv.innerHTML = [
					this.getHTML({
						"movie"   : "res/swf/sekaimon_ebay/sekaimon_ebay.swf",
						"width"   : 970,
						"height"  : 270,
						"bgcolor" : "#FFFFFF"
					})
				].join("");
			} else {
			}
		} else if(arguments[0] == "featured") {
			var fDiv = document.getElementById("featured");
			if(this.checkVersion(8)) {
				fDiv.innerHTML = [
					'<div id="featured_flash">',
					this.getHTML({
						"movie"   : "res/swf/featured/featured.swf",
						"width"   : 750,
						"height"  : 279,
						"bgcolor" : "#FFFFFF"
					}),
					'</div>'
				].join("");
			}
		} else if(arguments[0] == "beginners") {
			var gDiv = document.getElementById("beginnersGuide");
			if(this.checkVersion(8)) {
				gDiv.innerHTML = [
					'<div class="section" id="beginnersGuideMovie">',
					this.getHTML({
						"movie"   : "/images/guide/index.swf",
						"width"   : 570,
						"height"  : 350,
						"bgcolor" : "#FFFFFF"
					}),
					'</div>'
				].join("");
			}
		} else if(arguments[0] == "footer") {
			if(this.checkVersion(8)) {
				sekaimon.onRead.addEventListener(function() {
					var landmarks = document.createElement("div");
					landmarks.id = "landmarks";
					document.getElementById("footer-inner").appendChild(landmarks);
					sekaimon.fp.setFlash("landmarks", 8, "res/swf/footer/footer.swf", 970, 120, "#FFFFFF");
				});
			}
		}
	}
	this.stopFeatured = function() {
		try {
			document.getElementById("featured_flash").style.visibility = "hidden";
		} catch(e) {}
	}
	this.careFeatured = function() {
		try {
			document.getElementById("featured_flash").style.visibility = (document.getElementById("search_history_header").style.display == "block" || document.getElementById("category_selector_header").style.display == "block") ? "hidden" : "visible";
		} catch(e) {}
	}
}

sekaimon.fp = new class_fp();

//========================================================================================================================

sekaimon.fixKeywordMatchHeight = function() { try {
	var kWs = [
		document.getElementById("keywordMatch_eBay").getElementsByTagName("p")[1],
		document.getElementById("keywordMatch_PI").getElementsByTagName("p")[1],
		document.getElementById("keywordMatch_Hatena").getElementsByTagName("p")[1]
	];
	var __H = parseInt(kWs[0].offsetHeight);
	if(__H < parseInt(kWs[1].offsetHeight)) __H = parseInt(kWs[1].offsetHeight);
	if(__H < parseInt(kWs[2].offsetHeight)) __H = parseInt(kWs[2].offsetHeight);
	if(UA.IE && UA.IE < 7) kWs[0].style.height = kWs[1].style.height = kWs[2].style.height = (__H - 50) + "px";
	else                   kWs[0].style.minHeight = kWs[1].style.minHeight = kWs[2].style.minHeight = (__H - 50) + "px";
} catch(e) {} }

//========================================================================================================================

sekaimon.onRead.addEventListener(function() {

	sekaimon.extendElements();

	sekaimon.setRollOver("touch", "_on");
	sekaimon.setRollOver_forCatNav("_yellow");

	try {
		if(sekaimon.searchBar != undefined) {
			sekaimon.searchBar.params = {
				Is : [document.getElementById("search_keyword_header"), document.getElementById("search_keyword_footer")],
				Bs : document.getElementsByClassName("searchBt"),
				Fs : [document.searchFormHeader, document.searchFormFooter],
				fQ : "日本語でも英語でも検索できます",
				Cs : ["#AAAAAA", "#323232"],
				rd : [0, 0],
				fIf : function(I, i) {
					return function() {
						if(sekaimon.searchBar.params.rd[i]) {
							I.onfocus = function() {};
							return;
						} else if(I.value == sekaimon.searchBar.params.fQ) {
							I.style.color = sekaimon.searchBar.params.Cs[1];
							I.value = "";
							sekaimon.searchBar.params.rd[i] = 1;
						}
					}
				},
				fIb : function(I, i) {
					return function() {
						if(I.value == "") {
							I.style.color = sekaimon.searchBar.params.Cs[0];
							I.value = sekaimon.searchBar.params.fQ;
							sekaimon.searchBar.params.rd[i] = 0;
						} else if(I.value != sekaimon.searchBar.params.fQ) {
							I.style.color = sekaimon.searchBar.params.Cs[1];
							sekaimon.searchBar.params.rd[i] = 1;
						}
					}
				},
				fBc : function(I, i) {
					return function() {
						if(I.value == sekaimon.searchBar.params.fQ) I.value = "";
						searchMoveStart(sekaimon.searchBar.params.Fs[i], "srch");
						return false;
					}
				}
			};
			for(var i = 0; i < 2; i++) {
				var I = sekaimon.searchBar.params.Is[i];
				var B = sekaimon.searchBar.params.Bs[i];
				if(I.value == "" || I.value == sekaimon.searchBar.params.fQ) I.style.color = sekaimon.searchBar.params.Cs[0];
				if(I.value == "")                                            I.value = sekaimon.searchBar.params.fQ;
				I.onfocus = sekaimon.searchBar.params.fIf(I, i);
				I.onblur  = sekaimon.searchBar.params.fIb(I, i);
				B.onclick = sekaimon.searchBar.params.fBc(I, i);
			}
		}
	} catch(e) {}

	sekaimon.fixKeywordMatchHeight();

	try {
		var mW = document.getElementsByClassName("mypageWidgets")[0];
		var RE = mW.getElementsByTagName("li")[4];
		RE.className = "regist_edit";
		RE.getElementsByClassName("titleArea")[0].style.backgroundImage = "url(res/images/common/bg01.gif)";
		mW.getElementsByClassName("btn").forEach(function(B) { B.style.display = "none"; });
	} catch(e) {}

	try {
		var ROWs = document.getElementsByClassName("itemTable")[0].getElementsByClassName("row");
		ROWs[ROWs.length - 1].className = "row last";
	} catch(e) {}

});

//========================================================================================================================