(function($){
	$.fn.extend({
		codify : function () {
			var d = {
				url: "http://remiya.com",
				version: "1.6",
				title: true,
				style: "uni",
				elements: [],
				languages: ["4cs", "6502acme", "6502kickass", "6502tasm", "68000devpac", "abap", "actionscript", "actionscript3", "ada", "algol68", "apache", "applescript", "apt_sources", "asm", "asp", "autoconf", "autohotkey", "autoit", "avisynth", "awk", "bash", "basic4gl", "bf", "bibtex", "blitzbasic", "bnf", "boo", "c", "c_loadrunner", "c_mac", "caddcl", "cadlisp", "cfdg", "cfm", "chaiscript", "cil", "clojure", "cmake", "cobol", "cpp", "cpp-qt", "csharp", "css", "cuesheet", "d", "dcs", "delphi", "diff", "div", "dos", "dot", "e", "ecmascript", "eiffel", "email", "epc", "erlang", "f1", "falcon", "fo", "fortran", "freebasic", "fsharp", "gambas", "gdb", "genero", "genie", "gettext", "glsl", "gml", "gnuplot", "go", "groovy", "gwbasic", "haskell", "hicest", "hq9plus", "html4strict", "icon", "idl", "ini", "inno", "intercal", "io", "j", "java", "java5", "javascript", "jquery", "kixtart", "klonec", "klonecpp", "latex", "lb", "lisp", "locobasic", "logtalk", "lolcode", "lotusformulas", "lotusscript", "lscript", "lsl2", "lua", "m68k", "magiksf", "make", "mapbasic", "matlab", "mirc", "mmix", "modula2", "modula3", "mpasm", "mxml", "mysql", "newlisp", "nsis", "oberon2", "objc", "objeck", "ocaml", "ocaml-brief", "oobas", "oracle11", "oracle8", "oxygene", "oz", "pascal", "pcre", "per", "perl", "perl6", "pf", "php", "php-brief", "pic16", "pike", "pixelbender", "plsql", "postgresql", "povray", "powerbuilder", "powershell", "progress", "prolog", "properties", "providex", "purebasic", "python", "q", "qbasic", "rails", "rebol", "reg", "robots", "rpmspec", "rsplus", "ruby", "sas", "scala", "scheme", "scilab", "sdlbasic", "smalltalk", "smarty", "sql", "systemverilog", "tcl", "teraterm", "text", "thinbasic", "tsql", "typoscript", "unicon", "vala", "vb", "vbnet", "verilog", "vhdl", "vim", "visualfoxpro", "visualprolog", "whitespace", "whois", "winbatch", "xbasic", "xml", "xorg_conf", "xpp", "z80", "zxbasic"],
				uni: {
					out: "margin-bottom:10px;margin-top:10px;background:#DFDDD1;border:2px outset #7F7647;font-size:12px;font-family:\"Lucida Console\",\"Courier New\",Courier,monospace;",
					inner: "background:#F7FFEF;margin:5px;",
					title: "color:#F5F4EE;background:#7F7647;font-family:verdana;font-size:12px;"
				},
				blue: {
					out: "margin-bottom:10px;margin-top:10px;background:#AFE3FF;border:2px outset #0089B9;font-size:12px;font-family:\"Lucida Console\",\"Courier New\",Courier,monospace;",
					inner: "background:#EFFBFF;margin:5px;",
					title: "color:white;background:#0089B9;font-family:verdana;font-size:12px;"
				},
				green: {
					out: "margin-bottom:10px;margin-top:10px;background:#D5EF86;border:2px outset #8DB900;font-size:12px;font-family:\"Lucida Console\",\"Courier New\",Courier,monospace;",
					inner: "background:#FBFFEF;margin:5px;",
					title: "color:white;background:#8DB900;font-family:verdana;font-size:12px;"
				},
				red: {
					out: "margin-bottom:10px;margin-top:10px;background:#FFD7CF;border:2px outset #B91E00;font-size:12px;font-family:\"Lucida Console\",\"Courier New\",Courier,monospace;",
					inner: "background:#FFF2EF;margin:5px;",
					title: "color:white;background:#B91E00;font-family:verdana;font-size:12px;"
				}
			};
			function full_encode_uri(a) {
				var b = [];
				for (var i = 0; i < a.length; i++) {
					var c = a.charCodeAt(i);
					if (c < 128) {
						b.push(c)
					} else if (c < 2048) {
						b.push(0xC0 + (c >> 6), 0x80 + (c & 0x3F))
					} else if (c < 65536) {
						b.push(0xE0 + (c >> 12), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F))
					} else {
						b.push(0xF0 + (c >> 18), 0x80 + (c >> 12 & 0x3F), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F))
					}
				}
				for (var j = 0; j < b.length; j++) {
					var d = b[j].toString(16).toUpperCase();
					if (d.length < 2) {
						d = "0" + d
					}
					b[j] = d
				}
				return "%" + b.join("%")
			}
			function in_array(o, a) {
				for (var i = 0; i < a.length; i++) {
					if ((a[i] === o)) {
						return true
					}
				}
				return false
			}
			function init(b) {
				d.elements[d.elements.length] = b;
				var c = "";
				var e = $(b).attr("id");
				var f = $(b).attr("class").toLowerCase();
				if (f === "blue") {
					d.style = "blue"
				}
				if (f === "green") {
					d.style = "green"
				}
				if (f === "red") {
					d.style = "red"
				}
				if (f === "uni") {
					d.style = "uni"
				}
				var g = $(b).attr("lang").toLowerCase();
				var h = $(b).attr("title");
				if (h === "") {
					h = "Code"
				}
				var i = $(b).html();
				var j, icss, tcss;
				if (undefined !== d[d.style]) {
					j = d[d.style].out;
					icss = d[d.style].inner;
					tcss = d[d.style].title
				} else {
					j = d.uni.out;
					icss = d.uni.inner;
					tcss = d.uni.title
				}
				h = (d.title === true) ? "<table width='100%' cellspacing='0' cellpadding='3' style='" + tcss + "'><tr><td><b>&nbsp;" + h + "&nbsp;</b></td><td width='10'><button style='" + tcss + ";border:0px;' onmouseover='this.style.color=\"orange\";' onmouseout='this.style.color=\"#F5F4EE\";' title='About' onclick='com_remiya_codify_about()'><b>?</b></button></td></tr></table>": "";
				if (undefined !== $(b).attr("nodeName") && $(b).attr("nodeName").toLowerCase() == "pre") {
					c = "pre";
					$("<div style='" + j + "'>" + h + "<div style='" + icss + "'><pre id='" + e + "' style='width:100%;padding:10px;padding-top:20px;padding-bottom:20px;margin:0px;overflow-x:auto;'>" + i + "</pre></div>").replaceAll($(b))
				} else {
					c = "code";
					$("<div style='" + j + "'>" + h + "<div id='" + e + "' style='" + icss + "padding:20px;overflow-x:auto;'>" + i + "</div>").replaceAll($(b))
				}
				if (undefined !== d.geshi) {
					if (g !== "" && in_array(g, d.languages)) {
						var k = i.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '');
						if (c == "code") {
							k = k.split("<BR>").join("\n");
							k = k.split("<BR />").join("\n");
							k = k.split("<br>").join("\n");
							k = k.split("<br />").join("\n");
							k = k.split("&nbsp;").join(" ")
						}
						k = k.split("&lt;").join("<");
						k = k.split("&gt;").join(">");
						$.ajax({
							type: "POST",
							data: "language=" + g + "&text=" + full_encode_uri(k.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '')),
							url: d.geshi,
							dataType: "html",
							error: function () {},
							success: function (a) {
								$("#" + e).html(a);
								$("#" + e).css("padding", 10)
							}
						})
					}
				}
			}
			com_remiya_codify_about = function () {
				var a = "<p>JQuery Codify is a small, interactive, syntax highlighter built on top of the excellent jQuery and GeSHi library.</p>";
				a += "<p style='margin:2px;'><b>Official Website:</b> <a href='" + d.url + "' target='_blank'>" + d.url + "</a></p>";
				a += "<p style='margin:2px;'><b>License:</b> Freeware</p>";
				a += "<p style='margin:2px;'><b>Version:</b> " + d.version + "</p>";
				a += "<p style='margin:2px;'><b>Credits:</b></p>";
				a += "<p style='margin:2px;padding-left:20px;'><a href='http://jquery.com/' target='_blank'>JQuery (JavaScript Framework)</a></p>";
				a += "<p style='margin:2px;padding-left:20px;'><a href='http://qbnz.com/highlighter/' target='_blank'>GeSHi (Generic Syntax Highlighter)</a></p>";
				var b = '<table cellspacing="3" cellpadding="0" width="100%" height="100%"  style="background:#D7E3F2;border:2px solid #7E9DB9;font-family:verdana;font-size:12px;">';
				b += '<tr><td align="center" valign="middle" height="30" style="font-size:16px;"><b>About Codify</b></td></tr>';
				b += '<tr><td style="border:1px solid #7E9DB9;background:white;font-size:11px;" valign="top"><div style="overflow:auto;height:140px;" >' + a + '</div></td></tr>';
				b += '<tr><td height="20"><table width="100%" style="font-family:verdana;font-size:10px;"><tr><td align="left">Copyright&copy;2009-2010 Remiya Solutions<br>All right reserved!</td><td align="right"><button style="width:60px;height:24px;font-family:verdana;font-size:11px;" onclick="$(\'#' + d.id + '_about\').fadeOut(500);">Close</button></td></tr></table></td></tr>';
				b += '</table>';
				var w = 300;
				var h = 200;
				var c = ($(window).height() - 200) / 2 + $(document).scrollTop();
				var e = ($(window).width() - 300) / 2;
				if ($("#" + d.id + "_about").length === 0) {
					$("body").append("<div id='" + d.id + "_about' style='display:none;position:absolute;background:red;width:" + w + "px;height:" + h + "px;top:" + c + "px;left:" + e + "px;'>about</div>");
					$("#" + d.id + "_about").html(b)
				} else {
					$("#" + d.id + "_about").css("top", c).css("left", e)
				}
				$("#" + d.id + "_about").focus();
				$("#" + d.id + "_about").fadeIn(1000)
			};
			return this.each(function () {
				if (undefined === window.jquery_remiya_codify) {
					window.jquery_remiya_codify = []
				}
				if (!$(this).attr("id")) {
					$(this).attr("id", "jquery_codify_" + window.jquery_remiya_codify.length);
					window.jquery_remiya_codify[window.jquery_remiya_codify.length] = window.jquery_remiya_codify.length
				}
				//if (l !== undefined) {
				if (typeof(l) !== 'undefined') {
					$.extend(d, l)
				}
				init(this)
			})
		}
	});
})(jQuery);
