document.write ("<script type='text/javascript' src='/shared/qualityland/script/swfobject.js'></script>");

/* [navigation] ------------------------------------------------------------ */
$ (function () {
	$ ("div#global-navigation ul li a img[alt='" + $.trim ($ ("div#topic-path ul li:eq(1)").text ()) + "']").each (function () {
		this.src = this.src.replace (/\.([^.]+)$/, "_hover." + "$1");
	}).removeClass ("hover");
	adjustLocalNavigation = function () {
		$ ("div#local-navigation > ul > li:has(a img[alt='" + $.trim ($ ("div#topic-path ul li:eq(2)").text ()) + "'])").addClass ("selected").children ("ul").wrap ("<div id='sub-local-navigation'><div></div></div>");
		$ ("div#sub-local-navigation ul li:has(a img[alt='" + $.trim ($ ("div#topic-path ul li:eq(3)").text ()) + "'])").addClass ("selected");
		$ ("div#local-navigation:has(div#sub-local-navigation)").height ($ ("div#local-navigation").height () + $ ("div#sub-local-navigation").height () + 4);
		$ ("div#topic-path ul li a").after ("&nbsp;/&nbsp;");
	};
	if ($.browser.safari) {
		$ (window).load (function () {
			adjustLocalNavigation ();
		});
	} else {
		adjustLocalNavigation ();
		if ($.browser.msie && $.browser.version < 7) {
			$ ("div#sub-local-navigation").height ();
		}
	}
});

/* [stylesheet] ------------------------------------------------------------ */
$.fn.extend ({
	addPseudoClass: function (className) {
		var __className = className;
		this.each (function () {
			$ (this).addClass (__className);
			if ($.browser.msie && $.browser.version < 7) {
				var array = $.map ($ (this).attr ("class").split (" "), function (value) {
					return value && !/-child|after-/.test (value) ? value + "-" + __className : null;
				});
				$ (this).addClass (array.join (" "));
			}
		});
		return this;
	}
});
$ (function () {
	if ($.browser.msie) {
		$ ("div#content :last-child").addPseudoClass ("last-child");
		if ($.browser.version < 7) {
			$ ("div#content :first-child").addPseudoClass ("first-child");
			$ ("div#local-navigation + div#content > :nth-child(1), div#local-navigation + div#content > div.grid:nth-child(1) > div.column > :first-child").addPseudoClass ("after-local-navigation");
			$ ("div#title + div#content > :nth-child(1), div#title + div#content > div.grid:nth-child(1) > div.column > :first-child").addPseudoClass ("after-title");
			$.each (["anchor", "box", "navigation", "relation", "visual"], function () {
				$ ("div#content div." + this + " + *, div#content div." + this + " + div.grid > div.column > :first-child").addPseudoClass ("after-" + this);
			});
			$ ("div#content h3 + *, div#content h3 + div.grid > div.column > :first-child").addPseudoClass ("after-heading");
			$ ("div#content h4 + *, div#content h4 + div.grid > div.column > :first-child").addPseudoClass ("after-sub-heading");
			$ ("div#content h5 + *, div#content h5 + div.grid > div.column > :first-child, div#content h6 + *, div#content h6 + div.grid > div.column > :first-child").addPseudoClass ("after-sub-sub-heading");
			$ ("div#content div.box > div, div#content div.category div.sub div.link div.special > div").addClass ("inner");
		}
	}
	$ ("div#content div.column").each (function () {
		$ (this).addClass ("column-width-" + $ (this).width ());
	});
	for (var i = 1; i < 10; i++) {
		$ ("div#content ol.default > li:nth-child(" + i + ")").addClass ("nth-child-" + i);
	}
	$ ("div#content ul.border-link > li:has(> a[target]), div#content ul.link > li:has(> a[target]), div#content ul.small-link > li:has(> a[target]), div#questionnaire ul.link > li:has(> a[target])").addClass ("external");
	$ ("div#content ul.border-link > li > a, div#content ul.link > li > a, div#content ul.small-link > li > a, div#questionnaire ul.link > li > a").hover (function () {
		$ (this).parent ().addClass ($ (this).parent ().hasClass ("external") ? "external-hover" : "hover");
	}, function () {
		$ (this).parent ().removeClass ($ (this).parent ().hasClass ("external") ? "external-hover" : "hover");
	});
	$ ("div#content div.anchor ul li a").hover (function () {
		$ (this).parent ().addClass ("hover");
	}, function () {
		$ (this).parent ().removeClass ("hover");
	});
	$ ("div#content div.category div.main div.shop table tr:nth-child(even), div#content div.category div.main div.shop table tr th:nth-child(4)").addClass ("even");
	$ ("div#content div.table").append ("<div class='corner-1'></div><div class='corner-2'></div><div class='corner-3'></div><div class='corner-4'></div>");
	adjustMarker = function () {
		$ ("div#content span.marker").parent ().parent ().each (function () {
			var marker = $ (this).children ().children ("span.marker");
			var width = 0;
			marker.each (function () {
				if (/\d$/.test ($.trim ($ (this).text ()))) {
					$ (this).append ("&nbsp;&nbsp;");
				}
				width = Math.max (width, $ (this).css ("display", "inline").width ("auto").width () - parseInt ($ (this).css ("text-indent")));
			});
			var margin = (parseInt (marker.eq (0).css ("margin-right")) + width);
			$ (this).css ("margin-left", (parseInt ($ (this).css ("margin-left")) + margin) + "px");
			marker.width (width).css ("margin-left", "-" + margin + "px");
		});
	};
	adjustTable = function () {
		$ ("div#content div.table > table").each (function () {
			$ (this).parent ().width ($ (this).width () + 1);
		});
	};
	adjustColumn = function () {
		$ ("div#content div.grid > div").filter (".middle, .bottom").each (function () {
			var height = 0;
			$ (this).siblings ().each (function () {
				height = Math.max (height, $ (this).height ());
			});
			var margin = Math.floor ((height - $ (this).height ()) / ($ (this).hasClass ("middle") ? 2 : 1));
			if (margin > 0) {
				$ (this).css ("margin-top", margin + "px");
			}
		});
	};
	if ($.browser.safari) {
		$ (window).load (function () {
			adjustMarker ();
			adjustTable ();
			adjustColumn ();
		});
	} else {
		adjustMarker ();
		adjustTable ();
		adjustColumn ();
	}
	adjustFooter = function () {
		if ($ ("body").hasClass ("popup") || $ ("body").hasClass ("popup-old")) {
			$ ("div#body").height ("auto");
			var height = $ ("div#header").height () + $ ("div#footer").height () + 87;
			if (($ ("div#body").height () + height) < $ (window).height ()) {
				$ ("div#body").height ($ (window).height () - height);
			}
		} else {
			$ ("div#wrapper").height ("auto");
			var height = $ ("div#topic-path").height () + $ ("div#footer").height () + 62;
			if (($ ("div#wrapper").height () + height) < $ (window).height ()) {
				$ ("div#wrapper").height ($ (window).height () - height);
			}
		}
	}
	$ (window).load (function () {
		adjustFooter ();
	}).resize (function () {
		adjustFooter ();
	});
});

