/* Set body tag for javascript dependent styling
----------------------------------------------------------------------------*/

$(document).ready(function() {
	$("body").removeClass("noJs").removeClass("tempJs").addClass("activeJs");
	$("#submenus .level1").parent().addClass("hasChildren");
	$("#submenus .level2").parent().addClass("hasChildren");

   try {
   document.execCommand('BackgroundImageCache', false, true);
   } catch(e) {}
});


/* Stops Event Propagation
    -----------------------------------------------------------------------------*/

    function stop(e) {
        if (!e) e = window.event;
        (e.stopPropagation) ? e.stopPropagation() : e.cancelBubble = true;
        (e.preventDefault) ? e.preventDefault() : e.returnValue = false;
        return false;
    }

    function stopProp(e) {
        if (!e) e = window.event;
        (e.stopPropagation) ? e.stopPropagation() : e.cancelBubble = true;
        return false;
    }

    function prevDef(e) {
        if (!e) e = window.event;
        (e.preventDefault) ? e.preventDefault() : e.returnValue = false;
        return false;
    }

/* */

	$("#mainmenu li a").bind("click",function(e){stopProp(e)});
	$("#mainmenu li").bind("click",function(e){stopProp(e)});
	
	
	$("#mainmenu li").bind("click",function(e){
		
		if($(this).hasClass("hasChildren")){
		
			$submenu = $(this).find(">ul");

			if($(this).hasClass("open")){
				$("ul",this).slideUp(400);
				$(this).removeClass("open");
			} else {
				if($submenu.hasClass("level2")){
					$("#mainmenu .level1 .open ").removeClass("open")
					$("#mainmenu .level2").not($submenu).slideUp(400)
				}  
		
				if($submenu.hasClass("level1")){
					$("#mainmenu .open ").removeClass("open")
					$("#mainmenu .level1").not($submenu).slideUp(400)
					$("#mainmenu .level2").slideUp(400)
				}
		
				$(this).addClass("open");
				$submenu.slideDown(600)
			}
		}
	});
	

	$("#submenus li.selected.hasChildren").addClass("open").find(">ul").addClass("selected");

	if($("#submenus .selected").parent().hasClass("level2")){

		$("#submenus .selected")
			.parent()
			.addClass("open")
			.addClass("selected")
			.parent()
			.addClass("open")
			.addClass("selected");
	}
	
	if($("#submenus .selected").parent().hasClass("level1")){
	
	
		$("#submenus .selected")
			.parent()
			.addClass("open")
			.addClass("selected")
			.parent()
			.addClass("open")
			.addClass("selected");
	}



	$("#mainmenu ul:not(.selected)").hide();


/* */

	$("#fontscaler .small").bind("click",function(e){
		stop(e);
		$("body").css("font-size","50%");
	});

	$("#fontscaler .medium").bind("click",function(e){
		stop(e);
		$("body").css("font-size","67.5%");
	});

	$("#fontscaler .large").bind("click",function(e){
		stop(e);
		$("body").css("font-size","100%");
	});

/* */
	
	$("#search .searchfield").val("Zoeken");
	
	$("#search .searchfield").bind("focus",function(){
		var fieldValue = $(this).val();
		if (fieldValue == "Zoeken"){$(this).val("")}
	});	
	
	$("#search .searchfield").bind("blur",function(){
		var fieldValue = $(this).val();
		if (fieldValue == ""){$(this).val("Zoeken")}
	});

/* */

	var $main = $("#homepage #content>div");
	var highest = 0;
	
	function levelRow(caller){
		var rDivs = $(caller).find(">div")
	
	
		rDivs.each(function(n){
			height = $(this).height();
			if (highest < height) {highest = height};
		})

		if($(caller).attr("id")=="rij_twee"){
			highest += 10;
		}

		rDivs.each(function(n){
			$(this).height(highest);
		})
	}

	$main.each(function(n){
		highest = 0;
		var $rDiv = $main[n];
		
		levelRow($rDiv);
	
	})
	
	/**/
	
	$('#search .searchfield:first').bind('keypress', function(e) {
        if(e.keyCode==13){
			stop(e);
        	location.href = "/search/pages/results.aspx?k="+$("#search .searchfield:first").val();
        }
	});

/* */

	var slideWidth = 629; 
	var slideHeight = 210; 
	var max = $("#coda1 ul.images li").length;
	var counter = 1;
	var slideTimer = 2000;
	var holdTimer = 4000;
	
	var itemHeight = slideHeight / max;


	$("#coda1 .goto li a").each(function(){
		var itemPadding = (itemHeight - $(this).height()) / 2;

		$(this).css({"padding-top":itemPadding + "px"});
		$(this).css({"padding-bottom":itemPadding + "px"});

	});


	$("#coda1 .currentslider").css({"height":100/max+"%"});
	$("#coda1 .goto li:first").addClass("selected");

	function activateMenu(){
		var nChild = counter;
		if (nChild == 0) {nChild = max}

		$("#coda1 .goto li").removeClass("selected");		
		$("#coda1 .goto li:nth-child("+nChild+")").addClass("selected");
	}

	function setCoda(){
		$("#coda1 ul.images").css({"left":(counter*-slideWidth)});
		$("#coda1 .currentslider").css({"top":(counter*(100/max))+"%"});
		counter += 1;
		if (counter >= max) { counter = 0;}
		activateMenu();
	}

	function animateCoda(){
		$("#coda1 ul.images").stop().animate({"left":(counter*-slideWidth)},slideTimer,"easeInOutCubic");
		$("#coda1 .currentslider").animate({"top":(counter*(100/max))+"%"},slideTimer,"easeInOutCubic",activateMenu);

		counter += 1;
		if (counter >= max) { counter = 0;}

	}
	
	$("#coda1 .goto li").bind("click",function(e){
		prevDef(e);
		counter = $("#coda1 .goto a").index(e.target);
		if (counter<0){return false}
		animateCoda();
		clearInterval(coda1Timer);
		coda1Timer = setInterval(animateCoda,holdTimer+slideTimer);	
	});


	counter = Math.round(Math.random() * (max-1));
	setCoda();
	$("#coda1 ul.images").show();

	var coda1Timer = setInterval(animateCoda,holdTimer+slideTimer);
	



