var scriptversion = "Version: 08.12.2009 16:46 Ver: 001";
var o = null;
var height = 660;
jQuery
		.extend( {
			init : function(options) {
				if ($.browser.msie) {
					$("#container").css( {
						"height" : height
					});
					$("#left").css( {
						"height" : height
					});
					$("#middle").css( {
						"height" : height
					});
					$("#right").css( {
						"height" : height
					});
				}
				$("noscript").remove();
				if (!$().corner && $.browser.msie) {
					
					$.getScript("js/jquery.corner.js");
				}
				$("img")
						.attr(
								"src",
								function() {
									return this.src
											.replace(
													/http:\/\/obiwan\/pmd2009\//,
													(self.location.host == "www.promind.de" ? ""
															: ""));
								});
				var defaults = {
					idart : 0,
					height : 0,
					url : "router",
					imgLoad : "img/common/loadingAnimation.gif",
					easybox : false
				};
				window.status = "(c) 2009 Promind GmbH [...Initialisiere...]";
				window.defaultStatus = "(c) 2009 Promind GmbH [...Initialisiere...]";
				window.status = "(c) 2009 Promind GmbH [" + scriptversion + "]";
				window.defaultStatus = "(c) 2009 Promind GmbH ["
						+ scriptversion + "]";
				o = $.extend(defaults, options);
				if (o.idart == 29) {
				} else {
					if (o.idart == 32) {
						$.getScript("js/jq_suggestion.js");
					} else {
						if (o.idart == 39) {
							$(document)
									.ready(
											function() {
												$("div.para_img")
														.css(
																{
																	"margin" : "0px",
																	"padding" : "0px",
																	"backgroundColor" : "#D5DCEB",
																	"height" : "372px",
																	"width" : "566px",
																	"opacity" : "0.25"
																})
														.prepend(
																'<div class="error">Einen Augenblick bitte, ein WebCAM-Bild wird geladen...</div>')
														.animate( {
															"opacity" : "0.85"
														}, {
															duration : 5000
														});
												$.webCAM();
												window.setInterval(
														"$.webCAM()", 35100);
											});
						}
					}
				}
				$(window).load(function() {
					$.resizeBOXs();
				});
				$("img").attr("alt", "Bild");
				if (o.idart == 29) {
				} else {
					if (o.idart == 14) {
						$(".thumb").click(function() {
							alert($(this).attr("src"));
						});
					} else {
						if (o.idart == 4) {
							$('<div class="mvi"></div>').insertAfter(
									"#footer .para");
							$("#footer div.mvi")
									.css( {
										"position" : "relative",
										"float" : "right",
										"top" : -46,
										"width" : 85,
										"height" : $("#footer").height(),
										"pointer" : "cursor"
									})
									.attr("title", "MVI - Ueber uns")
									.click(
											function() {
												self.location.href = "ueber-uns-5.html";
											});
						} else {
							if (o.idart == 32) {
								window.setTimeout(function() {
									$.initSearchForm();
								}, 2000);
							}
						}
					}
				}
			},
			webCAM : function() {
				var doit = new Date();
				var img = new Image();
				$(img)
						.load(
								function() {
									$(this)
											.fadeOut(
													1000,
													function() {
														$("div.para_img").html(
																this).css( {
															opacity : "1"
														});
														$("div.para_img")
																.append(
																		'<div id="webcaminfo" class="info hidden">Anzeige: '
																				+ doit
																						.toLocaleString()
																				+ "</div>");
														$("#webcaminfo")
																.css(
																		{
																			opacity : "0",
																			marginTop : "5px"
																		})
																.removeClass(
																		"hidden")
																.animate(
																		{
																			opacity : "1"
																		},
																		{
																			duration : 6000,
																			queue : false
																		});
														$(this)
																.fadeIn(1000)
																.dblclick(
																		function() {
																			if (confirm("Jetzt aktualisieren?")) {
																				window
																						.clearInterval("$.webCAM()");
																				$
																						.webCAM();
																				window
																						.setInterval(
																								"$.webCAM()",
																								35000);
																			}
																		});
													});
								})
						.error(
								function() {
									$("div.para_img")
											.html(
													'<div class="error">Beim Laden des WebCAM-Bildes ist ein Fehler aufgetreten! <input class="webcam" type="button" value="Aktualisieren" /></div>');
									$("input.webcam").click(function() {
										$.webCAM();
									});
								}).attr(
								{
									"src" : "camshow?" + doit.getTime(),
									"alt" : "Promind WebCAM",
									"title" : "Promind WebCAM - Aufnahmezeit: "
											+ doit.toLocaleString()
											+ " [Doppelklick aktualisieren]"
								}).css( {
							left : "0px",
							top : "0px",
							opacity : "0.91"
						});
			},
			ieBehaviour : function() {
				if (!$().corner && $.browser.msie) {
					return false;
				}
				if ($.browser.msie) {
					$(".box_170_50").corner("round 8px");
					$(".box_col2").corner("round 8px");
				}
				$("#jq-state").html("");
			},
			loadEasyBox : function() {
				if (!$().easybox && o.easybox == false) {
					if (o.idart == 1 || o.idart == 2 || o.idart == 4 || o.idart == 39
							|| o.idart == 16 || o.idart == 18 || o.idart == 19
							|| o.idart == 20 || o.idart == 29 || o.idart == 32) {
						//$.getScript("js/jquery.easybox.js");
						//alert('LOAD E');
						o.easybox = true;
					}
				}
			},
			showEasyBox : function(ID) {
				var title = "";
				var bannerShow = false;
				var boxHeight = 610;
				var boxWidth = 1000;
				var classid = false;
				var bgColor = "#E3E8F1";
				switch (ID[0]) {
				case "SEMINAR":
					title = "Seminarangebot";
					boxWidth = 800;
					boxHeight = 800;
					break;
				case "JOB":
					title = "Stellanzeige";
					boxWidth = 831;
					boxHeight = 810;
					bgColor = "transparent";
					break;
				case "NEWS":
					title = "Nachricht";
					bannerShow = false;
					boxWidth = 425;
					boxHeight = 400;
					classid = "box_170_50";
					break;
				default:
					title = "Schulung: ";
					ID[1] = ID[0];
					ID[0] = "COURSE";
					boxWidth = 810;
					boxHeight = 1000;
					break;
				}
				$.easybox( {
					title : title + ID[2],
					backGroundColor : bgColor,
					opacity : "1",
					banner : bannerShow,
					padding : "0",
					border : "1",
					width : boxWidth,
					height : boxHeight,
					mode : "HTML",
					source : "router",
					params : "action=" + ID[0] + "_VIEW&id=" + ID[1],
					items : classid
				});
			},
			getXHR : function(opt) {
				var defaults = {
					"action" : "test",
					"param" : "",
					"mode" : "get",
					"type" : "html",
					"size" : "0"
				};
				paras = $.extend(defaults, opt);
				if (Number(paras.size) > 0) {
					o.height = Number(paras.size);
				}
				if (document.getElementById("jq_" + paras.action) != null) {
					var domid = $("#jq_" + paras.action);
					$.loadingPlaceHolder(domid, true);
					var regex = /action=/g;
					var res = regex.test(paras.param);
					if (paras.param == "") {
						paras.param = "action=" + paras.action;
					} else {
						if (res == false) {
							paras.param += "action=" + paras.action;
						}
					}
					if (paras.action == "search_result") {
						alert("2do: " + paras.action);
					} else {
						if (paras.action == "personal_data") {
							paras.param += "&id=" + o.idart;
							if (o.idart == 29) {
								var mode = self.location.href;
								mode = mode.split("/");
								if (mode[mode.length - 1] != "initiativbewerbung.html"
										&& mode[mode.length - 2] != "schulung"
										&& mode[mode.length - 2] != "seminar") {
									paras.param += "&idjob="
											+ mode[mode.length - 1];
								} else {
									if (mode[mode.length - 2] == "schulung") {
										paras.param += "&mode=schulung";
									} else {
										if (mode[mode.length - 2] == "seminar") {
											paras.param += "&mode=seminar";
										}
									}
								}
							}
							$.remoteAccess(domid, paras);
						} else {
							$.remoteAccess(domid, paras);
						}
					}
					$.loadEasyBox();
				}
			},
			remoteAccess : function(domid, paras) {
				$
						.ajax( {
							url : o.url,
							global : false,
							type : paras.mode,
							data : paras.param,
							dataType : paras.type,
							success : function(data) {
								$.loadingPlaceHolder(domid, false);
								$(domid).html(data);
								$.ieBehaviour();
								$(".box_col2").click(function() {
									$.showEasyBox($.getID($(this).attr("id")));
									$(this).css( {
										"background-color" : "#D5DCEB"
									});
								});
								$(".box_170_50").click(function() {
									$.showEasyBox($.getID($(this).attr("id")));
									$(this).css( {
										"background-color" : "#D5DCEB"
									});
								});
							},
							error : function(data) {
								$.loadingPlaceHolder(domid, false);
								$(domid)
										.html(
												'<div class="error">Beim Laden der Daten sind Fehler aufgetreten!</div>');
								$.resizeBOXs();
							}
						});
				$(document).ready(function() {
					$.resizeBOXs();
				});
			},
			getID : function(id) {
				var eid = id.split("_");
				if (eid[1] == "undefined") {
					eid[1] = eid[0];
					eid[0] = "SEMINAR";
					alert(eid[0]);
				}
				eid[2] = $("#" + id).text();
				return eid;
			},
			loadingPlaceHolder : function(id, load) {
				if (load) {
					$(id)
							.html(
									'<img id="LOADINGPLACEHOLDER" src="' + o.imgLoad + '" alt="Lade Daten..." />');
					$(id).show(3000);
				} else {
					$("#LOADINGPLACEHOLDER").hide(500).remove();
				}
			},
			previewArticle : function(idart) {
				$("html,body").animate( {
					scrollTop : 0
				}, 1000);
				var bgColor = $("#middle").css("background-color");
				$("#header")
						.hide(
								"fast",
								function() {
									$("#right").hide(500);
									$("#left").hide(500);
									$("#mfooter").hide(500);
									$("#footer").hide(500);
									$("#preview").hide(500);
									$(
											'<input id="closePreview" type="button" value="Schliessen" /> ')
											.appendTo("#container");
									$("#closePreview").show(500);
									$("#middle").css( {
										"background-color" : "#FFFFFF",
										"border" : "1px solid black"
									});
									$("#closePreview").click(function() {
										$("#middle").css( {
											"background-color" : bgColor,
											"border" : "0px"
										});
										$("#header").show(1000, function() {
											$("#left").show(500);
											$("#right").show(500);
											$("#footer").show(500);
											$("#mfooter").show(500);
											$("#preview").show(500);
										});
										$("input#closePreview").remove();
									});
								});
			},
			resizeBOXs : function() {
				var h = height;
				var topFooter = $("#mfooter").height()
						+ ($.browser.msie ? 45 : 44);
				$("#middle").height(
						100
								+ $("#content").height()
								+ $("#mfooter").height()
								+ ($("#jq_state").is(":hidden") ? 0 : $(
										"#jq_state").height())
								+ ($("#jq_result").is(":hidden") ? 0 : $(
										"#jq_result").height()));
				h = ($("#middle").height() > $("#left").height() ? $("#middle")
						.height() : $("#left").height());
				h = ($("#middle").height() > $("#right").height() ? $("#middle")
						.height()
						: $("#right").height());
				h = ($("#left").height() > $("#right").height() ? $("#left")
						.height() : $("#right").height());
				h = ($("#right").height() > $("#middle").height()
						|| $("#right").height() > $("#left").height() ? $(
						"#right").height()
						: ($("#middle").height() > $("#left").height() ? $(
								"#middle").height() : $("#left").height()));
				if (h < height) {
					h = height;
				}
				if (o != null) {
					if (o.idart == 4) {
						h = ($.browser.msie ? ($.browser.version == "8.0" ? 520
								: 590) : 540);
					}
					h = Number(h) + Number(o.height);
				} else {
					h = Number(h);
				}
				h += 10 + topFooter;
				$("#left").height(h);
				$("#middle").height(
						($.browser.msie && $.browser.version == "7.0" ? (h - 3)
								: h));
				$("#right").height(h);
				$("#content").height(h - topFooter - 20);
				$("#container").height(h);
				$("#wrap").height(
						h + $("#header").height() + $("#footer").height());
				$("body").height($("#wrap").height() + 150);
				var mOffset = $("#middle").offset();
				$("#mfooter").css( {
					"position" : "relative",
					"top" : "-" + 0 + "px",
					"left" : "0px",
					"width" : $("#middle").width()
				});
				$("#mfooter").show(1000).removeAttr("class");
			}
		});