$(document).ready(function(){
	
	$(".medewerker").click(function () {
		$("a:first", this).trigger("click");
	});


	
	
//	$("#agendaSlide").click(function () {
//		alert('click')
//		$(".meer_agenda").slideUp();
//	});
	
	$("#agendaSlide").toggle(function () {
		$(".meer_agenda").slideDown();
				$(".homeHeight1").css('height','auto');
				return false;
	},
	function () {
		$(".meer_agenda").slideUp();
//				$(".homeHeight1").animate({height:$(".homeHeight2").height()+"px"},500);
				return false;
	});
	
	$(".toggleAgendaItem").toggle(function () {
		$('span.intro',$(this).parent().parent()).slideDown();
		$(".homeHeight1").css('height','auto');
	},
	function () {
		$('span.intro',$(this).parent().parent()).slideUp();
	});
	
	
	
	// uitgelicht
	var idBlockInt=1;
	var maxBlocks=Number( $("#uitgelicht .navigatie a:last").text() ) ;
	var timeoutID;
	$("#uitgelicht .navigatie a").click(function(event){
		idBlockInt=Number($(this).text());	
		clearTimeout(timeoutID);
		showHomeItem();
		event.preventDefault();
		this.blur();
	});
	function showHomeItem(){
		var idBlock="uitL"+idBlockInt.toString();
		// zet de boxen uit en de nieuwe aan
		$(".uitgelichtbox").fadeOut("slow");
		$("#"+idBlock).fadeIn("slow");
		// set de juiste navigatie bolletje aan
		$("#uitgelicht .navigatie a").removeClass("active");
		//$("#uitgelicht .navigatie a:contains('"+idBlockInt+"')").addClass("active");
		$("#uitgelicht .navigatie a:contains('"+idBlockInt+"')").each(function (i){
        if ( $(this).text() == idBlockInt ){
          $(this).addClass("active");
        }
      });
      
		// 
		timeout();
	}
	function timeout(){
		timeoutID=setTimeout(function() { 
			idBlockInt++;
			if(idBlockInt > maxBlocks) idBlockInt=1;
			showHomeItem();
			//timeout();
			 }, 8000); 
	}
	if(maxBlocks > 1)	timeout();
	
	// slideshow
	var idBlockIntSl=1;
	var maxBlocksSl=Number( $("#slideshow .navigatie a:last").text() ) ;
	var timeoutIDSl;
	$("#slideshow .navigatie a").click(function(event){
		idBlockIntSl=Number($(this).text());	
		clearTimeout(timeoutIDSl);
		showHomeItemSl();
		event.preventDefault();
		this.blur();
	});
	function showHomeItemSl(){
		var idBlock="uitL"+idBlockIntSl.toString();
		// zet de boxen uit en de nieuwe aan
		$(".slideshowbox").fadeOut("slow");
		$("#"+idBlock).fadeIn("slow");
		// set de juiste navigatie bolletje aan
		$("#slideshow .navigatie a").removeClass("active");
		//$("#slideshow .navigatie a:contains('"+idBlockIntSl+"')").addClass("active");
		$("#slideshow .navigatie a:contains('"+idBlockIntSl+"')").each(function (i){
		//	alert($(this).text());
        if ( $(this).text() == idBlockIntSl ){
          $(this).addClass("active");
        }
      });
		
		timeoutSl();
	}
	function timeoutSl(){
		timeoutIDSl=setTimeout(function() { 
			idBlockIntSl++;
			if(idBlockIntSl > maxBlocksSl) idBlockIntSl=1;
			showHomeItemSl();
			//timeout();
			 }, 8000); 
	}
	if(maxBlocksSl > 1)	timeoutSl();
	
	jQuery('#mycarousel, #mycarouselProj').jcarousel(
    {
        scroll: 1
    }
    );
	
	function setPageHeight(){
		if(!document.getElementById) return false;
		var elrm=	document.getElementById("main");
		var rmhgt=document.documentElement.clientHeight-(420);
		// hier moet nog iets met Math.max() main en dus wat main zou moeten worden.
		elrm.style.height=Math.max(rmhgt,(elrm.clientHeight-50))+"px";
		//elrm.style.height=(rmhgt)+"px";
		// alert(rmhgt);
		return true;
	}

	setPageHeight();
	
	$(".meer_agenda").css('display','none');
	/*
	setTimeout(function() {
        $('div.request').fadeOut();
    }, 5000); 
    */

	// zet op home die drie dingen op een lijn!
	$(".homeHeight1,.homeHeight2,.homeHeight3").height(Math.max($(".homeHeight1").height(),$(".homeHeight2").height(),$(".homeHeigh3").height()));	
	

});
