var WikiReflection = {
	render : function(B, A) {
		$ES("*[class^=reflection]", B).each( function(C) {
			var D = C.className.split("-");
			$ES("img", C).each( function(E) {
				Reflection.add(E, D[1], D[2])
			})
		})
	}
};
Wiki.addPageRender(WikiReflection);
var Reflection = {
	options : {
		height : 0.33,
		opacity : 0.5
	},
	add : function(E, I, G) {
		I = (I) ? I / 100 : this.options.height;
		G = (G) ? G / 100 : this.options.opacity;
		var B = new Element("div").injectAfter(E).adopt(E), H = E.width, D = E.height, C = Math
				.floor(D * I);
		B.className = E.className.replace(/\breflection\b/, "");
		B.style.cssText = E.backupStyle = E.style.cssText;
		B.setStyles( {
			width : E.width,
			height : D + C
		});
		E.style.cssText = "vertical-align: bottom";
		if (window.ie) {
			new Element(
					"img",
					{
						src : E.src,
						styles : {
							width : H,
							marginBottom : "-" + (D - C) + "px",
							filter : "flipv progid:DXImageTransform.Microsoft.Alpha(opacity="
									+ (G * 100)
									+ ", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy="
									+ (I * 100) + ")"
						}
					}).inject(B)
		} else {
			var A = new Element("canvas", {
				width : H,
				height : C,
				styles : {
					width : H,
					height : C
				}
			}).inject(B);
			if (!A.getContext) {
				return
			}
			var J = A.getContext("2d");
			J.save();
			J.translate(0, D - 1);
			J.scale(1, -1);
			J.drawImage(E, 0, 0, H, D);
			J.restore();
			J.globalCompositeOperation = "destination-out";
			var F = J.createLinearGradient(0, 0, 0, C);
			F.addColorStop(0, "rgba(255, 255, 255, " + (1 - G) + ")");
			F.addColorStop(1, "rgba(255, 255, 255, 1.0)");
			J.fillStyle = F;
			J.rect(0, 0, H, C);
			J.fill()
		}
	}
};
var WikiAccordion = {
	render : function(D, C) {
		var A = new Element("div", {
			"class" : "toggle"
		}), B = new Element("div", {
			"class" : "collapseBullet"
		});
		$ES(".accordion, .tabbedAccordion, .leftAccordion, .rightAccordion", D)
				.each(
						function(E) {
							var G = [], F = [], H = false;
							if (E.hasClass("tabbedAccordion")) {
								H = new Element("div", {
									"class" : "menu top"
								}).injectBefore(E)
							} else {
								if (E.hasClass("leftAccordion")) {
									H = new Element("div", {
										"class" : "menu left"
									}).injectBefore(E)
								} else {
									if (E.hasClass("rightAccordion")) {
										H = new Element("div", {
											"class" : "menu right"
										}).injectBefore(E)
									}
								}
							}
							E.getChildren().each(
									function(J) {
										if (!J.className.test("^tab-")) {
											return
										}
										var K = J.className.substr(4)
												.deCamelize(), I = A.clone()
												.appendText(K);
										H ? I.inject(H) : B.clone().injectTop(
												I.injectBefore(J));
										G.push(I);
										F.push(J.addClass("tab"))
									});
							new Accordion(G, F, {
								height : true,
								alwaysHide : !H,
								onComplete : function() {
									var I = $(this.elements[this.previous]);
									if (I.offsetHeight > 0) {
										I.setStyle("height", "auto")
									}
								},
								onActive : function(J, K) {
									J.addClass("active");
									var I = J.getFirst();
									if (I) {
										I.setProperties( {
											title : "collapse".localize(),
											"class" : "collapseOpen"
										}).setHTML("-")
									}
									K.addClass("active")
								},
								onBackground : function(J, K) {
									K.setStyle("height", K.offsetHeight);
									J.removeClass("active");
									var I = J.getFirst();
									if (I) {
										I.setProperties( {
											title : "expand".localize(),
											"class" : "collapseClose"
										}).setHTML("+")
									}
									K.removeClass("active")
								}
							})
						});
		B = A = null
	}
};
Wiki.addPageRender(WikiAccordion);
var RoundedCorners = {
	$Top : {
		y : [ {
			margin : "5px",
			height : "1px",
			borderSide : "0",
			borderTop : "1px"
		}, {
			margin : "3px",
			height : "1px",
			borderSide : "2px"
		}, {
			margin : "2px",
			height : "1px",
			borderSide : "1px"
		}, {
			margin : "1px",
			height : "2px",
			borderSide : "1px"
		} ],
		s : [ {
			margin : "2px",
			height : "1px",
			borderSide : "0",
			borderTop : "1px"
		}, {
			margin : "1px",
			height : "1px",
			borderSide : "1px"
		} ],
		b : [ {
			margin : "8px",
			height : "1px",
			borderSide : "0",
			borderTop : "1px"
		}, {
			margin : "6px",
			height : "1px",
			borderSide : "2px"
		}, {
			margin : "4px",
			height : "1px",
			borderSide : "1px"
		}, {
			margin : "3px",
			height : "1px",
			borderSide : "1px"
		}, {
			margin : "2px",
			height : "1px",
			borderSide : "1px"
		}, {
			margin : "1px",
			height : "3px",
			borderSide : "1px"
		} ]
	},
	$registry : {},
	register : function(A, B) {
		this.$registry[A] = B;
		return this
	},
	render : function(D, B) {
		this.$Bottom = {};
		for ( var C in this.$Top) {
			this.$Bottom[C] = this.$Top[C].slice(0).reverse()
		}
		for ( var A in this.$registry) {
			var F = $$(A), E = this.$registry[A];
			this.exec(F, E[0], E[1], E[2], E[3])
		}
		$ES("*[class^=roundedCorners]", D).each( function(G) {
			var H = G.className.split("-");
			if (H.length >= 2) {
				this.exec( [ G ], H[1], H[2], H[3], H[4])
			}
		}, this)
	},
	exec : function(C, B, A, F, D) {
		B = (B || "yyyy") + "nnnn";
		A = new Color(A) || "transparent";
		F = new Color(F);
		D = new Color(D);
		var E = B.split("");
		C.each( function(J) {
			if (J.$passed) {
				return
			}
			var I = this.addCorner(this.$Top, E[0], E[1], A, F, J), G = this
					.addCorner(this.$Bottom, E[2], E[3], A, F, J);
			if (I || G) {
				this.addBody(J, A, F);
				if (I) {
					var H = J.getStyle("padding-top").toInt();
					I.setStyle("margin-top", H - I.getChildren().length);
					J.setStyle("padding-top", 0);
					I.injectTop(J)
				}
				if (G) {
					var H = J.getStyle("padding-bottom").toInt();
					G.setStyle("margin-bottom", H - G.getChildren().length);
					J.setStyle("padding-bottom", 0);
					J.adopt(G)
				}
			}
			if (F) {
				J.setStyle("border", "none")
			}
			J.$passed = true
		}, this);
		top = bottom = null
	},
	getTemplate : function(C, A) {
		var B = false;
		if (A != "nn") {
			for ( var D in C) {
				if (A.contains(D)) {
					B = C[D];
					break
				}
			}
		}
		return B
	},
	addCorner : function(H, D, I, F, E, B) {
		H = this.getTemplate(H, D + I);
		if (!H) {
			return false
		}
		var G = B.getStyle("padding-left").toInt(), A = B.getStyle(
				"padding-right").toInt();
		var C = new Element("b", {
			"class" : "roundedCorners",
			styles : {
				display : "block",
				"margin-left" : -1 * G,
				"margin-right" : -1 * A
			}
		});
		H.each( function(J) {
			var K = new Element("div", {
				styles : {
					height : J.height,
					overflow : "hidden",
					"border-width" : "0",
					"background-color" : F.hex
				}
			});
			if (E.hex) {
				K.setStyles( {
					"border-color" : E.hex,
					"border-style" : "solid"
				});
				if (J.borderTop) {
					K.setStyles( {
						"border-top-width" : J.borderTop,
						height : "0"
					})
				}
			}
			if (D != "n") {
				K.setStyle("margin-left", J.margin)
			}
			if (I != "n") {
				K.setStyle("margin-right", J.margin)
			}
			if (E.hex) {
				K.setStyles( {
					"border-left-width" : (D == "n") ? "1px" : J.borderSide,
					"border-right-width" : (I == "n") ? "1px" : J.borderSide
				})
			}
			C.adopt(K)
		});
		return C
	},
	addBody : function(G, B, D) {
		var E = G.getStyle("padding-left").toInt(), F = G.getStyle(
				"padding-right").toInt();
		var A = new Element("div", {
			styles : {
				overflow : "hidden",
				"margin-left" : -1 * E,
				"margin-right" : -1 * F,
				"padding-left" : (E == 0) ? 4 : E,
				"padding-right" : (F == 0) ? 4 : F,
				"background-color" : B.hex
			}
		}).wrapChildren(G);
		if (D.hex) {
			var C = "1px solid " + D.hex;
			A.setStyles( {
				"border-left" : C,
				"border-right" : C
			})
		}
	}
};
Wiki.addPageRender(RoundedCorners);
var WikiTips = {
	render : function(C, B) {
		var A = [];
		$ES("*[class^=tip]", C)
				.each(
						function(F) {
							var G = F.className.split("-");
							if (G.length <= 0 || G[0] != "tip") {
								return
							}
							F.className = "tip";
							var D = new Element("span").wrapChildren(F).hide(), E = (G[1]) ? G[1]
									.deCamelize()
									: "tip.default.title".localize();
							A.push(new Element("span", {
								"class" : "tip-anchor",
								title : E + "::" + D.innerHTML
							}).setHTML(E).inject(F))
						});
		if (A.length > 0) {
			new Tips(A, {
				className : "tip",
				Xfixed : true
			})
		}
	}
};
Wiki.addPageRender(WikiTips);
var WikiColumns = {
	render : function(C, B) {
		var A = [];
		$ES("*[class^=columns]", C).each( function(D) {
			var E = D.className.split("-");
			D.className = "columns";
			WikiColumns.buildColumns(D, E[1] || "auto")
		})
	},
	buildColumns : function(C, B) {
		var F = $ES("hr", C);
		if (!F || F.length == 0) {
			return
		}
		var E = F.length + 1;
		B = (B == "auto") ? 98 / E + "%" : B / E + "px";
		var D = new Element("div", {
			"class" : "col",
			styles : {
				width : B
			}
		}), A = D.clone().injectBefore(C.getFirst()), G;
		while (G = A.nextSibling) {
			if (G.tagName && G.tagName.toLowerCase() == "hr") {
				A = D.clone();
				$(G).replaceWith(A);
				continue
			}
			A.appendChild(G)
		}
		new Element("div", {
			styles : {
				clear : "both"
			}
		}).inject(C)
	}
};
Wiki.addPageRender(WikiColumns);
var WikiPrettify = {
	render : function(C, A) {
		var B = $ES(".prettify pre, .prettify code", C);
		if (!B || B.length == 0) {
			return
		}
		B.addClass("prettyprint");
		prettyPrint(C)
	}
};
Wiki.addPageRender(WikiPrettify);