$(function(){
		/*$('.screenshotList-Link').attr('rel', 'lightbox');*/
	
		function megaHoverOver(){
			
			$(this).find(".sub").stop().fadeTo('fast', 1).show();
			$(this).find(".sub-right").stop().fadeTo('fast', 1).show();
			$(this).find(".sub-center").stop().fadeTo('fast', 1).show();
			$(this).find(".sub-shadow-bottom").stop().fadeTo('fast', 1).show();
			
			
			//Calculate width of all ul's
			(function($) { 
				jQuery.fn.calcSubWidth = function() {
					rowWidth = 0;
					ulHeightMax = 0;
					//Calculate row
					$(this).find("ul > li ul").each(function() {					
						/* rowWidth += $(this).width();*/
						rowWidth += $(this).outerWidth();
						
						if (ulHeightMax < $(this).outerHeight()){
							ulHeightMax = $(this).outerHeight();
						}	
						
	
					});	
				};
			})(jQuery); 
			
			(function($) { 
				jQuery.fn.updateHeight = function() {
					ulHeight = 0;
					ulHeightMax = 0;
						
					
					//Calculate row
					$(this).find("ul .subLink").each(function() {					
						/* rowWidth += $(this).width();*/
						ulHeight = $(this).outerHeight();
						if(ulHeight > 32) {
							 $(this).css({'height' : 56});
						}
					});	
				};
			})(jQuery);
			
			(function($) { 
				jQuery.fn.updateImg = function() {
		
					var test = $(this).children()[0];
					
					if ($(test).attr("id").indexOf("-active")<1){
						img = $(test).css('background-image');
						if (img.indexOf("_2")>0){
							img = img.replace("_2","_1");
						}else {
							img = img.replace("_1","_2");
						}
						img = $(test).css({'background-image' : img});
					}	
				};
			})(jQuery); 
			
		
			$(this).updateHeight();
			$(this).updateImg();
			
			if ( $(this).find(".row").length > 0 ) { //If row exists...
				var biggestRow = 0;	
				//Calculate each row
				$(this).find(".row").each(function() {		
					$(this).calcSubWidth();
					//Find biggest row
					if(rowWidth > biggestRow) {
						biggestRow = rowWidth;
					}
				});
				//Set width
				$(this).find(".sub").css({'width' :biggestRow});
				$(this).find(".row:last").css({'margin':'0'});
				
			} else { //If row does not exist...
				
				$(this).updateHeight();
				$(this).calcSubWidth();
				//Set Width
				if(rowWidth < 100) {
					 $(this).find(".sub").stop().fadeTo('fast', 0, function() {
						  $(this).hide(); 
					  });
					 $(this).find(".sub-right").stop().fadeTo('fast', 0, function() {
						  $(this).hide(); 
					  });
					 $(this).find(".sub-shadow-bottom").stop().fadeTo('fast', 0, function() {
						  $(this).hide(); 
					  });
					 $(this).find(".sub-center").stop().fadeTo('fast', 0, function() {
						  $(this).hide(); 
					  });
				}else {
					
					
					
					/* 1. Berechnen Pfeil*/
					
					var _sub = $(this).find(".sub");
					var _subEntry = $(this).find(".subEntry");
					
					var _menuoffset = _sub.offset();
					var _menuleft =  _sub.offset().left;
					var _menutop = _sub.offset().top;
					var _menuwidth = _menuleft + rowWidth;
					var _navileft = $('#navigationFirstLevelMenu').offset().left;
					var _naviwidth = parseFloat($('#navigationFirstLevelMenu').css("width"), 10);
					
					var _max = _navileft + _naviwidth;
					
					if (_menuwidth > _max){
						var _diff = _menuwidth   - _max - 20;
						_diff = _menuleft -_diff ; 
						_sub.offset({ top: _menutop, left: _diff});						
					}else{
						_diff = _menuleft;
					}
					
					/* Breite setzten */
					_sub.css({'width' : rowWidth});
					
					
					
					var _divBottom = $(this).find(".sub-shadow-bottom");
					var _bottomTop = _sub.outerHeight() + _menutop;
					var _bottomLeft = _diff;
					
					_divBottom.offset({ top: _bottomTop, left: _bottomLeft});
					_divBottom.css({'width' : _sub.outerWidth()});
					
					var _divBottomCenter = $(this).find(".sub-shadow-center");
					_divBottomCenter.css({'width' : _sub.outerWidth() - 8});
					_divBottomCenter.offset({ top: _bottomTop, left: _bottomLeft + 8});
					
					var _divBottomRight = $(this).find(".sub-shadow-bottom-right");
					_divBottomRight.offset({ top: _bottomTop , left: _bottomLeft + _sub.outerWidth()});
					
					var _divRight = $(this).find(".sub-right");
					var _rightTop = _menutop;
					var _rightLeft = _sub.outerWidth() + _sub.offset().left;
					_divRight.offset({ top: _rightTop, left: _rightLeft});
					_divRight.css({'height' : _sub.outerHeight()});
					
					
					var _divRightCenter = $(this).find(".sub-shadow-right");
					_divRightCenter.css({'height' : _sub.outerHeight() - 8});
					
				}
				
				
			}
		}
		
		function megaHoverOut(){
			
		  $(this).updateImg();	
		  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
			  $(this).hide(); 
		  });
		  $(this).find(".sub-right").stop().fadeTo('fast', 0, function() {
			  $(this).hide(); 
		  });
		  $(this).find(".sub-shadow-bottom").stop().fadeTo('fast', 0, function() {
			  $(this).hide(); 
		  });
		  $(this).find(".sub-center").stop().fadeTo('fast', 0, function() {
			  $(this).hide(); 
		  });
		}


		var config = {    
			 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 2, // number = milliseconds for onMouseOver polling interval    
			 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
			 //timeout: 300, // number = milliseconds delay before onMouseOut
			 timeout: 100, // number = milliseconds delay before onMouseOut
			 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
		};

		$("ul#topnav li .sub").css({'opacity':'0'});
		$("ul#topnav li").hoverIntent(config);
		
		
		$(".screenshotList-Link").each(function() {
			$(this).fancybox();
		}); 
		
		$(".videoList-Link").each(function() {
			$(this).fancybox({
				'padding'		: 0,
				'autoScale'		: true,
				'transitionIn'   : 'fade',
				'transitionOut'   : 'fade',
		
				'onStart'	:	function() {
				$("#videoPlay").css({'display':'block'});
				
				},
				'onCleanup'	:	function() {
					$("#videoPlay").css({'display':'none'});
				}
			});
		}); 
		/* Using custom settings */
		$("a#KontaktForm").attr({"href": "#contactForm"}).fancybox({
			'padding'		: 0,
			'autoScale'		: true,
			'width'			: 550,
			'height'		: 570,
			'autoDimensions': true,
			'transitionIn'   : 'fade',
			'transitionOut'   : 'fade',
			'onStart'	:	function() {
				$("#contactForm").show();
			},
			
			'onCleanup'	:	function() {
				$("#contactForm").css('display','none');
			}
		});
		
		/* Using custom settings */
		$("a#InformationsForm").attr({"href": "#infoForm"}).fancybox({
			'padding'		: 0,
			'autoScale'		: true,
			'width'			: 550,
			'height'		: 570,
			'autoDimensions': true,
			'transitionIn'   : 'fade',
			'transitionOut'   : 'fade',
			'onStart'	:	function() {
				$("#infoForm").css({'display':'block'});
			},
			'onCleanup'	:	function() {
				$("#infoForm").css({'display':'none'});
			}
		});
		
		/* Using custom settings */
		$("a#AnmdeldeForm").attr({"href": "#anmeldeForm"}).fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'width'			: 800,
			'height'		: 600,
			'transitionIn'   : 'fade',
			'transitionOut'   : 'fade',
			'onStart'	:	function() {
			$("#anmeldeForm").css({'display':'block'});
					
			},
			'onCleanup'	:	function() {
				$("#anmeldeForm").css({'display':'none'});
			}
		});
		
		/*
		$("a#show_praesentation").fancybox({
			'showCloseButton' : 'true',
			'overlayOpacity' : 0.5,
			'overlayColor' : '#000',
			'frameWidth' : 650,
			'frameHeight' : 600,
			'hideOnContentClick': false
		});
		$(this).find('a#show_praesentation').each(function() {
			$("a#show_praesentation").trigger("click");
		});
		*/
		
		$(this).find('.errorInfo').each(function() {
			$("a#InformationsForm").trigger("click");
		});
		
		$(this).find('.errorLstAnmeldung').each(function() {
			$("a#AnmdeldeForm").trigger("click");
		});
		
		$(this).find('.errorLst').each(function() {
			$("a#KontaktForm").trigger("click");
		});
		if ($('.div-headerText').length)
		{
			var htmlHeaderText = '<div class="div-headerText">'+$('.div-headerText').html()+'</div>';
			$('.div-headerText').remove();
			$('#div-logo').append(htmlHeaderText);
		}
		
		if (!$.browser.msie){
			$(".div-headerText").hide();
			$(".div-headerText").fadeTo(2000,1,function(){
				if ($.browser.msie){
					this.style.removeAttribute("filter");
				}
			});
		}
		
		$('#navigationFirstLevelMenu').corner("tr br");
		
		$('.webcode-idle').focus(function() {  
		$(this).removeClass("webcode-idle").addClass("webcode-focus");  
		if (this.value == "WEBCODE"){  
		    this.value = '';  
		    }  
		    if(this.value != "WEBCODE"){  
		        this.select();  
		    }  
		});  
	    
		$('.webcode-idle').blur(function() {  
			$(this).removeClass("webcode-focus").addClass("webcode-idle");  
			if ($.trim(this.value) == ''){  
				this.value = "WEBCODE";  
			}  
		}); 
		
		// größer korregieren 
		var _content = $('#div-content');
		var _height = $('#div-content').outerHeight();
		var _offset = _content.offset();
		var _top = _content.offset().top;
		_height = _height + _top ;
		
		var htmlheight = parseFloat($('html').css("height"), 10);
				
		if (_height < htmlheight){
			_height = htmlheight; 
		}
		
		$("html").css({'height':_height});
		$("body").css({'height':_height});
		
		var minHeight = $('#div-spalteRechts').outerHeight()+50;
		if (minHeight < 500) minHeight = 500;
		$('#div-content').css('min-height', minHeight+'px');
		
		
});

