/* child
--------------------------------------------------------- */
$ (function () {

	if ($.browser.msie) {
		if ($.browser.version < 7) {
			$ (":first-child").addClass ("first-child");
			$ ("input").each (function () {
				$ (this).addClass ($ (this).attr ("type"));
			});
		}
	}
});


/* indent
--------------------------------------------------------- */
$ (function () {
	$ ("span.marker").parent ().parent ().each (function () {
		var marker = $ (this).children ().children ("span.marker");
		var width = 0;
		marker.each (function () {
			width = Math.max (width, $ (this).css ("display", "inline").width () - parseInt ($ (this).css ("text-indent")));
		});
		var margin = (parseInt (marker.eq (0).css ("margin-right")) + width) + "px";
		$ (this).css ("margin-left", margin);
		marker.width (width).css ("margin-left", "-" + margin);
	});
});

/* rollover
--------------------------------------------------------- */
$ (function () {
	$ ("img.rollover").each (function () {
		$ ("<img />").attr ("src", this.src.replace (/\.([^.]+)$/, "_hover." + "$1"));
	});
	$ ("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"));
		$ (this).hover (function () {
			this.src = this.src.replace (/\.([^.]+)$/, "_hover." + "$1");
		}, function () {
			this.src = this.src.replace (/_hover\.([^.]+)$/, "." + "$1");
		});
	});
});

/* table
--------------------------------------------------------- */
$ (function () {
	$ ("div#content div.round-table-a-1,div#content div.round-table-b-1").append ("<div class='corner-1'></div><div class='corner-2'></div><div class='corner-3'></div><div class='corner-4'></div>");
});

/* window
--------------------------------------------------------- */
$ (function () {
	$ (".external").attr ("target", "_blank");
	$ ("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;
	});
});

/* valign */
$ (function () {
	$ ("div.column").filter (".middle, .bottom").each (function () {
		var height = 0;
		$ (this).siblings ().each (function () {
			height = Math.max (height, $ (this).height ());
		});
			var margin = Math.max (height - $ (this).height (), 0);
		$ (this).css ("margin-top", ($ (this).hasClass ("middle") ? Math.floor (margin / 2) : margin) + "px");
	});
});