
$(document).ready(
	function () {
		// linke Spalte und Inhaltsspalte auf die selbe Höhe bringen
		// TODO: da scheint etwas in der Hoehenberechnung schief zu laufen. Wenn man den ausgelesenen Wert wieder setzt, aendert sich sichtbar die Hoehe des Elements! Zum Glueck ist die ausgelesene Hoehe hoeher als der benoetigte Bereich - also setzen wir beiden Objekten die neue Hoehe
		var contentWrapObj = $("#contentWrap");
		var colLeftObj = $("#colLeft");
		var newH = (contentWrapObj.height() < colLeftObj.height()) ? colLeftObj.height() : contentWrapObj.height();
		colLeftObj.height(newH);
		contentWrapObj.height(newH);
		
		// Inhaltsspalte animieren
		$("#contentWrap").animateContent();
		
		// Hintergrundbild anpassen
		$("#backgroundImage img").setSizeAndPositionOfBackgroundImage();
		$("#backgroundImage2 img").setSizeAndPositionOfBackgroundImage();
		
		// Tooltips
		$('.tt').tooltip({  track: true,  showURL: false,  showBody: " - ",  fixPNG: true,  opacity: 0.95,  left: -120  });
		
		// Scriptabhaengige Bereiche ein-, bzw. ausblenden
		$(".script").show();
		$(".noscript").hide();
		
		// Opera betreffend
		if (browser != "opera") {
			$(".operaOnly").hide();
		}
		
		// Lightbox fuer Bilder
		//$('a.popupImage').lightBox();
		
		// scroll to top
		$("#toTop a").click(function () {
				$('html,body').animate({scrollTop: 0}, $(this).offset().top);
				return false;
		})

		
		// IE 6 betreffend (hope this Browser will pass away soon - it's a reason for my nightmares)
		if (browser == "msie" && version < 7){
			// PNG-Fix
			$(".spritesIcons").addClass("ieTransBug");
			DD_belatedPNG.fix('.ieTransBug');
			
			// den user alamieren, dass er einen uralt Browser benutzt
			if ($.readCookie("iebrowserupdate") != "1") {
				$.setCookie("iebrowserupdate", "1", {duration: 1});
				if (language == "de"){
					jAlert('Ihr Browser ist <b>inkompatibel</b> zu den weltweiten Standards (W3C) und beherbergt <span style="color: red;">mindestens 22 nicht behobene schwere Fehler</span>, die es z. B. ermöglichen, Daten von ihrem Computer zu klauen oder Ihren Computer als Spamschleuder zu missbrauchen! Wechseln Sie auf einen anderen Browser!<br /><br />Hier eine Liste populärer und sicherer anderer Webbrowser:<br /><table style="text-align: center"><tr><td><a style="color: #000;" href="http://www.microsoft.com/windows/Internet-explorer/default.aspx" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_ie.gif" width="100" height="100" border="0" alt="Internet Explorer 7+" /><br />Internet Explorer 7+</a></td><td><a style="color: #000;" href="http://www.mozilla.com/firefox/" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_firefox.gif" width="100" height="100" border="0" alt="Firefox 3+" /><br />Firefox 3+</a></td><td><a style="color: #000;" href="http://www.apple.com/safari/download/" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_safari.gif" width="100" height="100" border="0" alt="Safari 3+" /><br />Safari 3+</a></td><td><a style="color: #000;" href="http://www.opera.com/download/" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_opera.gif" width="100" height="100" border="0" alt="Opera 9.5+" /><br />Opera 9.5+</a></td><td><a style="color: #000;" href="http://www.google.com/chrome" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_chrome.gif" width="100" height="100" border="0" alt="Chrome 2.0+" /><br />Chrome 2.0+</a></td></tr></table>', 'Wissen Sie, dass Ihr Internet Explorer seit mindestens 5 Jahren nicht mehr aktuell ist?');
				} else {
					jAlert('Your Browser is <b>incompatible</b> to the worldwide standards (W3C) and includes <span style="color: red;">at least 22 not solved heavy errors</span>, which allows to steal data from your computer or to abuse your computer as spam-machine! Please change to another Browser!<br /><br />Here is a list of popular and save Webbrowser:<br /><table style="text-align: center"><tr><td><a style="color: #000;" href="http://www.microsoft.com/windows/Internet-explorer/default.aspx" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_ie.gif" width="100" height="100" border="0" alt="Internet Explorer 7+" /><br />Internet Explorer 7+</a></td><td><a style="color: #000;" href="http://www.mozilla.com/firefox/" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_firefox.gif" width="100" height="100" border="0" alt="Firefox 3+" /><br />Firefox 3+</a></td><td><a style="color: #000;" href="http://www.apple.com/safari/download/" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_safari.gif" width="100" height="100" border="0" alt="Safari 3+" /><br />Safari 3+</a></td><td><a style="color: #000;" href="http://www.opera.com/download/" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_opera.gif" width="100" height="100" border="0" alt="Opera 9.5+" /><br />Opera 9.5+</a></td><td><a style="color: #000;" href="http://www.google.com/chrome" target="_blank"><img src="fileadmin/tmpl/lib/ie6-warning/browser_chrome.gif" width="100" height="100" border="0" alt="Chrome 2.0+" /><br />Chrome 2.0+</a></td></tr></table>', 'Do you know, that your Internet Explorer is out of date at least than 5 years?');
				}
			}
		}
	}
);

