$(document).ready( function () {



	if($('#afdelingen').length > 0){
		var talest = 0;
		$('#afdelingen li .bg').each(function(){
			
			if($(this).height() > talest)
			{
				talest = $(this).height();
			}

		});

		if(talest > 0)
		{
			$('#afdelingen li .bg').css('height', talest);
		}
	}

	if($('#sitemap').length > 0){
		var talest = 0;
		$('#sitemap > ul > li').each(function(){
			
			if($(this).height() > talest)
			{
				talest = $(this).height();
			}

		});

		if(talest > 0)
		{
			$('#sitemap > ul > li').not('.paginas').css('height', talest);
		}
	}	
		
		$('.show_form1').click(function(e){
			$('#frame2').show();
			$('#leftNavigationContainer').css('height', $('#frame2').height());
			$("#frame2").contents().find('form').submit(function(){
				$('html, body').animate({ scrollTop: 0 }, 0);
			});
			$('#afdelingen').hide();
		});

		$('.show_form2').click(function(e){
			$('#frame3').show();
			$('#leftNavigationContainer').css('height', $('#frame2').height());
			$("#frame3").contents().find('form').submit(function(){
				$('html, body').animate({ scrollTop: 0 }, 0);
			});
			$('#afdelingen').hide();
		});

	$('#afdelingen.afdelingen .info').hide();

	$('#afdelingen.afdelingen .vacature_titel').click(function(){
		$('#afdelingen.afdelingen .info:visible').slideUp();
		$(this).parent().find('.info').slideDown();
	});

	$('#medewerkers li span').click(function(){
			var info = $(this).parent().find('.info');
			
			if($(info).is(':visible'))
			{
				$(info).animate({
					width: 'hide'
				});
			}
			else
			{
				$('#medewerkers li .info').hide();
				$(info).animate({
					width: 'show'
				});
			}

	});

	Cufon.replace('h1, h2, .producten h3, #product th, #afdelingen .vacature_titel, #medewerkers h3, #personalia strong, #timeline #dates li');
	
	$("#kaart a").click( function (e) {
	
			e.preventDefault();

			var vestiging_id = $(this).attr('rel');

			if($('#vestiging div:visible').length > 0 && $('#vestiging div:visible').attr('id') != 'vestiging-' + vestiging_id)
			{
				$('#vestiging div:visible').slideUp(function(){
					$('#vestiging-' + vestiging_id).slideDown();
				});
			}
			else
			{
				$('#vestiging-' + vestiging_id).slideDown();
			}
		
	});	
		
	$('#newsSlider').cycle({ 			
		fx: 'scrollHorz',
		timeout: 15000,
		slideExpr: 'li'				
	});

	var delay = 200;
	var duration = 800;
	var count = 0;
	var length = $("#headerMain img.toDo").length;
	
	while (count < length)
	{
		var rand = Math.floor(Math.random()*length);
		
		if ($("#headerMain img").eq(rand).hasClass('toDo'))
		{	
			count += 1;			
			$("#headerMain img").eq(rand).removeClass('toDo');
			$("#headerMain img").eq(rand).css("opacity", 0.0);
			$("#headerMain img").eq(rand).delay((count * delay)).animate({ opacity: 1.0}, duration);
			
		}
	}
	
	function initMenu() 
	{		
		$('.accordionMenu ul').hide();
		//$('.accordionMenu ul li.active').parent().parent().parent().find("ul").show();
		// $('.accordionMenu li a').click( function() {
			
		// 	var checkElement = $(this).next();
		// 	if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		// 		return false;
		// 	}
		// 	if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		// 		$('.accordionMenu ul:visible').slideUp('normal');
		// 		checkElement.slideDown('normal');
		// 		return false;
		// 	}
		// });

		$('.accordionMenu .active_m ul').show();
		$('.accordionMenu .active_s').parent().show();
		$('.accordionMenu li ul:visible').parent().find('ul:hidden').show();
	}
	$(document).ready(function() {initMenu();});
	
});

$(window).load(function() {
		if(window.location.hash == '#frame2')
		{
			$('.show_form1').click();
		}
		if(window.location.hash == '#frame3')
		{
			$('.show_form2').click();
		}

	if($('#body').height() > $('#leftNavigationContainer').height())
	{
		$('#leftNavigationContainer').animate({ height: $('#body').height() - 75 });
		$('#content').animate({ height: $('#body').height() });
	}

});

