$(document).ready(function() 
{
	$('#subLinks li img, #mainLinks li img').hover(function()
	{
		src =  $(this).attr('src');
		baseSrc = src;
		src = src.replace('-hover.png', '.png');
		hover = src.replace('.png', '-hover.png');
		$(this).attr('src', hover);
		$(this).attr('oSrc', hover);
		$(this).css("filter", $(this).css('filter').replace('-hover.png', '.png'));
		$(this).css("filter", $(this).css('filter').replace('.png', '-hover.png'));
		count = 0;
		liData = $(this).parent().parent();	
		$(this).parent().parent().parent().children().each(function()
		{
			if($(this).html() == liData.html() && liData.parent().attr('id') == "subLinks")
			{
				$('#subSubLinks').children().each(function()
				{
					if($(this).hasClass('groep' + count))
					{
						$(this).css("display", "inline");
					}
					else 
					{
						$(this).css("display", "none");
					}
				});
			}
			else
			{
				count++;
			}
		});
	}, function()
	{
		src =  $(this).attr('src');
		hover = src.replace('-hover.png', '.png');
		$(this).attr('src', hover);
		$(this).attr('oSrc', hover);
		$(this).css("filter", $(this).css('filter').replace('-hover.png', '.png'))
		activeLink();
	});
	
	function activeSubLinks(page)
	{
		$("#subLinks li a img").each(function()
		{
			srcData = $(this).attr('src').split("/");
			srcLink = srcData[(srcData.length-1)];
			
			srcLink = srcLink.replace("menu-", "");
			srcLink = srcLink.replace(".png", "");
			
			if(srcLink == page)
			{
				$(this).attr("src", $(this).attr("src").replace(".png", "-hover.png"));
				$(this).attr('oSrc', $(this).attr("src").replace(".png", "-hover.png"));
				$(this).css("filter", $(this).css('filter').replace('.png', '-hover.png'))
			}
		});
	}
	
	var activeOnce = true;
	function activeLink()
	{
		urlData = document.location.href.split("/");
		page = urlData[(urlData.length - 1)];
		page = page.replace(".html", "");
		page = page.replace(".php", "");
		page = page.replace(/_/g, "");
		
		
		activeSubLinks(page);
		
		$("#subSubLinks li a").each(function()
		{
			hrefData = $(this).attr('href').split("/");
			hrefLink = hrefData[(hrefData.length-1)];
			hrefLink = hrefLink.replace(".html", "");
			hrefLink = hrefLink.replace(/_/g, "");
			
			hrefParent = hrefData[(hrefData.length-2)];
			hrefParent = hrefParent.replace(/_/g, "");
			
			if(hrefLink == page)
			{
				activeSubLinks(hrefParent);	
				if(activeOnce)
				{
					$(this).css("color", "#fff");
					groupClass = $(this).parent().attr('class');
					$("." + groupClass).css("display", "inline");
					activeOnce = false;
				}
			}
	
			
		});
	}
	
	
	
	activeLink();
});

$('.box-placeholder a').each(function()
{
	if($(this).attr('href').substring(0, 1) == "#" && $(this).attr('href').substring(0, 6) != "#popup") 
	{
		$(this).removeAttr('target');
		$(this).click(function()
		{
			window.open('/popup/websitepopup' + $(this).attr('href').substring(1) + '.html','mywindow' +  $(this).attr('href').substring(1),'width=500,height=400');
		});
	}
});

$(".buttonLeft, .buttonRight, .button-submit-holder, .buttonReact").hover(function()
{
	$(this).addClass("active" + $(this).get(0).className);
	$(this).css("color", "#66400c");
	$(this).children().css("color", "#66400c");
}, function() {
	$(this).removeClass("active" + $(this).get(0).className);
	$(this).css("color", "#000");
	$(this).children().css("color", "#000");
});

$("img").each(function()
{
	imgSrcParts = $(this).attr('src').split("/");
	imgName = imgSrcParts[imgSrcParts.length-1];
	
	if(imgName == "magazine_146x30.png")
	{
		$(this).css("behavior", "url(/script/iepngfix.htc)");
		$(this).hover(function()
		{
			$(this).attr('src', "/images/buttons/bestellen-active.png");
			$(this).css('width', '150px');
			$(this).css('height', '34px');
		}
		, function() 
		{
			$(this).attr('src', "/images/magazine_146x30.png");
			$(this).css('width', '146px');
			$(this).css('height', '30px');
		});
	}
	
	if(imgName == "videos_146x30.png")
	{
		$(this).css("behavior", "url(/script/iepngfix.htc)");
		$(this).hover(function()
		{
			$(this).attr('src', "/images/buttons/videos-active.png");
			$(this).css('width', '150px');
			$(this).css('height', '34px');
		}
		, function() 
		{
			$(this).attr('src', "/images/videos_146x30.png");
			$(this).css('width', '146px');
			$(this).css('height', '30px');
		});
	}
});
