﻿inMenuArea = "no";

$(document).ready(function(){
	
	//SUBMENU:
	//Positioneer submenu:
	var count = 0;
	var mouseoverItem = "";
	
	
	$(".submenu-first-level .act-back").find(".submenu-second-level").each(function(){
		$parentTitle = $(this).parent().find("a").html();
		
		$(".menu").find(".act-back").each(function(){
			if($(this).find("a").html() == $parentTitle){
				targetOffset = $(this).offset();
			}
		});

		if(count < 1){
			currentOffset = $(this).offset();
			correctedOffsetLeft = currentOffset.left + (targetOffset.left-currentOffset.left) - currentOffset.left;
			$(this).parent().css("margin-left",correctedOffsetLeft);
		}
		
		$(this).parent().css("visibility","visible");
		$(this).find(".act-back").css("font-weight","bold").css("visibility","visible");
		
		count++;
	});
	
	$(".menu").find("li").mouseenter(function(){
		$targetTitle = $(this).find("a").html();
		$activeClass = $(this).find("a").attr("class");
		targetOffset = $(this).offset();
		
		//loop trhough submenu items to find the matching submenu:
		$("#SUBMENU").find("li").each(function(){
				
			if($(this).find("a").html() == $targetTitle){
				if($(this).find(".submenu-second-level").length > 0){
				
					currentOffset = $(this).parent().offset();
		
					var correctedOffsetLeft = currentOffset.left + (targetOffset.left-currentOffset.left) - currentOffset.left;
					//$(this).find(".hoofd-back").css("margin-left",correctedOffsetLeft);
					//alert('currentOffset.left: '+currentOffset.left+" / targetOffset.left: "+targetOffset.left+" / correctedOffsetLeft(margin):"+correctedOffsetLeft);
					
					//Maak bestaande submenu hidden:
					$("#SUBMENU").find(".act-back, .actieve-submenu").each(function(){
						$(this).css("display","none");
						$(this).css("visibility","hidden");
						$(this).removeClass("actieve-submenu");
					});
					
					//Maak nieuwe, tijdelijke submenu visible en geef actieve-submenu class:
					$(this).addClass("actieve-submenu");
					
					$(".actieve-submenu").first().css("margin-left",correctedOffsetLeft);

					//$(this).css("display","block");
					if($activeClass != "active"){
						//$(this).slideDown();
						$(this).css("display","block");
					}
					else{
						$(this).css("display","block");
					}
					$(this).find("a").first().css("display","none");
					$(this).find("li").css("display","block");
					$(this).find("li").find("a").css("display","block");
					$(this).css("visibility","visible");
					
					$(this).find(".act-back").css("font-weight","bold").css("visibility","visible");

				}
			}
		});
		
		$("#menuPart").mouseleave(function(){
			//Maak bestaande (temp) submenu hidden:
			$(".actieve-submenu").first().css("display","none");
			$(".actieve-submenu").first().css("visibility","hidden");
			$(".actieve-submenu").first().removeClass("actieve-submenu");
			//Maak actieve menu visible:
			$(".submenu-first-level .act-back").css("visibility","visible");
			$(".submenu-first-level .act-back").slideDown();
		});
	});
	
	//HANDLE CONTENTWINDOW POSITION:
	setTimeout("handleContentHeight();",200);
	
	
	
	/*
	//Handle mouseouver submenu items:
	$("#MENU .nor-back, #MENU2 .nor-back").mouseover(function(){
		//HIDE ACTIVE SUBMENU:
		$targetID = $(this).attr("id");
		$targetTitle = $(this).find("a").html();
		$targetOffset = $(this).offset();
		
		displaySubmenu($targetTitle,"nonactive",$targetOffset.left);	
	});
	
	//Handle mouseouver submenu active item:
	$("#MENU .act-back, #MENU2 .act-back").mouseover(function(){
		//HIDE HOVER SUBMENUS:
		$targetID = $(this).attr("id");
		$targetTitle = $(this).find("a").html();
		$targetOffset = $(this).offset();
		$("#SUBMENU .nor-back").slideUp(300);
		setTimeout('displaySubmenu($targetTitle,"active",$targetOffset.left);',400);
	});
	
	$("#menuPart").mouseenter(function(){
		inMenuArea = "yes";
	});
	
	$("#menuPart").mouseleave(function(){
		inMenuArea = "no";
	
		$targetTitle = $("#MENU .act-back, #MENU2 .act-back").find("a").html();

		$("#SUBMENU").find(".nor-back").each(function(){
			$(this).slideUp();
		});
		
		setTimeout('displaySubmenu($targetTitle,"active",$targetOffset.left);',200);
	});

	*/
	
	
	
	//IMAGE SLIDER:
	$('#slider').nivoSlider({
		effect:'sliceDownLeft', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:1000, //Slide transition speed
		pauseTime:8000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:false, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){}, //Triggers after all slides have been shown
		lastSlide: function(){}, //Triggers when last slide is shown
		afterLoad: function(){} //Triggers when slider has loaded
	});
	
	
	
	
});

	function handleContentHeight(){
		$maxHeightNoScrollHeight_hoog = 256;
		$maxHeightNoScrollHeight_laag = 230;
		$heightStep = 90;

		if($("#centerContent").height() > $maxHeightNoScrollHeight_hoog){
			$verschil = $("#centerContent").height() - $maxHeightNoScrollHeight_hoog;
			$heightToAdd = Math.floor($verschil / $heightStep) * $heightStep + (1*$heightStep);
			
			//if($("#centerContent").height() <= ($maxHeightNoScrollHeight_hoog + 90)){
				//$("#centerContent").height($maxHeightNoScrollHeight_hoog + $heightToAdd);
			//}
			//else{
			if($("#centerContent").height() > 600){
				$("#centerContent").height($maxHeightNoScrollHeight_hoog + $heightToAdd);
				$("#centerColumn").height($maxHeightNoScrollHeight_hoog + $heightToAdd + 10);
			}
			else{
				$("#centerContent").height($maxHeightNoScrollHeight_hoog + $heightToAdd);
			}
			//}
			
			if($heightToAdd > $maxHeightNoScrollHeight_hoog){
				$("#bottomBlockRow").css("padding-top","0");
				$("#centerContent").css("background",'transparent url("/fileadmin/templates/images/caracthair_grid_centerbottom.png") repeat scroll left top');
			}
		}
		else{
			$verschil = $("#centerContent").height() - $maxHeightNoScrollHeight_laag;
			$heightToAdd = Math.floor($verschil / $heightStep) * $heightStep + (1*$heightStep);
			$("#centerContent").height($maxHeightNoScrollHeight_laag + 26);
			
			if($heightToAdd > $maxHeightNoScrollHeight_laag){
				$("#bottomBlockRow").css("padding-top","0");
				$("#centerContent").css("background",'transparent url("/fileadmin/templates/images/caracthair_grid_centerbottom.png") repeat scroll left top');
			}

		}	
	}


	/*
	function displaySubmenu(targetTitle,type,targetOffsetLeft){
		switch(type){
			case "nonactive":
				$("#SUBMENU .nor-back").find(".submenu-second-level").each(function(){
					if($(this).parent().find("a").html() == targetTitle){
						$thisID = $(this).parent().attr("id");
						subCounter = 0;
						trigger = 0;
						if(inMenuArea == "yes"){
							$("#SUBMENU .act-back").find(".submenu-second-level").find("li").slideUp(300, function(){
								if(subCounter < 1){
									$("#SUBMENU .act-back").find(".submenu-second-level").find("ul").hide();
									$("#SUBMENU .act-back").find(".submenu-second-level").parent().hide();
									//SHOW HOVER SUBMENU:
			
									$("#"+$thisID).find("a").hide();
									$("#"+$thisID).find(".submenu-second-level").find("ul").show();
									$("#"+$thisID).find(".submenu-second-level").find("a").show();
									$("#"+$thisID).show();
									
									currentOffset = $("#"+$thisID).offset();
									correctedOffsetLeft = currentOffset.left + (targetOffsetLeft-currentOffset.left) - currentOffset.left;
									
									$("#"+$thisID).find(".submenu-second-level ul").css("margin-left",correctedOffsetLeft);					
									$("#"+$thisID).find(".submenu-second-level").find("li").slideDown();
								}
								subCounter++;
								trigger++;
							});
							if(trigger < 1){
								$("#SUBMENU .nor-back").slideUp(300);
								$("#SUBMENU .act-back").find(".submenu-second-level").find("ul").hide();
								$("#SUBMENU .act-back").find(".submenu-second-level").parent().hide();
								//SHOW HOVER SUBMENU:
		
								$("#"+$thisID).find("a").hide();
								$("#"+$thisID).find(".submenu-second-level").find("ul").show();
								$("#"+$thisID).find(".submenu-second-level").find("a").show();
								$("#"+$thisID).show();
								
								currentOffset = $("#"+$thisID).offset();
								correctedOffsetLeft = currentOffset.left + (targetOffsetLeft-currentOffset.left) - currentOffset.left;
								
								$("#"+$thisID).find(".submenu-second-level ul").css("margin-left",correctedOffsetLeft);					
								$("#"+$thisID).find(".submenu-second-level").find("li").slideDown();
							}
						}
					}
				});
				break;
				
			case "active":
				$("#SUBMENU .act-back").find(".submenu-second-level").each(function(){
					if($(this).parent().find("a").html() == targetTitle){
						$(this).parent().find("a").hide();
						$(this).find("ul").show();
						$(this).find("a").show();
						$(this).parent().show();
						
						$(this).show();
						$(this).find("li").slideDown();
					}
				});
				break;
		}
	}
	
	*/


