$(document).ready(function(){
	$(".ContainerRightPane ul li:last").addClass("LastChild");			
	
	/* Links in Slideshow on Home */
	$(".slide .mss_conent").each(function() { $("a", this).each(function(i,e) { $(this).addClass("link" + i); }); });
	$(".slide .mss_conent table").each(function(i,e) { $(this).addClass("slidetext"); $("td", this).each(function(i,e) { $(this).addClass("slidetext" + i); }); });
	
	/* Cols on Home */
	$(".Tab39 .HomeCol").hover(function() { $(this).addClass("HomeColHover"); }, function() { $(this).removeClass("HomeColHover"); })
		.click(function() { window.location.href = $(".Normal a", this).attr("href"); });
	
	// MegaMenuWrapper 
	$("#NavMain>li").hoverIntent({
		over: function() {
			$(".MegaMenuWrapper, .MegaArrow", this).fadeIn('fast');
			$(this).addClass("Hover");
			},
		out: function() {
			$(".MegaMenuWrapper, .MegaArrow", this).fadeOut('fast');
			$(this).removeClass("Hover");	
		},
		timeout:300
	});
	
	PositionMegaMenu();
	
	/* Newline "Branchenlösungen" */
	$("#footer #Nav72>a").html("Branchen- l&ouml;sungen").next("ul").css('margin-top', $.browser.msie ? '6px' : '5px');
});

function PositionMegaMenu()
{
	$(".MegaMenuWrapper").each(function() {
		/* Set Width */
		var ChildrenCount = $(this).children("ul").children("li").length;
		if(ChildrenCount > 4)
			ChildrenCount = 4;
		
			$(this).css('width', ((ChildrenCount * 220) + 5) + "px");
			
		if($.browser.msie && $.browser.version < 7)
		{
			$(this).css({'width': '920px', 'zoom': '1'});
		}
		
		/* Set Position */
		$(this).show();
		var Par = $(this).parent("li");
		var sum = 0;
		$("#NavMain>li:lt(" + $(Par).index() + ")").each(function(i,e) { sum += $(this).outerWidth(); });
		var MoveLeft = sum - ($(this).outerWidth() / 2) + ($(Par).children("a").outerWidth() / 2);
		$(this).css('left', MoveLeft + 'px');
		
		/* If Menu is over the 965px borders, align the menu correctly */
		var RightDiff = ($(this).offset().left + parseInt($(this).css("width"))) - ($("#main .page_margins").offset().left + parseInt($("#main .page_margins").css("width"))) + 40;
		if(RightDiff > 0)
		{
			$(this).css('left', (MoveLeft - RightDiff) + 'px');
		}
		
		var LeftDiff = $(this).offset().left - $("#main .page_margins").offset().left;
		if(LeftDiff < 0)
			$(this).css('left', (MoveLeft - LeftDiff) + 'px');
		$(this).hide();
	});
}