$(window).resize(function () {
		// Hintergrundbild anpassen
		$("#backgroundImage img").setSizeAndPositionOfBackgroundImage();
		$("#backgroundImage2 img").setSizeAndPositionOfBackgroundImage();
});


var sectionInUrl = 	function(section) {
	var s = location.href.split("#");
	if (s[1] && s[1] == section) return true;
	return false;
};


(function($) {
	/**
	Inhaltsspalte zum aus- und zuklappen
	*/
	$.fn.animateContent = function(options){
		var defaults = {
			posShow: 0,
			posHide: "-968px",
			speedShow: 800,
			speedHide: 800,
			btnShowObj: "#btnShow",
			btnHideObj: "#btnHide",
			toTopObj: "#toTop",
			backgroundImgObj: "#backgroundImage img",
			linkSelector: 'a[target!="_blank"]'
		};
		var c = $.extend(defaults, options);
		var obj
		var btnShowObj = (typeof c.btnShowObj == "object") ? c.btnShowObj : $(c.btnShowObj);
		var btnHideObj = (typeof c.btnHideObj == "object") ? c.btnHideObj : $(c.btnHideObj);
		var toTopObj = (typeof c.toTopObj == "object") ? c.toTopObj : $(c.toTopObj);
		var backgroundImgObj = (typeof c.backgroundImgObj == "object") ? c.backgroundImgObj : $(c.backgroundImgObj);
		var linksObj = $(c.linkSelector);
		
		var fn = {
			showContent: function () {
				backgroundImgObj.fadeIn(c.speedShow);
				obj.animate( {	'left': c.posShow }, c.speedShow, function () { toTopObj.show(); btnHideObj.unbind("click").show().click( function () { btnHideObj.hide(); toTopObj.hide(); fn.hideContent(); } ); });
			},
			hideContent: function () {
				backgroundImgObj.fadeOut(c.speedShow);
				obj.animate( { 'left': c.posHide }, c.speedHide, function () {  btnShowObj.unbind("click").show().click( function () { btnShowObj.hide(); fn.showContent(); } ); } );
			},
			hideContentAndGetUrl: function (href) {
				backgroundImgObj.fadeOut(c.speedShow);
				obj.animate( { 'left': c.posHide }, c.speedHide, function () {  btnShowObj.unbind("click").show().click( function () { btnShowObj.hide(); fn.showContent(); } ); location.href = href; } );
			}
		};
		
		this.each(function() {
				backgroundImgObj.hide();
				
				obj = $(this);
				fn.showContent();
				
				linksObj.each(function () {
					var currentLinkObj = $(this);
					var href = currentLinkObj.attr("href");
					if (href && href.indexOf("#") != 0 && href.indexOf("javascript".toLowerCase()) != 0 && !currentLinkObj.attr("onclick")){
						currentLinkObj.click(function () {
								btnHideObj.hide();
								toTopObj.hide();
								fn.hideContentAndGetUrl(href);
								return false;
						});
					}
			});
		});
		return this;
	};
	
	/**
	Bildgroessenanpassung
	*/
	$.fn.setSizeAndPositionOfBackgroundImage = function(options) {
		var defaults = {
			imgW: 0,
			imgH: 0,
			imgMinW: 0,
			imgMinH: 0,
			containerW: $(window).width(),
			containerH: $(window).height()
		};
		var c = $.extend(defaults, options);
		var obj;
		var imgObj = new Image();
		
		var fn = {
			main: function (obj) {
				if(c.containerW / c.containerH > c.imgW / c.imgH) {
					newW = c.containerW;
					newH = c.containerW/c.imgW*c.imgH;
				} else {
					newW = c.containerH/c.imgH*c.imgW;
					newH = c.containerH;
				}
				
				// test minsize
				if (newW < c.imgMinW && newH < c.imgMinH) {
					newW = c.imgMinW;
					newH = c.imgMinH;
				}
				
				// set imagesize
				obj.width(newW);
				obj.height(newH);
			},
			
			checkImageIsLoaded: function (obj) {
				if (imgObj.complete){ // Bild fertig geladen
					c.imgW = imgObj.width;
					c.imgH = imgObj.height;
					c.imgMinW = imgObj.width;
					c.imgMinH = imgObj.height;
					fn.main(obj);
				} else {
					window.setTimeout(function () { fn.checkImageIsLoaded(obj); }, 100);
				}
			},
			
			lastObjectEntryToAvoidToForgetTheLastKommata: function () {}
		};
		this.each(function() {
				obj = $(this);
				
				if (c.imgW == 0 || c.imgH == 0){
					imgObj.src = obj.attr("src");
					fn.checkImageIsLoaded(obj);
				} else {
					fn.main(obj);
				}
				
		});
		return this;
	};
	
	
	/**
	Focus- und Focusout-Event auf Input - loescht/setzt den Standardwert
	*/
	$.fn.handleInputValue = function(options) {
		var defaults = {
			value: '',
			setValueIfEmpty: false
		};
		var c = $.extend(defaults, options);
		var obj, val, btnObj;
		this.each(function() {
				obj = $(this);
				if (!c.value) return;
				if (!obj.val() && c.setValueIfEmpty) obj.val(c.value);
				obj.focus(function () { if (obj.val() == c.value) obj.val(""); })
				obj.focusout(function () { if (obj.val() == "") obj.val(c.value); })
		});
		return this;
	};

	
})(jQuery);


