var o = null;
jQuery
		.extend( {
			easybox : function(options) {
				var defaults = {
					padding : "0",
					backGroundColor : "#E3E8F1",
					backGroundInner : "#F1F3F8",
					borderColor : "#E3E8F1",
					borderWidth : "0",
					color : "#5D5D5D",
					top : "20",
					width : "800",
					height : "600",
					duration : "800",
					opacity : "1",
					data : "",
					anchor : "#",
					id : "",
					fixWidth : "0",
					source : "",
					params : "",
					mode : "html",
					title : "Easybox by &copy 2009 Adrian Koschnik inspired by thickbox &amp; lightbox",
					items : false,
					banner : true,
					closeAllElems : false,
					corner : false,
					version : "12.10.2009"
				};
				o = $.extend(defaults, options);
				if (o.corner) {
					if (!$().corner) {
						$.getScript("js/jquery.corner.js");
					}
				}
				if (document.getElementById("jq_box") == null) {
					$("body").append(
							'<div id="jq_box" style="display:none;" />');
				}
				if (document.getElementById("jq_box_banner") == null) {
					$("body").append(
							'<div id="jq_box_banner" style="display:none;"><div id="jq_box_title">'
									+ o.title + "</div></div>");
				}
				if (document.getElementById("jq_box_inner") == null) {
					$("body")
							.append(
									'<div id="jq_box_inner" style="display:none;"></div>');
				}
				$.load("jq_box_inner");
				var bodyWidth = $("body").innerWidth();
				var bodyHeight = $("body").innerHeight();
				if (bodyWidth <= o.width) {
					o.width = bodyWidth * 0.6;
				}
				if (bodyHeight <= o.height) {
					o.height = bodyHeight * 0.6;
				}
				var borderTopBottom = (bodyHeight - o.height) / 2;
				var borderLeftRight = (bodyWidth - o.width) / 2;
				var cssParam = {
					"position" : "absolute",
					"left" : "-4px",
					"top" : "10px",
					"padding" : "7px",
					"width" : bodyWidth + "px",
					"height" : "40px",
					"background-color" : o.borderColor,
					"color" : "#5D5D5D",
					"cursor" : "pointer",
					"opacity" : "0.55",
					"font-family" : "Verdana, Arial,Times New Roman",
					"font-weight" : "700",
					"font-size" : "32px",
					"border" : "3px solid #2F65B1",
					"textAlign" : "left",
					"cursor" : "pointer",
					"background-image" : "url(easybox_logo.gif)",
					"background-repeat" : "no-repeat"
				};
				$("#jq_box_banner").css(cssParam);
				var cssParam = {
					"width" : (bodyWidth - 150) + "px",
					"height" : "40px",
					"background-color" : "transparent",
					"color" : "#2F65B1",
					"font-family" : "Verdana, Arial,Times New Roman",
					"font-weight" : "500",
					"font-size" : "14pt",
					"marginLeft:" : "100px",
					"marginTop:" : "8px"
				};
				$("#jq_box_title").css(cssParam);
				var cssParam = {
					"position" : "absolute",
					"left" : "0px",
					"top" : "0px",
					"width" : bodyWidth + "px",
					"height" : $("body").height() + "px",
					"background-color" : "#808080",
					"opacity" : "1",
					"font-weight" : "700",
					"text-align" : "center",
					"cursor" : (o.closeAllElems ? "pointer" : "hand")
				};
				$("#jq_box").css(cssParam);
				var cssParam = {
					"position" : "absolute",
					"left" : "0px",
					"top" : (Number(o.top) + 65) + "px",
					"marginLeft" : (borderLeftRight) + "px",
					"width" : o.width + "px",
					"height" : "35px",
					"background-color" : o.backGroundColor,
					"border" : o.borderWidth + "px solid #2F65B1",
					"font-weight" : "700",
					"opacity" : "0.55",
					"padding" : "10px",
					"cursor" : (o.closeAllElems ? "pointer" : "hand"),
					"text-align" : "left"
				};
				$("#jq_box_inner").css(cssParam);
				$("#jq_box").queue(function() {
					$("#jq_box").fadeIn(o.duration);
					$("#jq_box_inner").slideDown(o.duration / 2, function() {
					});
					$("#jq_box").dequeue();
				});
				$("#jq_box").animate( {
					"opacity" : o.opacity
				}, 2000);
				$("html,body").animate( {
					scrollTop : 0
				}, {
					duration : 500,
					queue : true
				});
				if (o.banner == true) {
					$("#jq_box_banner").show().animate( {
						"opacity" : "0.98"
					}, 5000);
				}
				$("#jq_box_loader").animate( {
					"font-size" : "25"
				}, 5000);
				$("#jq_box_inner").animate( {
					"height" : o.height + "px"
				}, 1000);
				$.getSource();
				$("#jq_box_banner").click(function() {
					$.close();
				});
				$("#jq_box_close").click(function() {
					$.close();
				});
				$("input#jq_box_close").click(function() {
					$.close();
				});
				var closeText = "Mit einem Mausklick diese Ansicht beenden.";
				$("#jq_box_banner").attr("title", closeText);
				if (o.closeAllElems) {
					$("#jq_box_inner").click(function() {
						$.close();
					});
					$("#jq_box_loader").click(function() {
						$.close();
					});
					$("#jq_box").click(function() {
						$.close();
					});
					$("#jq_box_inner").attr("title", closeText);
					$("#jq_box").attr("title", closeText);
				}
				return o.json;
			},
			load : function(id, ende) {
				$("html,body").animate( {
					scrollTop : 0
				}, {
					duration : 500,
					queue : true
				});
				$('<div id="jq_box_loader"></div>').appendTo("#" + id);
				$("#jq_box_loader")
						.html(
								'<img src="img/common/loadingAnimation.gif" title="Laden..." /><br/>' + (ende != true ? "Die Daten werden geladen..."
										: "Die Ansicht wird geschlossen..."));
				$("#jq_box_loader")
						.css(
								{
									"position" : "absolute",
									"top" : "200px",
									"left" : (ende == true ? (($("body")
											.innerWidth() / 2) - 100)
											+ "px" : "200px")
								});
			},
			close : function() {
				$.load("jq_box", true);
				$("#jq_box").animate( {
					"opacity" : "1",
					"background-color" : "#E3E8F1"
				}, {
					duration : 800,
					queue : false
				});
				$("#jq_box").css( {
					"text-align" : "center",
					"vertical-align" : "middle"
				});
				$("#jq_box_banner").animate( {
					"height" : "0",
					"opacity" : "0"
				}, {
					duration : 800,
					queue : true
				}).remove();
				$("#jq_box_inner").animate( {
					"height" : "0",
					"opacity" : "0"
				}, {
					duration : 800,
					queue : true
				}).remove();
				var achorTop = (o.anchor != "#" && o.anchor != "" ? $(o.anchor)
						.offset().top : 0);
				window.setTimeout(function() {
					if (achorTop > 0) {
						$("html,body").animate( {
							scrollTop : achorTop
						}, "fast");
					}
					window.setTimeout(function() {
						$("#jq_box").animate( {
							"opacity" : "0",
							"background-color" : "#E3E8F1"
						}, {
							duration : 200,
							queue : true
						});
						window.setTimeout(function() {
							$("#jq_box_loader").remove();
							$("#jq_banner").remove();
							$("#jq_inner").remove();
							$("#jq_box").remove();
						}, 500);
					}, 500);
				}, 500);
			},
			fillNavi : function() {
				if (o.items != false) {
					alert("APEND");
					$("#jq_box_inner")
							.append(
									"<table><tr><td></td><td></td><td>Naechste</td></tr></table>");
				}
			},
			fillBox : function(code) {
				$("#jq_box_loader").animate( {
					"height" : "0",
					"opacity" : "0"
				}, {
					"duration" : "200",
					"queue" : true
				});
				$("#jq_box_loader").remove();
				$("#jq_box_inner").html('<div id="jq_box_code"></div>');
				$("#jq_box_code").html(code);
				window.setTimeout(function() {
					$("#jq_box_code").ready(
							function() {
								$("#jq_box_inner").css( {
									"opacity" : "1"
								});
								$("#jq_box_inner").height(
										($("#jq_box_code").height() + 200));
								if (o.corner && $().corner) {
									$("#jq_box_inner").corner(
											"cc:#808080 round 28px");
								}
							});
				}, 2000);
				$("img").css( {
					"border" : "0px",
					"text-align" : "center"
				});
				$(".easyBoxClose").click(function() {
					$.close();
				});
			},
			getSource : function() {
				switch (o.mode) {
				case "HTML":
					$.ajax( {
						url : o.source,
						global : false,
						type : "GET",
						data : o.params,
						dataType : "html",
						success : function(html) {
							$.fillBox(html);
						},
						error : function(msg) {
							$.fillBox("Fehler");
						}
					});
					break;
				case "JSON":
					break;
				case "XML":
					break;
				case "ID":
					$.fillBox($("#" + o.source).html());
					break;
				default:
					alert("Box Init Error:" + o.mode);
					break;
				}
			}
		});