/* analytics */
$ (function () {
	if (!/p.yusukekamiyamane.com/.test (location) || /local/.test (location) || /__utmv=[0-9]+\.local/.test (document.cookie)) {
		$ ("<div id='local'>local</div>").appendTo ("body");
		pageTracker._setVar ("local");
	} else {
		pageTracker._setVar ("lang: " + document.getElementsByTagName ("html")[0].getAttribute ("lang"));
	}
});

/* search-box */
var SB = {};
SB.ajax = false;
SB.initialize = function () {
	SB.placeholder = $ ("html").attr ("lang") == "en" ? "Keyword search" : "キーワード検索";
	SB.block = $ ("div#content div.search-box");
	SB.form = $ ("div#content div.search-box form");
	SB.input = $ ("div#content div.search-box form input");
	SB.form.submit (function () {
		var keyword = SB.input.val ().replace (/\s/g, "+");
		var bool = !!keyword && !SB.input.hasClass ("placeholder");
		if (SB.ajax) {
			$.historyLoad (bool ? "keyword=" + keyword : "keyword=");
		} else {
			location.href = $ (this).attr ("action") + (bool ? "#keyword=" + keyword : "");
		}
		return false;
	});
	SB.input.focus (function () {
		SB.block.addClass ("focus");
		var keyword = $ (this).val ();
		if (!keyword || keyword == SB.placeholder) {
			$ (this).val ("").removeClass ("placeholder");
		}
	});
	SB.input.blur (function () {
		SB.block.removeClass ("focus");
		if (!$ (this).val ()) {
			$ (this).val (SB.placeholder).addClass ("placeholder");
		}
	});
	if (!SB.input.val ()) {
		SB.input.val (SB.placeholder).addClass ("placeholder");
	}
	$ ("div#content div.search-box form a").click (function () {
		if (SB.input.hasClass ("placeholder")) {
			SB.input.val ("");
		}
		SB.form.submit ();
		return false;
	});
	$ ("div#content div.search-box p a").click (function () {
		SB.input.val ($ (this).attr ("href").match (/keyword=(.*)/) [1]).removeClass ("placeholder");
		SB.form.submit ();
		return false;
	});
};
$ (function () {
	SB.initialize ();
});

/* rollover */
$ (function () {
	$ ("img.rollover").each (function () {
		$ ("<img />").attr ("src", this.src.replace (/\.([^.]+)$/, "-hover." + "$1")).appendTo ("body").hide ();
	});
	$ ("a:has(img.rollover)").hover (function () {
		$ ("img.rollover", this).each (function () {
			this.src = this.src.replace (/\.([^.]+)$/, "-hover." + "$1");
		});
	}, function () {
		$ ("img.rollover", this).each (function () {
			this.src = this.src.replace (/-hover\.([^.]+)$/, "." + "$1");
		});
	});
	$ ("input.rollover").each (function () {
		$ ("<img />").attr ("src", this.src.replace (/\.([^.]+)$/, "-hover." + "$1")).appendTo ("body").hide ();
		$ (this).hover (function () {
			this.src = this.src.replace (/\.([^.]+)$/, "-hover." + "$1");
		}, function () {
			this.src = this.src.replace (/-hover\.([^.]+)$/, "." + "$1");
		});
	});
	$ ("form").submit (function () {
		$ ("input.rollover").unbind ("mouseover").unbind ("mouseout");
	});
});

/* stylesheet */
$ (function () {
	if ($.browser.mozilla) {
		$ ("html:lang(ja)").attr ("lang", "");
	}
});