// JavaScript Document
jQuery.fn.che_replace = function (d) {
	var e = {
		width: 15,
		height: 15,
		margin: {
			left: 0,
			top: 0,
			right: 5,
			bottom: 0
		},
		img: '/i/che.gif',
		state: {
			normal: {
				left: 0,
				top: -53
			},
			down: {
				checked: {
					left: 0,
					top: 0
				},
				normal: {
					left: 0,
					top: -36
				}
			},
			up: {},
			checked: {
				left: 0,
				top: -17
			}
		}
	};
	e = jQuery.extend(e, d);
	return $(this).each(function () {
		var b = $(this).attr("checked");
		var c = $(this).val();
		$(this).css({
			display: "none"
		}).wrap(document.createElement("div")).parent().attr("tabindex", "0").css({
			width: e.width + "px",
			height: e.height + "px",
			margin: e.margin.top + "px " + e.margin.right + "px " + e.margin.bottom + "px " + e.margin.left + "px",
			backgroundImage: "url(" + e.img + ")",
			backgroundPosition: (b) ? e.state.checked.left + "px " + e.state.checked.top + "px ": e.state.normal.left + "px " + e.state.normal.top + "px ",
			cursor: "pointer",
			backgroundRepeat: "no-repeat",
			float: "left"
		}).attr("class", (b) ? "checked": "normal").mousedown(function () {
			var a = $(this).attr("class");
			$(this).css({
				backgroundPosition: (a == "checked") ? e.state.down.checked.left + "px " + e.state.down.checked.top + "px ": e.state.down.normal.left + "px " + e.state.down.normal.top + "px ",
			}).mouseout(function () {})
		}).mouseup(function () {
			var a = $(this).attr("class");
			$(this).css({
				backgroundPosition: (a == "checked") ? e.state.normal.left + "px " + e.state.normal.top + "px ": e.state.checked.left + "px " + e.state.checked.top + "px ",
			}).attr("class", (a == "checked") ? "normal": "checked").find(":checkbox").attr("checked", (a == "checked") ? "": "checked")
		}).keydown(function (a) {
			switch (a.keyCode) {
			case 32:
				$(this).trigger("mousedown");
				break
			}
		}).keyup(function (a) {
			switch (a.keyCode) {
			case 32:
				$(this).trigger("mouseup");
				break
			}
		})
	})
};

