var Global = this;

function log (msg) {
	if (window.console) {
		console.log.apply(console, arguments);
	}
}

function d(args) {
	var out = [];
	for (var i = 0; i < arguments.length; i++) out.push(arguments[i]);
	if (navigator.userAgent.match(/Firefox/)) {
		dump(out.join(" ") + "\n");
	} else {
		// alert(out.join(" "));
	}
}

Object.prototype.p = function () {
	var t = Object.inspect(this);
	if (t == "[object Object]")
		t = $H(this).inspect().replace(/^#<Hash/, "#<Object");
	if (navigator.userAgent.match(/Firefox/)) {
		window.dump(t + "\n");
	} else {
		window.status = t;
	}
	return this;
}


DOMBuilder = function (name, attr, childs) {
	var ret = document.createElement(name);
	for (k in attr) {
		if (!attr.hasOwnProperty(k)) continue;
		v = attr[k];
		if (k == "class") {
			ret.className = v;
		} else {
			ret.setAttribute(k, v);
		}
	}
	if (typeof childs == "string") {
		ret.appendChild(document.createTextNode(childs));
	} else {
		(childs || []).each(function (child) {
			if (typeof child == "string") {
				ret.appendChild(document.createTextNode(child));
			} else {
				ret.appendChild(child);
			}
		});
	}
	return ret;
}

$N = DOMBuilder;

/*
 * DOM 定数の定義
 */
ELEMENT_NODE                   = 1;
ATTRIBUTE_NODE                 = 2;
TEXT_NODE                      = 3;
CDATA_SECTION_NODE             = 4;
ENTITY_REFERENCE_NODE          = 5;
ENTITY_NODE                    = 6;
PROCESSING_INSTRUCTION_NODE    = 7;
COMMENT_NODE                   = 8;
DOCUMENT_NODE                  = 9;
DOCUMENT_TYPE_NODE             = 10;
DOCUMENT_FRAGMENT_NODE         = 11;
NOTATION_NODE                  = 12;

Cookie = function () {
	var self = arguments.callee;
	if(self.instance == null){
		this.initialize.apply(this,arguments);
		self.instance = this;
	}
	return self.instance;
}
Cookie.prototype =  {
	initialize : function () {
		this.cookie = {};
		this.expires = null;
		var c = document.cookie.split(RegExp("\\s*;\\s*"));
		for (var i = 0; i < c.length; i++) {
			var t = c[i].split("=", 2);
			this.cookie[t[0]] = t[1];
		}
	},

	get : function (id) {
		return this.cookie[id.toString()] ? decodeURIComponent(this.cookie[id.toString()])
			: null;
	},

	set : function (id, val) {
		this.cookie[id.toString()] = encodeURIComponent(String(val));
		this.beEaten();
	},

	// id が指定されなければすべて削除
	del : function (id) {
		if (id) {
			this.cookie[id] = null;
			this.beEaten();
		} else {
			for (id in this.cookie)
				this.cookie[id] = null;
			this.beEaten();
		}
	},

	// ムシャムシャされる。
	beEaten : function () {
		for (id in this.cookie) {
			if (!this.cookie.hasOwnProperty(id)) continue;

			if (id && this.cookie[id]) {
				var v = [id, "=", this.cookie[id], ";"];
				if (this.expires)
					v.push("expires=", this.expires.toGMTString());
				document.cookie = v.join("");
			} else {
				var e = new Date();
				e.setMonth(e.getMonth() - 1);
				document.cookie = [id, "=;", "expires=", e.toGMTString()].join("");
			}
		}
		// d("setcookie:", document.cookie);
	} // ムシャムシャされた。食べてもらえるならなんでもよかった。
}

AccessibilityOption = {
	addListTitle : function () {
		var func = function (eles) {
			$A(eles).each(function (i) {
				var title = i.getAttribute("title");
				if (title && title != "") {
					var p = document.createElement("p");
					p.className = "js_AccessibilityOption-ListTitle";

					p.appendChild(document.createTextNode(title));

					i.parentNode.insertBefore(p, i);
					i.className = "js_AccessibilityOption-List";
				}
			});
		}
		func(document.getElementsByTagName("ul"));
		func(document.getElementsByTagName("ol"));
		func(document.getElementsByTagName("dl"));
	}
}


StyleSheetSelector = Class.create(); {
	StyleSheetSelector.prototype = {
		initialize : function () {
			var styles = document.styleSheets;
			if (!styles) return;
			this.choice = [];
			$A(styles).each((function (item) {
				if (item.type == "text/css" && item.title != "") {
					this.choice.push(item.title);
				}
			}).bind(this));

			this.prepare();
			this.area.style.left = 0;

			if (navigator.userAgent.match(/MSIE/)) {
				this.area.style.position = "absolute";
				this.area.style.bottom = "0";
				Event.observe(window, "scroll", (function (e) {
					this.setPos();
				}).bindAsEventListener(this));
			} else {
				this.area.style.position = "fixed";
				this.area.style.bottom = "0";
			}
		},

		select : function (title) {
			var styles = $A(document.styleSheets);
			switch (title) {
				case "No Styles": {
					styles.each(function (item) {
						if (item.type == "text/css") {
							item.disabled = true;
						}
					});
					break;
				}
				case "Basic Style": {
					styles.each(function (item) {
						if (item.type == "text/css") {
							item.disabled = (styles[i].title == "") ? false : true;
						}
					});
					break;
				}
				default : {
					styles.each(function (item) {
						if (item.type == "text/css") {
							item.disabled =
								(item.title == title || item.title == "") ? false : true;
						}
					});
					break;
				}
			}
		},

		/* private */
		prepare : function () {
			this.area = document.createElement("div");
			this.area.className = "style-sheet-selector";
			this.list = document.createElement("ol");

			var close = document.createElement("div");
			close.className = "style-sheet-selector-close";
			close.appendChild(document.createTextNode("s"));
			this.area.appendChild(close);

			var add = (function (name) {
				var li = document.createElement("li");
				li.appendChild(document.createTextNode(name));
				li.name = name;
				Event.observe(li, "click", this.onclick.bindAsEventListener(this));
				this.list.appendChild(li);
			}).bind(this);

			//add("No Styles");
			//add("Basic Style");

			this.choice.each((function (i) {
				add(i);
			}).bind(this));

			this.area.appendChild(this.list);
			Element.hide(this.list);

			document.body.appendChild(this.area);

			var timer;
			Event.observe(this.area, "mouseout", (function () {
				if (timer) clearTimeout(timer);
				timer = setTimeout((function () {
					Element.hide(this.list);
					this.setPos();
				}).bind(this), 300);
			}).bind(this));

			Event.observe(this.area, "mouseover", (function () {
				if (timer) clearTimeout(timer);
				timer = setTimeout((function () {
					Element.show(this.list);
					this.setPos();
				}).bind(this), 300);
			}).bind(this));
		},

		setPos : function () {
			if (!navigator.userAgent.match(/MSIE/)) return;
			
			Position.prepare();
			var bottom = Position.deltaY +
				(window.innerHeight || document.body.clientHeight) -
					this.area.offsetHeight;
			this.area.style.top = bottom + "px";
		},

		onclick : function (e) {
			this.select(Event.element(e).name);
		}
	}
}


overlaySearch = Class.create(); {
	overlaySearch.prototype = {
		initialize : function (form, input, option) {
			this.oform = $(form);
			this.oinput = $(input);
			this.option = option;
			this.oform.onsubmit = this.onsubmit.bindAsEventListener(this);

			this.prepare();

			new Form.Element.Observer(this.input, 1.5, this.start.bindAsEventListener(this));


			/*
			Ajax.Responders.register({
				onCreate : function () {
					Element.show(this.loading);
				},

				onComplete : function () {
					if(Ajax.activeRequestCount == 0){
						Element.hide(this.loading);
					}
				}
			});
			 */
		},

		/* nounai private */

		start : function () {
			this.loading.style.visibility = "visible";
			var ajaxReq = new Ajax.Request(this.oform.action, {
				method : "get",
				parameters : ["query=", encodeURIComponent(this.input.value), ";",
							  this.option.optParam].join(""),
				onComplete : this.update.bind(this),

				onFailure : (function (req) {
					this.loading.style.visibility = "hidden";
					var code = document.createElement("div");
					code.appendChild(document.createTextNode("Error: " + req.status));
					var content = document.createElement("div");
					content.appendChild(document.createTextNode(req.responseText));
					this.result.appendChild(code);
					this.result.appendChild(content);
				}).bind(this),

				onSuccess : (function (req) {
					this.loading.style.visibility = "hidden";
				}).bind(this),

				onException : (function (req, e) {
					var content = document.createElement("div");
					content.appendChild(document.createTextNode(e));
					this.result.appendChild(content);
				}).bind(this)
				});

		},

		update : function (req) {
			while (this.result.childNodes.length > 0)
				this.result.removeChild(this.result.firstChild);

			this.option.update.apply(this, [req, this.result]);
		},

		onsubmit : function (e) {
			this.overlay.style.display = "block";
			this.input.value = this.oinput.value;
			this.input.focus();
			this.start();
			Event.stop(e);
		},

		getWindowHeight : function () {
			// copy from lightbox plus (but codingrule)

			var ch, sh;
			if (window.innerHeight) {
				ch = window.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) {
				ch = document.documentElement.clientHeight;
			} else {
				ch = document.body.clientHeight;
			}

			if (window.innerHeight && window.scrollMaxY) {
				sh = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight) {
				sh = document.body.scrollHeight;
			} else {
				sh = document.body.offsetHeight;
			}

			return (ch > sh) ? ch : sh;
		},

		prepare : function () {
			// prepare overlay objects
			this.overlay = document.createElement("div");
			this.overlay.className = "overlay-search";
			with (this.overlay.style) {
				height = this.getWindowHeight() + "px";
				background = "url(/img/overlay.png)";
				display = "none";
				if (navigator.userAgent.match(/MSIE/)) {
					background = "#000";
					filter = "Alpha(opacity=80)";
				}
			}
			this.overlay.onclick = (function () {
				this.overlay.style.display = "none";
			}).bindAsEventListener(this);
			document.body.appendChild(this.overlay);

			var area = document.createElement("div");
			area.className = "overlay-search-area";

			//area.onclick = (function (e) {
			//	Event.stop(e);
			//}).bindAsEventListener(this);
			this.overlay.appendChild(area);

			var close = document.createElement("div");
			close.className = "overlay-search-close";
			close.onclick = (function (e) {
				this.overlay.style.display = "none";
			}).bindAsEventListener(this);
			close.appendChild(document.createTextNode("close"));

			area.appendChild(close);

			var fp = document.createElement("p");
			with (fp.style) {
				margin = "0";
			}
			area.appendChild(fp);

			this.input = document.createElement("input");
			this.input.type = "text";
			fp.appendChild(this.input);
			this.input.onclick = (function (e) {
				Event.stop(e);
			}).bindAsEventListener(this);

			this.loading = document.createElement("img");
			this.loading.src = "/img/circling-squares-with-trail.gif";
			this.loading.style.visibility = "hidden";
			area.appendChild(this.loading);

			this.result = document.createElement("div");
			with (this.result.style) {
				textAlign = "left";
			}
			area.appendChild(this.result);
		}
	}

}

FastComment = Class.create(); {
	FastComment.prototype = {
		initialize : function () {
			document.getElementsByClassName("post-comment").each((function (i) {
				Event.observe(i, "click", this.handler.bindAsEventListener(this));
				Event.observe(i, "keypress", this.handler.bindAsEventListener(this));
			}).bind(this));

			this.prepare();

			this.cookie = new Cookie();
		},

		handler : function (e) {
			var element = Event.element(e);
			element.parentNode.appendChild(this.floatingForm);
			this.floatingForm.action = element.href.replace(/#c$/, '');

			var name = this.cookie.get("name");
			this.name.value = name ? name : "Name";

			this.body.value = this.body._value;

			Element.show(this.floatingForm);

			Event.stop(e);
		},

		post : function (e) {
			Event.stop(e);
			Form.getElements(this.floatingForm).each((function (i) {
				i.style.visibility = "hidden";
			}).bind(this));
			this.floatingForm.style.background = "url('/img/circling-squares-with-trail.gif') no-repeat 50% 50%";

			var postData = [], invalid = false;
			["name", "body"].each((function (n) {
				if (!this[n].value || this[n]._value == this[n].value) {
					invalid = true;
					new Effect.Highlight(this[n], {startcolor:"#ff9999"});
					throw $break;
				}
				postData.push([this[n].name, encodeURIComponent(this[n].value)].join("="));
			}).bind(this));

			var show = (function () {
				this.floatingForm.style.background = "";
				Form.getElements(this.floatingForm).each((function (i) {
					i.style.visibility = "visible";
				}).bind(this));
			}).bind(this);

			if (invalid) {
				show();
			} else {
				//Ajax;
				var action = this.floatingForm.action.replace("http://"+location.host, "");

				this.cookie.set("name", this.name.value);

				postData.push("calcq=1&calc=1");
				new Ajax.Request(action + ".js", {
					method: "post",
					postBody: postData.join("&"),

					onSuccess : (function (req) {
						while (this.box.firstChild)
							this.box.removeChild(this.box.firstChild);

						var res = eval(req.responseText); // 二重 eval

						if (res.message) {
							this.box.appendChild(document.createTextNode(req.responseText));
						} else {
							this.box.appendChild(document.createTextNode("Posted!"));

							/* Show new Comment */
							var dt = $N("dt", {}, this.name.value);
							var dd = $N("dd");

							this.body.value.split(/\r?\n/).each((function (l) {
								dd.appendChild($N("span", {"class":"l"}, l));
							}).bind(this));


							var dlId = "c"+this.floatingForm.action.match(RegExp("\\d{4}/\\d\\d/\\d\\d/\\d+$"));
							dlId = dlId.replace(RegExp("/", "g"), "-");
							var dl = $(dlId);

							if (dl) {
								dl.appendChild(dt);
								dl.appendChild(dd);
							} else {
								this.floatingForm.parentNode.parentNode.appendChild(
									$N("dl", {id:dlId}, [dt, dd])
									);
							}
						}

						Element.show(this.box);
						setTimeout((function () {
							Element.hide(this.box);
							Element.hide(this.floatingForm);

							show();
						}).bind(this), 1000);
					}).bind(this),

					onFailure : (function (req) {
						while (this.box.firstChild)
							this.box.removeChild(this.box.firstChild);

						this.box.appendChild(document.createTextNode(req.status));
						Element.show(this.box);

						show();
						setTimeout((function () {
							Element.hide(this.box);
						}).bind(this), 3000);
					}).bind(this),

					onException : (function (req, e) {
						alert(e);
						while (this.box.firstChild)
							this.box.removeChild(this.box.firstChild);

						this.box.appendChild(document.createTextNode(e));
						Element.show(this.box);

						setTimeout((function () {
							Element.hide(this.box);
						}).bind(this), 3000);
					}).bind(this)

					});
			}


		},

		prepare : function () {
			var close;
			this.floatingForm = $N("form", {"class":"floating-form"}, [
				this.box = $N("div", {"class":"message"}),
				$N("p", {}, [
					this.name    = $N("input", {name:"name",type:"text", value:"Name", "class":"name"}),
					this.body    = $N("textarea", {name:"body","class":"body"}, "Your Comment!"),
					$N("p", {}, [
						this.submit  = $N("input", {type:"submit", value:"POST", "class":"button"}),
						" ",
						close = $N("a", {href:"javascript:void(0)"}, "Close")
						])
					])
				]);
			Element.hide(this.box);
			this.name._value = this.name.value;
			this.body._value = this.body.value;

			Event.observe(this.name, "focus", (function (e) {
				if (this.name.value == this.name._value) this.name.value = "";
			}).bindAsEventListener(this));
			Event.observe(this.name, "blur", (function (e) {
				if (this.name.value == "") this.name.value = this.name._value;
			}).bindAsEventListener(this));

			Event.observe(this.body, "focus", (function (e) {
				if (this.body.value == this.body._value) this.body.value = "";
			}).bindAsEventListener(this));
			Event.observe(this.body, "blur", (function (e) {
				if (this.body.value == "") this.body.value = this.body._value;
			}).bindAsEventListener(this));

			Event.observe(close, "click", (function (e) {
				Element.hide(this.floatingForm);
			}).bindAsEventListener(this));

			Event.observe(this.floatingForm, "submit", this.post.bindAsEventListener(this));
		}
	}
}

PickBabilon = Class.create(); {
	PickBabilon.prototype = {
		initialize: function () {
			this.prepare();
			this.load();
			Ajax.Responders.register({
				onCreate : function () {
					Element.show(this.loadInd);
				},

				onComplete : function () {
					if(Ajax.activeRequestCount == 0){
						Element.hide(this.loadInd);
					}
				}
			});
		},

		load : function () {
			var ajaxReq = new Ajax.Request("/test/tekito-.tsv", {
				method : "get",
				parameters : String(Math.random()),
				onComplete : (function (req) {
					this.update(req.responseText);
				}).bind(this),

				onFailure : (function (req) {
					//	alert(req);
				}).bind(this),

				onSuccess : (function (req) {
				}).bind(this),

				onException : (function (req, e) {
					alert(e)
					}).bind(this)
				});
		},

		post : function () {
			if (this.input.value == "") {
				this.load();
				return;
			}
			var ajaxReq = new Ajax.Request("/test/tekito.rb", {
				method : "post",
				parameters : ["message=", encodeURIComponent(this.input.value)].join(""),
				onComplete : (function (req) {
					this.input.value = "";
					this.update(req.responseText);
				}).bind(this),

				onFailure : (function (req) {
				}).bind(this),

				onSuccess : (function (req) {
				}).bind(this),

				onException : (function (req, e) {
				}).bind(this)
				});
		},

		update : function (text) {
			while (this.mesbox.firstChild) this.mesbox.removeChild(this.mesbox.firstChild);

			var lines = text.split(/\n/);
			lines.pop();
			lines = lines.findAll(function (i,index) { return index > lines.length - 6});
			lines.each((function (i, index) {
				var l = i.split(/\t/);
				var c = [l[0].match(/\d\d:\d\d:\d\d/), l[2], "-", l[1]].join(" ")
					this.mesbox.appendChild($N("li", {title:l[3]}, c));
			}).bind(this));
		},

		prepare : function () {

			this.area = $N("div", {"class":"chat-window"}, [
				this.content = $N("div", {"class":"content"}, [
					this.mesbox = $N("ol"),
					this.form = $N("form", {}, [
						this.input = $N("input", {type:"text"}),
						//$N("input", {type:"submit", value:"submit"}),
						this.loadInd = $N("img", {src:"/img/circling-squares-with-trail.gif"})
						])
					])
				]);
			Element.hide(this.loadInd);

			document.body.appendChild(this.area);
			with (this.area.style) {
				position = "fixed";
				bottom = "0";
				left   = "0";
				width  = "100%";
				fontSize = "80%";
			}
			if (navigator.userAgent.match(/MSIE/)) {
				this.area.style.position = "absolute";
				Event.observe(window, "scroll", (function (e) {
					var t = document.body.scrollTop + document.body.clientHeight - this.area.offsetHeight;
					this.area.style.top = t + "px";
					this.area.style.position = "absolute";
				}).bindAsEventListener(this));
			}

			with (this.content.style) {
				margin = "0 10%";
				background = "url('/img/overlay.png')";
				color = "#fff";
				border = "1px solid #000";
				padding = "1em";
			}

			with (this.mesbox.style) {
				listStyle = "none";
				padding = "0";
			}

			var processing = false;
			var isOver = false;
			Event.observe(document, "mousemove", (function (e) {
				if (processing) return;
				Position.prepare();
				var pointerX = Event.pointerY(e) - Position.deltaY;
				var height = window.innerHeight || document.body.clientHeight;
				if (pointerX > height * 0.90) {
					if (!Element.visible(this.area)) {
						Effect.BlindDown(this.area, {duration: 0.5});
						isOver = processing = true;
						setTimeout(function () {
							processing = false;
						}, 1000);
					}
				} else {
					if (Element.visible(this.area) && !isOver) {
						Effect.BlindUp(this.area, {duration: 0.5});
						processing = true;
						setTimeout(function () {
							processing = false;
						}, 1000);
					}
				}

			}).bindAsEventListener(this));

			Event.observe(this.area, "mouseover", (function (e) {
				isOver = true;
			}).bindAsEventListener(this));
			Event.observe(this.area, "mouseout", (function (e) {
				isOver = false;
			}).bindAsEventListener(this));

			Event.observe(this.form, "submit", (function (e) {
				Event.stop(e);
				this.post();
			}).bindAsEventListener(this));

		}
	}
}

function coloring() {
	if (navigator.userAgent.match(/MSIE/)) return;

	var pres = document.getElementsByTagName("pre");
	for (var i = 0, len = pres.length; i < len; i++) {
		if (pres[i].className.match(/^(cpp|css|diff|dtd|html|java|javascript|mysql|perl|php|python|ruby|sql|xml|ecmascript|sh)$/i)) {
			(function (pre) {
				var lang = pre.className.toLowerCase();
				if (lang == "ecmascript") lang = "javascript";
				if (lang == "sh") lang = "bash";
				var source = pre.firstChild.nodeValue;
				source = source.replace(/^\s+/, '').replace(/\s+$/, '');

				var ajaxReq = new Ajax.Request("/test/highlight/test.php", {
					method : "get",
					parameters : ["lang=", encodeURIComponent(lang), "&",
								  "source=", encodeURIComponent(source)].join(""),

					onComplete : (function (req) {
						var s = document.importNode(req.responseXML.documentElement, true).firstChild;
						s.appendChild($N("a", {href:"data:text/plain;charset=utf-8,"+encodeURIComponent(source)}, ">> [Original pre source]"));
						pre.parentNode.replaceChild(s, pre);

					}).bind(this),

					onFailure : (function (req) {
					//	alert(req);
					}).bind(this),

					onSuccess : (function (req) {
						//		alert(req);
					}).bind(this),

					onException : (function (req, e) {
						//alert(e);
					}).bind(this)
					});
			})(pres[i]);
			//break;
		}
	}
}


function SBSComments () {
	if (!location.href.match(RegExp('/blog/\\d{4}/\\d\\d/\\d\\d/\\d$'))) return;
	var d = document.getElementsByClassName('diary')[0];
	log(d);
	var comments, holder, info;
	var area = $N('div', {'class':'comments'}, [
		$N('h4', {}, 'Comments'),
		comments = $N('div', {} , [holder = $N('p', {}, 'Loading...')]),
		info = $N('div', {'class':'login-notice'}, [
			$N('p', {}, 'はてなブックマークのコメントを表示しています。'),
			$N('p', {}, [
				'コメントをつけたい場合、',
				$N('a',
					{ href:'http://b.hatena.ne.jp/add?mode=confirm&url='+encodeURIComponent(location.href) },
					'はてなブックマークでブックマーク'
				),
				'してください。'
			])
		])
	]);
	d.appendChild(area);

	var appendComment = function (d) {
		var n = $N('div', {'class':'comment'}, [
			$N('span', {'class':'icon'}, [
				$N('img', {src:d.icon, alt:''})
			]),
			$N('div', {'class':'c-content'}, [
				$N('div', {'class':'c-name'}, [
					$N('em', {}, d.name)
				]),
				$N('div', {'class':'c-body'}, [
					d.body
				]),
				$N('div', {'class':'c-info'}, [
					d.info
				])
			])
		]);
		comments.appendChild(n);
	}
	SBSComments.Hateb = function (data) {
		comments.removeChild(holder);
		if (!data) return;
		info.appendChild(
			$N('p', {}, [
				'ブクマ数:',
				data.count
			])
		);
		log(data);
		data.bookmarks.reverse().each(function (c) {
			if (!c.comment) return;
			appendComment({
				icon: [
					'http://www.hatena.ne.jp/users/',
					c.user.slice(0, 2),
					'/',
					c.user,
					'/profile_s.gif'
				].join(''),
				name: [$N('a', {href:'http://d.hatena.ne.jp/'+c.user}, 'id:'+c.user)],
				body: c.tags.length == 0 ? c.comment : '['+c.tags.join('][')+'] ' + c.comment,
				info: c.timestamp
			})
		});
	}

	// hatebu
	var url = 'http://b.hatena.ne.jp/entry/json/?callback=SBSComments.Hateb&url=' + encodeURIComponent(location.href),
	url = url.replace(/.lab.lowreal.net/, '');
	document.getElementsByTagName('head')[0].appendChild(
		$N('script', {
			type: 'text/javascript',
			src: url,
			charset: 'utf-8'
		})
	);
}


function initialize() {
	//	if (navigator.userAgent.match(/Gecko/))
	//	new PickBabilon();

	new StyleSheetSelector();

	//if (!navigator.userAgent.match(/Opera/))
	//	new FastComment();

	SBSComments();

	var a = new overlaySearch("navigation-search-form", "navigation-search-form-query", {
		optParam : "mode=xml",

		update : function (req, result) {
			if (!req.responseXML) return;
			var rd = req.responseXML.getElementsByTagName("resultdata");
			for (var i = 0; i < rd.length; i++) {
				var div = document.createElement("div");
				var subject = [
					(i + 1),
					". ",
					rd[i].getElementsByTagName("subject")[0].firstChild.nodeValue
					].join("");
				var uri = rd[i].getElementsByTagName("uri")[0].firstChild.nodeValue;
				var summary = rd[i].getElementsByTagName("summary")[0].firstChild.nodeValue;
				with (div) {
					className = "overlay-search-result";
					var a = document.createElement("a");
					a.href = uri;
					a.appendChild(document.createTextNode(subject));
					appendChild(a);
					var sume = document.createElement("div");
					sume.appendChild(document.createTextNode(summary));
					appendChild(sume);
				}
				result.appendChild(div);
			}
		}
	});


	AccessibilityOption.addListTitle();
	coloring();

}
Event.observe(window, "load", initialize, false);
