$(document).ready(function(){
	/* fix markit module "stop on mouseover" bug */
	$(".DnnModule-MarkitSlideShow img").hover(function(e){ e.stopPropagation();e.preventDefault(); });
													 
	/* Mega Menu hover fix for IE6 */
	if($.browser.msie && $.browser.version == 6)
		$("#NavMain>li").hover(function() { $(this).addClass("Hover"); }, function() { $(this).removeClass("Hover"); })
													 
	/* Center Banner Image */
	/*$("#BannerWrapper img").load(function() {
		HalfWidth = $("#BannerWrapper img").width()/2;
		$("#BannerWrapper img").css("margin-left", -HalfWidth);
	});*/

	$("#BannerWrapper img:first").each(function() {
		pic = new Image();
		pic.src = $(this).attr("src");
		if(pic.complete) {
			HalfWidth = pic.width/2;
			$(".ContainerBanner").css("margin-left", -HalfWidth);
		}
		else
		{
			pic.onload = function() {
				HalfWidth = pic.width  /2;
				$(".ContainerBanner").css("margin-left", -HalfWidth);
			};
		}
	});
	
	/* home link box */
	$(".ContainerHomeLinkBox li a:odd").addClass("odd");
	
	/* team overview */
	$(".TeamOverview a").each(function(){
		$(this).attr("title",$("img", this).attr("alt") ).tooltip({showURL: false, track: true, delay: 0});
	});	
	
	
	/* display only specific team categories in footer sitemap */
	$("#FooterSitemap ul.CategoryId117 li").not(".ParentId117").remove();
	$("#Nav144>span, #Nav143>span").html("");
	
	/* alignment of mega menu for different tabs */
	$(".MegaMenuWrapper").each(function() { $(this).width((920 - ($(this).parent("li").offset().left - $("#nav .page").offset().left)) + 50 + "px"); });

 $(".MegaMenuWrapper").mouseover(function(){$(this).prev("a").addClass("hover");}).mouseout(function(){$(this).prev("a").removeClass("hover");});
 
 /* Suchfeld-Anpassungen */
 $("input[id$='_SearchInput_imgGo']").hover(function() { $(this).attr('src', '/images/search_start_hover.gif'); }, function() { $(this).attr('src', '/images/search_start.gif'); });
});

/* Main Menu */

																		 
function ReorderMegaMenu(){
	/*var MegaMenu = [
		[ "#Nav58", [ 2, 1, 2, 2 ] ],
		[ "#Nav59", [ 1, 1, 1, 1 ] ]
	];*/
	
	$(MegaMenu).each(function(i,e) {
			$(e[1]).each(function(i1,e1) {
				$(e[0] + " .ListItemsWrapper").append("<li class='Col" + (i1 + 1) + "Wrapper ColWrapper'><ul /></li>");
				for(var c = 0; c < e1; c++)
				{
					$("#NavMain " + e[0] + " .ListItemsWrapper>li.Level1:first").appendTo(e[0] + " .ListItemsWrapper .Col" + (i1 + 1) + "Wrapper>ul");
				}
			});
			
	});          
	
	}
	
/* Footer Sitemap */

function ReorderFooterSitemap(){
	$(FooterMenu).each(function(i,e) {
		$("#SitemapCol" + (i + 1) + "Wrapper").append($("<ul />"));
		for(var c = 0; c < e; c++)
		{
			$("#FooterSitemap>li:first").appendTo($("#SitemapCol" + (i + 1) + "Wrapper>ul"));
		}
	});          
	
	/* split pages of "Behandlungsangebote" into 2 columns */
	var HalfLength = $("#SitemapCol1Wrapper ul.CategoryId77 li").size()/2; 
	var HalfLength = Math.round(HalfLength);
	$("#SitemapCol1Wrapper ul.CategoryId77 li:gt(" + HalfLength + ")").addClass("Col2Element");
	$("#SitemapCol2Wrapper").append("<ul><li><ul /></li></ul>");
	$("#SitemapCol1Wrapper ul.CategoryId77 li.Col2Element").prependTo($("#SitemapCol2Wrapper ul li ul"));
	
	$(".FooterTab59>a").html("Zahn&auml;rzte");
}