/* [rollover] --------------------------------------------------------------- */
$ (function () {
	$ ("img.hover").each (function () {
		var source = $ (this).css ("filter").indexOf ("progid") != -1 ? $ (this).css ("filter").split ("\"")[1] : this.src;
		$ ("<img>").attr ("src", source.replace (/\.([^.]+)$/, "_hover." + "$1")).appendTo ("body").hide ();
	});
	$ ("a:has(img.hover)").hover (function () {
		$ ("img.hover", this).each (function () {
			var source = $ (this).css ("filter").indexOf ("progid") != -1 ? $ (this).css ("filter").split ("\"")[1] : this.src;
			this.src = source.replace (/\.([^.]+)$/, "_hover." + "$1");
		});
	}, function () {
		$ ("img.hover", this).each (function () {
			var source = $ (this).css ("filter").indexOf ("progid") != -1 ? $ (this).css ("filter").split ("\"")[1] : this.src;
			this.src = source.replace (/_hover\.([^.]+)$/, "." + "$1");
		});
	});
	$ ("input.hover").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");
		});
	});
});

/* [opener] ---------------------------------------------------------------- */
$ (function () {
	if ($ ("body").hasClass ("popup") || $ ("body").hasClass ("popup-old")) {
		$ ("a[target='_opener']").click (function () {
			try {
				window.opener.location.href = this.href;
				window.opener.focus ();
			} catch (e) {
				window.open (this.href, "_opener").focus ();
			}
			return false;
		});
	}
});

/* [theme] ------------------------------------------------------------------ */
var hour = (new Date).getHours () + (new Date).getMinutes () / 60;
document.write ("<link rel='stylesheet' type='text/css' href='/shared/qualityland/stylesheet/theme/" + (hour < 5 ? "night" : (hour < 12 ? "morning" : (hour < 17 ? "daylight" : "downlight"))) + ".css'>");