// layout
	jQuery(function () {
	  // image preloader
	    var preloader = jQuery('<div id="dynamicPreloaderContainer" style="position:absolute; display:none;" />').prependTo('body');
		// opacities
			jQuery('#footerBottomBorder').css('opacity', 0.3);
		// browser fixes
			if (jQuery.browser.safari) jQuery('div.homePage .teaserColumn .contentBlockFooter').css('width', '100%');
		// home teasers should have the same height
			  var h = 0;
				jQuery('div.homePage .teaserColumn .contentBlockBody').each(function () {
				  var me = jQuery(this);
				  me.append('<div class="stopFloat">&nbsp;</div>');
				  var myH = me.height();
					if (myH > h)
					  if (me.prev().is('.contentBlockHeader')) h = myH;
					  else h = myH - 18;
				});
				jQuery('div.homePage .teaserColumn')
					.find('.contentBlock:has(.contentBlockHeader) .contentBlockBody').height(h).end()
					.find('.contentBlock:not(:has(.contentBlockHeader)) .contentBlockBody').height(h + 18);
		// "filler" within block-headers and -footers
			jQuery('.blockFiller').each(function () {
			  var me = jQuery(this);
			  var l = 0;
			  var r = 0;
			  var meFound = false;
			  var rEls = [];
			  me.parent().children(':not(.stopFloat)').each(function () {
					if (jQuery(this).is('.blockFiller')) meFound = true;
					else if (meFound) {
						r += jQuery(this).outerWidth(true);
						rEls.push(jQuery(this));
					} else l += jQuery(this).outerWidth(true);
				});
				// necessary because of firefox on mac
					var rElContainer;
					jQuery.each(rEls, function (i) {
					  if (!rElContainer) {
							rElContainer = jQuery('<div style="position:absolute;" />');
							jQuery(this).parent().prepend(rElContainer);
							rElContainer.css({
								width: r + 'px',
								'margin-left': (jQuery(this).parent().width() - r) + 'px'
							});
						}
						jQuery(this).appendTo(rElContainer);
					});
				me.css({
					'margin-left': l + 'px',
					'margin-right': r + 'px',
					'float': 'none',
					'display': 'block'
				});
			});
		// special classes
		  jQuery('p:last-child').addClass("lastP");
		  jQuery('.shortContentColumn .contentBlockBody').children(':last-child').addClass("lastContentRow");
		// striped tables
			jQuery('table tbody').each(function () { // separate handling in function for each table is necessary because otherwise it would not work correctly for cascaded tables
				jQuery(this).children()
					.filter(':even').children().addClass('even').filter(':first-child').addClass('firstTdInRow').end().end().end()
			  	.filter(':odd').children().addClass('odd').filter(':first-child').addClass('firstTdInRow');
			});
		// form
			jQuery('form').each(function () {
				jQuery(this)
					.find('div.field')
						.filter(':even').addClass('even').end().filter(':odd').addClass('odd').end()
						.filter(':has(div.middleColumn:has(span.smallText))').removeClass('even').removeClass('odd').addClass('formInfoRow').end()
						.append('<div class="stopFloat">&nbsp;</div>');
			});
		// browser fixes
			if (jQuery.browser.safari) jQuery('.stopFloat').height(0);
			if (jQuery.browser.msie && jQuery.browser.version < 8) {
			  jQuery('.stopFloat').height(0);
				jQuery('form .stopFloat').height(1);
	 		}
			if (jQuery.browser.safari || jQuery.browser.mozilla) {
				jQuery('a img:not([align])').attr('align', 'absbottom');
				jQuery('.pagingFooter a img[align=absbottom]').removeAttr('align');
	 		}
		// h3 tags should be displayed inline and with a left margin/padding
			jQuery('.contentBlockBody h3').each(function () {
				var me = jQuery(this);
		  	var tester = jQuery('<div style="position:absolute;" />').append(me.clone()).appendTo(me.parent());
				me.wrap('<div class="h3Wrapper" style="width:' + (tester.width() + 10) + 'px;" />');
				tester.remove();
			});
		// form
			jQuery('form legend + .h3Wrapper').addClass('firstFormH3Wrapper');
		// top image with text overlay
			var visImg = jQuery('#visualImageContainer img');
      if (visImg.length) {
				var footerHeight = jQuery('#topMediaContainer .contentBlockFooter').height();
        var imagePadding = parseInt(jQuery('#topMediaContainer .contentBlockBody').css("padding-top").replace('px','')) + parseInt(jQuery('#topMediaContainer .contentBlockBody').css("padding-bottom").replace('px',''));
				var loader = jQuery('<div />').appendTo('body');
				jQuery('<img src="' + visImg.attr('src') + '" style="display:none;" />').bind('load', function () {
          jQuery('.pageTitle1Bg').height(jQuery(this).height() + imagePadding + footerHeight);
          visImg.parent().height(jQuery(this).height());
          loader.remove();
				}).appendTo(loader);
			}
		// behaviours
		  jQuery('a.disabled').bind("click", function () { return false; });
		  jQuery('#searchField input:first').bind('focus', function () {
		    var me = jQuery(this);
				if (!me.data('searchText')) me.data('searchText', me.val());
				if (me.val() == me.data('searchText')) me.val('');
			}).bind('blur', function () {
		    var me = jQuery(this);
				if (me.val() == "") me.val(me.data('searchText'));
			});
			// video / image toggler
			  var me = jQuery('img[showimagetext]');
				if (me.length) {
				  var videoImageSlideDuration = 400;
				  me.attr('title', me.attr('showimagetext'));
				  me.data("imageActive", false);
				  preloader.append('<img src="' + me.attr("src").replace("/topMediaClose.gif", "/topMediaOpen.gif") + '" />');
				  var moviePlayer, visualImage, bothContainer;
				  me.bind('click', function () {
						if (!me.data('initialized')) {
						  moviePlayer = jQuery('#moviePlayer').parent();
						  visualImage = jQuery('#visualImage');
						  bothContainer = visualImage.parents('.contentBlockBody');
						  // sizes
						    moviePlayer.data('size', moviePlayer.outerHeight());
						    visualImage.data('size', visualImage.outerHeight());
								bothContainer.data('addSize', 0); // bothContainer.data('addSize', bothContainer.outerHeight() - bothContainer.find('div:visible:first').outerHeight());
						  bothContainer.height(bothContainer.find('div:visible:first').outerHeight() + bothContainer.data('addSize'));
						  me.data('initialized', true);
					  }
				    me.trigger('mouseout');
				    if (me.data("imageActive")) {
				      visualImage.hide(0.1, function () {
								bothContainer.animate({height: moviePlayer.data('size') + bothContainer.data('addSize')}, videoImageSlideDuration, function () {
				        	moviePlayer.show();
						      me.attr('title', me.attr('showimagetext'));
					  			me.data('title', me.attr('title'));
						      me.data("imageActive", false);
						      me.attr("src", me.attr("src").replace("/topMediaOpen.gif", "/topMediaClose.gif"));
								});
							});
				    } else {
				      moviePlayer.hide(0.1, function () {
								bothContainer.animate({height: visualImage.data('size') + bothContainer.data('addSize')}, videoImageSlideDuration, function () {
					        visualImage.show();
									me.attr('title', me.attr('showvideotext'));
					  			me.data('title', me.attr('title'));
						      me.data("imageActive", true);
						      me.attr("src", me.attr("src").replace("/topMediaClose.gif", "/topMediaOpen.gif"));
								});
							});
						}
					});
				}
	 	// link text in inline popup
	 		var descriptionPopup = jQuery('<div id="descriptionPopup"><div class="descriptionPopupLeft" /><div class="descriptionPopupRight" /></div>').prependTo('body');
			jQuery('.contentBlockHeader a img, .contentBlockFooter a img').bind('mouseover', function () {
			  var me = jQuery(this);
			  if (!me.attr('title') || !me.attr('title').length) return;
			  me.data('title', me.attr('title'));
			  me.attr('title', '');
				descriptionPopup
					.find('.descriptionPopupRight').html('<div>' + me.data('title') + '</div>').end()
					.show().css({
						top: me.offset().top - descriptionPopup.height() + 8,
						left: me.offset().left + me.width() - descriptionPopup.width() + 13
					});
			}).bind('mouseout', function () {
				descriptionPopup.hide();
				jQuery(this).attr('title', jQuery(this).data('title'));
			});
		// features
		  // home: latest News
		    if (jQuery('.latestNewsBlock').length > 1) {
		      var toggleLastNewsFadeTime = 500;
		      var toggleLastNewsDelay = 5000;
		      var aktNewsItem = jQuery('.latestNewsBlock:first');
			    aktNewsItem.parent().append(aktNewsItem.clone().empty().addClass('latestNewsBlockPlaceHolder'));
			    jQuery('.latestNewsBlock').add(aktNewsItem.parent()).css({
						'height': aktNewsItem.height() + 'px',
						'width': aktNewsItem.width() + 'px',
						'overflow': 'hidden'
					}).end().filter(':not(.latestNewsBlockPlaceHolder)').css('position', 'absolute');
				  var toggleLastNews = function () {
					  var nextNewsItem = aktNewsItem.next().is('.latestNewsBlockPlaceHolder') ? jQuery('.latestNewsBlock:first') : aktNewsItem.next();
				    aktNewsItem.fadeOut(500, function () {
					    nextNewsItem.fadeIn(500, function () {
					      aktNewsItem = nextNewsItem;
								window.setTimeout(toggleLastNews, toggleLastNewsDelay);
							});
						});
					};
					window.setTimeout(toggleLastNews, toggleLastNewsDelay);
				}
		// flash
		  if (jQuery('#productChooser').length) {
		    var chooserDiv = jQuery('#productChooser');
		    chooserDiv.wrap('<div style="height:' + chooserDiv.css('height') + ';"></div>');
				swfobject.embedSWF("/themes/speag/flash/productChooser.swf", "productChooser", "954", "364", "9.0.115", "/mysite/swf/expressInstall.swf", {
					dataXmlPath: '/home/getTeaserXML'
				}, {
					menu: "false",
					wmode: "transparent"
				});
			}
		  if (jQuery('#moviePlayer').length) {
		    var playerDiv = jQuery('#moviePlayer');
		    playerDiv.wrap('<div style="height:' + playerDiv.css('height') + ';"></div>');
				swfobject.embedSWF("/themes/speag/flash/moviePlayer.swf", "moviePlayer", "934", "314", "9.0.115", "/mysite/swf/expressInstall.swf", {
					dataXmlPath: playerDiv.attr("URLSegment") + 'getTeaserXML'
				}, {
					menu: "false",
					wmode: "transparent"
				});
			}
	});