﻿/*
 * Copyright (c) 2009 Simo Kinnunen.
 * Licensed under the MIT license.
 */
var Cufon = (function () {
	var L = function () {
			return L.replace.apply(null, arguments)
		};
	var V = L.DOM = {
		ready: (function () {
			var a = false,
				c = {
					loaded: 1,
					complete: 1
				};
			var Z = [],
				b = function () {
					if (a) {
						return
					}
					a = true;
					for (var d; d = Z.shift(); d()) {}
				};
			if (document.addEventListener) {
				document.addEventListener("DOMContentLoaded", b, false);
				window.addEventListener("pageshow", b, false)
			}
			if (!window.opera && document.readyState) {
				(function () {
					c[document.readyState] ? b() : setTimeout(arguments.callee, 10)
				})()
			}
			if (document.readyState && document.createStyleSheet) {
				(function () {
					try {
						document.body.doScroll("left");
						b()
					} catch (d) {
						setTimeout(arguments.callee, 1)
					}
				})()
			}
			P(window, "load", b);
			return function (d) {
				if (!arguments.length) {
					b()
				} else {
					a ? d() : Z.push(d)
				}
			}
		})()
	};
	var M = L.CSS = {
		Size: function (a, Z) {
			this.value = parseFloat(a);
			this.unit = String(a).match(/[a-z%]*$/)[0] || "px";
			this.convert = function (b) {
				return b / Z * this.value
			};
			this.convertFrom = function (b) {
				return b / this.value * Z
			};
			this.toString = function () {
				return this.value + this.unit
			}
		},
		getStyle: function (a) {
			var Z = document.defaultView;
			if (Z && Z.getComputedStyle) {
				return new A(Z.getComputedStyle(a, null))
			}
			if (a.currentStyle) {
				return new A(a.currentStyle)
			}
			return new A(a.style)
		},
		quotedList: I(function (c) {
			var b = [],
				a = /\s*((["'])([\s\S]*?[^\\])\2|[^,]+)\s*/g,
				Z;
			while (Z = a.exec(c)) {
				b.push(Z[3] || Z[1])
			}
			return b
		}),
		ready: (function () {
			var b = false;
			var a = [],
				c = function () {
					b = true;
					for (var e; e = a.shift(); e()) {}
				};
			var Z = Object.prototype.propertyIsEnumerable ? F("style") : {
				length: 0
			};
			var d = F("link");
			V.ready(function () {
				var h = 0,
					g;
				for (var f = 0, e = d.length; g = d[f], f < e; ++f) {
					if (!g.disabled && g.rel.toLowerCase() == "stylesheet") {
						++h
					}
				}
				if (document.styleSheets.length >= Z.length + h) {
					c()
				} else {
					setTimeout(arguments.callee, 10)
				}
			});
			return function (e) {
				if (b) {
					e()
				} else {
					a.push(e)
				}
			}
		})(),
		supports: function (b, a) {
			var Z = document.createElement("span").style;
			if (Z[b] === undefined) {
				return false
			}
			Z[b] = a;
			return Z[b] === a
		},
		textAlign: function (c, b, Z, a) {
			if (b.get("textAlign") == "right") {
				if (Z > 0) {
					c = " " + c
				}
			} else {
				if (Z < a - 1) {
					c += " "
				}
			}
			return c
		},
		textDecoration: function (e, d) {
			if (!d) {
				d = this.getStyle(e)
			}
			var a = {
				underline: null,
				overline: null,
				"line-through": null
			};
			for (var Z = e; Z.parentNode && Z.parentNode.nodeType == 1;) {
				var c = true;
				for (var b in a) {
					if (!J(a, b) || a[b]) {
						continue
					}
					if (d.get("textDecoration").indexOf(b) != -1) {
						a[b] = d.get("color")
					}
					c = false
				}
				if (c) {
					break
				}
				d = this.getStyle(Z = Z.parentNode)
			}
			return a
		},
		textShadow: I(function (d) {
			if (d == "none") {
				return null
			}
			var c = [],
				e = {},
				Z, a = 0;
			var b = /(#[a-f0-9]+|[a-z]+\(.*?\)|[a-z]+)|(-?[\d.]+[a-z%]*)|,/ig;
			while (Z = b.exec(d)) {
				if (Z[0] == ",") {
					c.push(e);
					e = {}, a = 0
				} else {
					if (Z[1]) {
						e.color = Z[1]
					} else {
						e[["offX", "offY", "blur"][a++]] = Z[2]
					}
				}
			}
			c.push(e);
			return c
		}),
		color: I(function (a) {
			var Z = {};
			Z.color = a.replace(/^rgba\((.*?),\s*([\d.]+)\)/, function (c, b, d) {
				Z.opacity = parseFloat(d);
				return "rgb(" + b + ")"
			});
			return Z
		}),
		textTransform: function (a, Z) {
			return a[{
				uppercase: "toUpperCase",
				lowercase: "toLowerCase"
			}[Z.get("textTransform")] || "toString"]()
		}
	};

	function R(a) {
		var Z = this.face = a.face;
		this.glyphs = a.glyphs;
		this.w = a.w;
		this.baseSize = parseInt(Z["units-per-em"], 10);
		this.family = Z["font-family"].toLowerCase();
		this.weight = Z["font-weight"];
		this.style = Z["font-style"] || "normal";
		this.viewBox = (function () {
			var c = Z.bbox.split(/\s+/);
			var b = {
				minX: parseInt(c[0], 10),
				minY: parseInt(c[1], 10),
				maxX: parseInt(c[2], 10),
				maxY: parseInt(c[3], 10)
			};
			b.width = b.maxX - b.minX, b.height = b.maxY - b.minY;
			b.toString = function () {
				return [this.minX, this.minY, this.width, this.height].join(" ")
			};
			return b
		})();
		this.ascent = -parseInt(Z.ascent, 10);
		this.descent = -parseInt(Z.descent, 10);
		this.height = -this.ascent + this.descent
	}

	function E() {
		var a = {},
			Z = {
				oblique: "italic",
				italic: "oblique"
			};
		this.add = function (b) {
			(a[b.style] || (a[b.style] = {}))[b.weight] = b
		};
		this.get = function (f, g) {
			var e = a[f] || a[Z[f]] || a.normal || a.italic || a.oblique;
			if (!e) {
				return null
			}
			g = {
				normal: 400,
				bold: 700
			}[g] || parseInt(g, 10);
			if (e[g]) {
				return e[g]
			}
			var c = {
				1: 1,
				99: 0
			}[g % 100],
				i = [],
				d, b;
			if (c === undefined) {
				c = g > 400
			}
			if (g == 500) {
				g = 400
			}
			for (var h in e) {
				if (!J(e, h)) {
					continue
				}
				h = parseInt(h, 10);
				if (!d || h < d) {
					d = h
				}
				if (!b || h > b) {
					b = h
				}
				i.push(h)
			}
			if (g < d) {
				g = d
			}
			if (g > b) {
				g = b
			}
			i.sort(function (k, j) {
				return (c ? (k > g && j > g) ? k < j : k > j : (k < g && j < g) ? k > j : k < j) ? -1 : 1
			});
			return e[i[0]]
		}
	}

	function Q() {
		function b(d, e) {
			if (d.contains) {
				return d.contains(e)
			}
			return d.compareDocumentPosition(e) & 16
		}

		function Z(f) {
			var d = f.relatedTarget;
			if (!d || b(this, d)) {
				return
			}
			a(this)
		}

		function c(d) {
			a(this)
		}

		function a(d) {
			setTimeout(function () {
				L.replace(d, D.get(d).options, true)
			}, 10)
		}
		this.attach = function (d) {
			if (d.onmouseenter === undefined) {
				P(d, "mouseover", Z);
				P(d, "mouseout", Z)
			} else {
				P(d, "mouseenter", c);
				P(d, "mouseleave", c)
			}
		}
	}

	function Y() {
		var b = {},
			Z = 0;

		function a(c) {
			return c.cufid || (c.cufid = ++Z)
		}
		this.get = function (c) {
			var d = a(c);
			return b[d] || (b[d] = {})
		}
	}

	function A(Z) {
		var b = {},
			a = {};
		this.get = function (c) {
			return b[c] != undefined ? b[c] : Z[c]
		};
		this.getSize = function (d, c) {
			return a[d] || (a[d] = new M.Size(this.get(d), c))
		};
		this.extend = function (c) {
			for (var d in c) {
				if (J(c, d)) {
					b[d] = c[d]
				}
			}
			return this
		}
	}

	function P(a, Z, b) {
		if (a.addEventListener) {
			a.addEventListener(Z, b, false)
		} else {
			if (a.attachEvent) {
				a.attachEvent("on" + Z, function () {
					return b.call(a, window.event)
				})
			}
		}
	}

	function T(a, Z) {
		var b = D.get(a);
		if (b.options) {
			return a
		}
		if (Z.hover && Z.hoverables[a.nodeName.toLowerCase()]) {
			B.attach(a)
		}
		b.options = Z;
		return a
	}

	function I(Z) {
		var a = {};
		return function (b) {
			if (!J(a, b)) {
				a[b] = Z.apply(null, arguments)
			}
			return a[b]
		}
	}

	function C(e, d) {
		if (!d) {
			d = M.getStyle(e)
		}
		var a = M.quotedList(d.get("fontFamily").toLowerCase()),
			c;
		for (var b = 0, Z = a.length; b < Z; ++b) {
			c = a[b];
			if (H[c]) {
				return H[c].get(d.get("fontStyle"), d.get("fontWeight"))
			}
		}
		return null
	}

	function F(Z) {
		return document.getElementsByTagName(Z)
	}

	function J(a, Z) {
		return a.hasOwnProperty(Z)
	}

	function G() {
		var Z = {},
			b, d;
		for (var c = 0, a = arguments.length; b = arguments[c], c < a; ++c) {
			for (d in b) {
				if (J(b, d)) {
					Z[d] = b[d]
				}
			}
		}
		return Z
	}

	function N(c, m, a, n, d, b) {
		var k = n.separate;
		if (k == "none") {
			return X[n.engine].apply(null, arguments)
		}
		var j = document.createDocumentFragment(),
			f;
		var g = m.split(O[k]),
			Z = (k == "words");
		if (Z && S) {
			if (/^\s/.test(m)) {
				g.unshift("")
			}
			if (/\s$/.test(m)) {
				g.push("")
			}
		}
		for (var h = 0, e = g.length; h < e; ++h) {
			f = X[n.engine](c, Z ? M.textAlign(g[h], a, h, e) : g[h], a, n, d, b, h < e - 1);
			if (f) {
				j.appendChild(f)
			}
		}
		return j
	}

	function K(a, i) {
		var b, Z, c, f, e, h;
		for (c = T(a, i).firstChild; c; c = e) {
			f = c.nodeType;
			e = c.nextSibling;
			h = false;
			if (f == 1) {
				if (!c.firstChild) {
					continue
				}
				if (!/cufon/.test(c.className)) {
					arguments.callee(c, i);
					continue
				} else {
					h = true
				}
			} else {
				if (f != 3) {
					continue
				}
			}
			if (!Z) {
				Z = M.getStyle(a).extend(i)
			}
			if (!b) {
				b = C(a, Z)
			}
			if (!b) {
				continue
			}
			if (h) {
				X[i.engine](b, null, Z, i, c, a);
				continue
			}
			var g = c.data;
			if (g === "") {
				continue
			}
			var d = N(b, g, Z, i, c, a);
			if (d) {
				c.parentNode.replaceChild(d, c)
			} else {
				c.parentNode.removeChild(c)
			}
		}
	}
	var S = " ".split(/\s+/).length == 0;
	var D = new Y();
	var B = new Q();
	var W = [];
	var X = {},
		H = {},
		U = {
			enableTextDecoration: false,
			engine: null,
			hover: false,
			hoverables: {
				a: true
			},
			printable: true,
			selector: (window.Sizzle || (window.jQuery &&
			function (Z) {
				return jQuery(Z)
			}) || (window.dojo && dojo.query) || (window.$$ &&
			function (Z) {
				return $$(Z)
			}) || (window.$ &&
			function (Z) {
				return $(Z)
			}) || (document.querySelectorAll &&
			function (Z) {
				return document.querySelectorAll(Z)
			}) || F),
			separate: "words",
			textShadow: "none"
		};
	var O = {
		words: /\s+/,
		characters: ""
	};
	L.now = function () {
		V.ready();
		return L
	};
	L.refresh = function () {
		var b = W.splice(0, W.length);
		for (var a = 0, Z = b.length; a < Z; ++a) {
			L.replace.apply(null, b[a])
		}
		return L
	};
	L.registerEngine = function (a, Z) {
		if (!Z) {
			return L
		}
		X[a] = Z;
		return L.set("engine", a)
	};
	L.registerFont = function (b) {
		var Z = new R(b),
			a = Z.family;
		if (!H[a]) {
			H[a] = new E()
		}
		H[a].add(Z);
		return L.set("fontFamily", '"' + a + '"')
	};
	L.replace = function (b, a, Z) {
		a = G(U, a);
		if (!a.engine) {
			return L
		}
		if (typeof a.textShadow == "string") {
			a.textShadow = M.textShadow(a.textShadow)
		}
		if (!Z) {
			W.push(arguments)
		}
		if (b.nodeType || typeof b == "string") {
			b = [b]
		}
		M.ready(function () {
			for (var d = 0, c = b.length; d < c; ++d) {
				var e = b[d];
				if (typeof e == "string") {
					L.replace(a.selector(e), a, true)
				} else {
					K(e, a)
				}
			}
		});
		return L
	};
	L.set = function (Z, a) {
		U[Z] = a;
		return L
	};
	return L
})();
Cufon.registerEngine("canvas", (function () {
	var B = document.createElement("canvas");
	if (!B || !B.getContext || !B.getContext.apply) {
		return
	}
	B = null;
	var A = Cufon.CSS.supports("display", "inline-block");
	var E = !A && (document.compatMode == "BackCompat" || /frameset|transitional/i.test(document.doctype.publicId));
	var F = document.createElement("style");
	F.type = "text/css";
	F.appendChild(document.createTextNode(".cufon-canvas{text-indent:0}@media screen,projection{.cufon-canvas{display:inline;display:inline-block;position:relative;vertical-align:middle" + (E ? "" : ";font-size:1px;line-height:1px") + "}.cufon-canvas .cufon-alt{display:-moz-inline-box;display:inline-block;width:0;height:0;overflow:hidden}" + (A ? ".cufon-canvas canvas{position:relative}" : ".cufon-canvas canvas{position:absolute}") + "}@media print{.cufon-canvas{padding:0 !important}.cufon-canvas canvas{display:none}.cufon-canvas .cufon-alt{display:inline}}"));
	document.getElementsByTagName("head")[0].appendChild(F);

	function D(O, H) {
		var M = 0,
			L = 0;
		var G = [],
			N = /([mrvxe])([^a-z]*)/g,
			J;
		generate: for (var I = 0; J = N.exec(O); ++I) {
			var K = J[2].split(",");
			switch (J[1]) {
			case "v":
				G[I] = {
					m: "bezierCurveTo",
					a: [M + ~~K[0], L + ~~K[1], M + ~~K[2], L + ~~K[3], M += ~~K[4], L += ~~K[5]]
				};
				break;
			case "r":
				G[I] = {
					m: "lineTo",
					a: [M += ~~K[0], L += ~~K[1]]
				};
				break;
			case "m":
				G[I] = {
					m: "moveTo",
					a: [M = ~~K[0], L = ~~K[1]]
				};
				break;
			case "x":
				G[I] = {
					m: "closePath"
				};
				break;
			case "e":
				break generate
			}
			H[G[I].m].apply(H, G[I].a)
		}
		return G
	}

	function C(K, J) {
		for (var I = 0, H = K.length; I < H; ++I) {
			var G = K[I];
			J[G.m].apply(J, G.a)
		}
	}
	return function (q, T, k, P, X, r) {
		var I = (T === null);
		var V = q.viewBox;
		var J = k.getSize("fontSize", q.baseSize);
		var h = k.get("letterSpacing");
		h = (h == "normal") ? 0 : J.convertFrom(parseInt(h, 10));
		var W = 0,
			j = 0,
			f = 0,
			R = 0;
		var U = P.textShadow,
			d = [];
		if (U) {
			for (var p = 0, m = U.length; p < m; ++p) {
				var Z = U[p];
				var c = J.convertFrom(parseFloat(Z.offX));
				var b = J.convertFrom(parseFloat(Z.offY));
				d[p] = [c, b];
				if (b < W) {
					W = b
				}
				if (c > j) {
					j = c
				}
				if (b > f) {
					f = b
				}
				if (c < R) {
					R = c
				}
			}
		}
		var u = Cufon.CSS.textTransform(I ? X.alt : T, k).split("");
		var G = 0,
			S = null;
		for (var p = 0, m = u.length; p < m; ++p) {
			var Q = q.glyphs[u[p]] || q.missingGlyph;
			if (!Q) {
				continue
			}
			G += S = Number(Q.w || q.w) + h
		}
		if (S === null) {
			return null
		}
		j += (V.width - S);
		R += V.minX;
		var O, K;
		if (I) {
			O = X;
			K = X.firstChild
		} else {
			O = document.createElement("span");
			O.className = "cufon cufon-canvas";
			O.alt = T;
			K = document.createElement("canvas");
			O.appendChild(K);
			if (P.printable) {
				var n = document.createElement("span");
				n.className = "cufon-alt";
				n.appendChild(document.createTextNode(T));
				O.appendChild(n)
			}
		}
		var v = O.style;
		var a = K.style;
		var H = J.convert(V.height - W + f);
		var t = Math.ceil(H);
		var e = t / H;
		K.width = Math.ceil(J.convert(G + j - R) * e);
		K.height = t;
		W += V.minY;
		a.top = Math.round(J.convert(W - q.ascent)) + "px";
		a.left = Math.round(J.convert(R)) + "px";
		var N = Math.ceil(J.convert(G * e)) + "px";
		if (A) {
			v.width = N;
			v.height = J.convert(q.height) + "px"
		} else {
			v.paddingLeft = N;
			v.paddingBottom = (J.convert(q.height) - 1) + "px"
		}
		var s = K.getContext("2d"),
			Y = t / V.height;
		s.scale(Y, Y);
		s.translate(-R, -W);
		s.lineWidth = q.face["underline-thickness"];
		s.save();

		function L(i, g) {
			s.strokeStyle = g;
			s.beginPath();
			s.moveTo(0, i);
			s.lineTo(G, i);
			s.stroke()
		}
		var M = P.enableTextDecoration ? Cufon.CSS.textDecoration(r, k) : {};
		if (M.underline) {
			L(-q.face["underline-position"], M.underline)
		}
		if (M.overline) {
			L(q.ascent, M.overline)
		}
		s.fillStyle = k.get("color");

		function o() {
			for (var w = 0, g = u.length; w < g; ++w) {
				var x = q.glyphs[u[w]] || q.missingGlyph;
				if (!x) {
					continue
				}
				s.beginPath();
				if (x.d) {
					if (x.code) {
						C(x.code, s)
					} else {
						x.code = D("m" + x.d, s)
					}
				}
				s.fill();
				s.translate(Number(x.w || q.w) + h, 0)
			}
		}
		if (U) {
			for (var p = 0, m = U.length; p < m; ++p) {
				var Z = U[p];
				s.save();
				s.fillStyle = Z.color;
				s.translate.apply(s, d[p]);
				o();
				s.restore()
			}
		}
		o();
		s.restore();
		if (M["line-through"]) {
			L(-q.descent, M["line-through"])
		}
		return O
	}
})());
Cufon.registerEngine("vml", (function () {
	if (!document.namespaces) {
		return
	}
	if (document.namespaces.cvml == null) {
		document.namespaces.add("cvml", "urn:schemas-microsoft-com:vml")
	}
	var B = document.createElement("cvml:shape");
	B.style.behavior = "url(#default#VML)";
	if (!B.coordsize) {
		return
	}
	B = null;
	document.write('<style type="text/css">.cufon-vml-canvas{text-indent:0}@media screen{cvml\\:shape,cvml\\:shadow{behavior:url(#default#VML);display:block;antialias:true;position:absolute}.cufon-vml-canvas{position:absolute;text-align:left}.cufon-vml{display:inline-block;position:relative;vertical-align:middle}.cufon-vml .cufon-alt{position:absolute;left:-10000in;font-size:1px}a .cufon-vml{cursor:pointer}}@media print{.cufon-vml *{display:none}.cufon-vml .cufon-alt{display:inline}}</style>');

	function C(D, E) {
		return A(D, /(?:em|ex|%)$/i.test(E) ? "1em" : E)
	}

	function A(G, H) {
		if (/px$/i.test(H)) {
			return parseFloat(H)
		}
		var F = G.style.left,
			E = G.runtimeStyle.left;
		G.runtimeStyle.left = G.currentStyle.left;
		G.style.left = H;
		var D = G.style.pixelLeft;
		G.style.left = F;
		G.runtimeStyle.left = E;
		return D
	}
	return function (s, V, n, S, Z, t, j) {
		var G = (V === null);
		if (G) {
			V = Z.alt
		}
		var X = s.viewBox;
		var H = n.computedFontSize || (n.computedFontSize = new Cufon.CSS.Size(C(t, n.get("fontSize")) + "px", s.baseSize));
		var h = n.computedLSpacing;
		if (h == undefined) {
			h = n.get("letterSpacing");
			n.computedLSpacing = h = (h == "normal") ? 0 : ~~H.convertFrom(A(t, h))
		}
		var P, I;
		if (G) {
			P = Z;
			I = Z.firstChild
		} else {
			P = document.createElement("span");
			P.className = "cufon cufon-vml";
			P.alt = V;
			I = document.createElement("span");
			I.className = "cufon-vml-canvas";
			P.appendChild(I);
			if (S.printable) {
				var q = document.createElement("span");
				q.className = "cufon-alt";
				q.appendChild(document.createTextNode(V));
				P.appendChild(q)
			}
			if (!j) {
				P.appendChild(document.createElement("cvml:shape"))
			}
		}
		var y = P.style;
		var c = I.style;
		var E = H.convert(X.height),
			v = Math.ceil(E);
		var g = v / E;
		var f = X.minX,
			e = X.minY;
		c.height = v;
		c.top = Math.round(H.convert(e - s.ascent));
		c.left = Math.round(H.convert(f));
		y.height = H.convert(s.height) + "px";
		var L = S.enableTextDecoration ? Cufon.CSS.textDecoration(t, n) : {};
		var U = n.get("color");
		var w = Cufon.CSS.textTransform(V, n).split("");
		var D = 0,
			d = 0,
			M = null;
		var T, N, W = S.textShadow;
		for (var r = 0, p = 0, o = w.length; r < o; ++r) {
			T = s.glyphs[w[r]] || s.missingGlyph;
			if (T) {
				D += M = ~~ (T.w || s.w) + h
			}
		}
		if (M === null) {
			return null
		}
		var O = -f + D + (X.width - M);
		var x = H.convert(O * g),
			m = Math.round(x);
		var b = O + "," + X.height,
			F;
		var Y = "r" + b + "nsnf";
		for (r = 0; r < o; ++r) {
			T = s.glyphs[w[r]] || s.missingGlyph;
			if (!T) {
				continue
			}
			if (G) {
				N = I.childNodes[p];
				if (N.firstChild) {
					N.removeChild(N.firstChild)
				}
			} else {
				N = document.createElement("cvml:shape");
				I.appendChild(N)
			}
			N.stroked = "f";
			N.coordsize = b;
			N.coordorigin = F = (f - d) + "," + e;
			N.path = (T.d ? "m" + T.d + "xe" : "") + "m" + F + Y;
			N.fillcolor = U;
			var u = N.style;
			u.width = m;
			u.height = v;
			if (W) {
				var K = W[0],
					J = W[1];
				var R = Cufon.CSS.color(K.color),
					Q;
				var a = document.createElement("cvml:shadow");
				a.on = "t";
				a.color = R.color;
				a.offset = K.offX + "," + K.offY;
				if (J) {
					Q = Cufon.CSS.color(J.color);
					a.type = "double";
					a.color2 = Q.color;
					a.offset2 = J.offX + "," + J.offY
				}
				a.opacity = R.opacity || (Q && Q.opacity) || 1;
				N.appendChild(a)
			}
			d += ~~ (T.w || s.w) + h;
			++p
		}
		y.width = Math.max(Math.ceil(H.convert(D * g)), 0);
		return P
	}
})());

