jQuery.fn.fancyZoom = function(O) {
	var O = O || {};
	var L = O && O.directory ? O.directory : "images";
	var D = false;
	if ($("#zoom").length == 0) {
		var E = $.browser.msie ? "gif" : "png";
		var J = '<div id="zoom" style="display:none;"> <table id="zoom_table" style="border-collapse:collapse; width:100%; height:100%;"> <tbody> <tr> <td class="tl" style="background:url('
				+ L
				+ "/tl."
				+ E
				+ ') 0 0 no-repeat; width:20px; height:20px; overflow:hidden;" /> <td class="tm" style="background:url('
				+ L
				+ "/tm."
				+ E
				+ ') 0 0 repeat-x; height:20px; overflow:hidden;" /> <td class="tr" style="background:url('
				+ L
				+ "/tr."
				+ E
				+ ') 100% 0 no-repeat; width:20px; height:20px; overflow:hidden;" /> </tr> <tr> <td class="ml" style="background:url('
				+ L
				+ "/ml."
				+ E
				+ ') 0 0 repeat-y; width:20px; overflow:hidden;" /> <td class="mm" style="background:#fff; vertical-align:top; padding:10px;"> <div id="zoom_content"> </div> </td> <td class="mr" style="background:url('
				+ L
				+ "/mr."
				+ E
				+ ') 100% 0 repeat-y; width:20px; overflow:hidden;" /> </tr> <tr> <td class="bl" style="background:url('
				+ L
				+ "/bl."
				+ E
				+ ') 0 100% no-repeat; width:20px; height:20px; overflow:hidden;" /> <td class="bm" style="background:url('
				+ L
				+ "/bm."
				+ E
				+ ') 0 100% repeat-x; height:20px; overflow:hidden;" /> <td class="br" style="background:url('
				+ L
				+ "/br."
				+ E
				+ ') 100% 100% no-repeat; width:20px; height:20px; overflow:hidden;" /> </tr> </tbody> </table> <a href="#" title="Close" id="zoom_close" style="position:absolute; top:0; left:0;"> <img src="'
				+ L
				+ "/closebox."
				+ E
				+ '" alt="Close" style="border:none; margin:0; padding:0;" /> </a> </div>';
		$("body").append(J);
		$("html").click(function(P) {
			if ($(P.target).parents("#zoom:visible").length == 0) {
				K()
			}
		});
		$(document).keyup(function(P) {
			if (P.keyCode == 27 && $("#zoom:visible").length > 0) {
				K()
			}
		});
		$("#zoom_close").click(K)
	}
	var N = $("#zoom");
	var I = $("#zoom_table");
	var H = $("#zoom_close");
	var G = $("#zoom_content");
	var A = $("td.ml,td.mm,td.mr");
	this.each(function(P) {
		$($(this).attr("href")).hide();
		$(this).click(M)
	});
	return this;
	function M(V) {
		if (D) {
			return false
		}
		D = true;
		var P = $($(this).attr("href"));
		var T = O.width;
		var U = O.height;
		var Q = window.innerWidth
				|| (window.document.documentElement.clientWidth || window.document.body.clientWidth);
		var b = window.innerHeight
				|| (window.document.documentElement.clientHeight || window.document.body.clientHeight);
		var Z = window.pageXOffset
				|| (window.document.documentElement.scrollLeft || window.document.body.scrollLeft);
		var Y = window.pageYOffset
				|| (window.document.documentElement.scrollTop || window.document.body.scrollTop);
		var c = {
			width : Q,
			height : b,
			x : Z,
			y : Y
		};
		var Q = (T || P.width()) + 60;
		var b = (U || P.height()) + 60;
		var W = c;
		var X = Math.max((W.height / 2) - (b / 2) + Y, 0);
		var a = (W.width / 2) - (Q / 2);
		var R = V.pageY;
		var S = V.pageX;
		H.attr("curTop", R);
		H.attr("curLeft", S);
		H.attr("scaleImg", O.scaleImg ? "true" : "false");
		$("#zoom").hide().css( {
			position : "absolute",
			top : R + "px",
			left : S + "px",
			width : "1px",
			height : "1px"
		});
		F();
		H.hide();
		if (O.closeOnClick) {
			$("#zoom").click(K)
		}
		if (O.scaleImg) {
			G.html(P.html());
			$("#zoom_content img").css("width", "100%")
		} else {
			G.html("")
		}
		$("#zoom").animate( {
			top : X + "px",
			left : a + "px",
			opacity : "show",
			width : Q,
			height : b
		}, 500, null, function() {
			if (O.scaleImg != true) {
				G.html(P.html())
			}
			C();
			H.show();
			D = false
		});
		return false
	}
	function K() {
		if (D) {
			return false
		}
		D = true;
		$("#zoom").unbind("click");
		F();
		if (H.attr("scaleImg") != "true") {
			G.html("")
		}
		H.hide();
		$("#zoom").animate( {
			top : H.attr("curTop") + "px",
			left : H.attr("curLeft") + "px",
			opacity : "hide",
			width : "1px",
			height : "1px"
		}, 500, null, function() {
			if (H.attr("scaleImg") == "true") {
				G.html("")
			}
			C();
			D = false
		});
		return false
	}
	function B(R) {
		$("#zoom_table td").each(
				function(T) {
					var S = $(this).css("background-image").replace(
							/\.(png|gif|none)\"\)$/, "." + R + '")');
					$(this).css("background-image", S)
				});
		var Q = H.children("img");
		var P = Q.attr("src").replace(/\.(png|gif|none)$/, "." + R);
		Q.attr("src", P)
	}
	function F() {
		if ($.browser.msie && parseFloat($.browser.version) >= 7) {
			B("gif")
		}
	}
	function C() {
		if ($.browser.msie && $.browser.version >= 7) {
			B("png")
		}
	}
};
