﻿$(document).ready(function(){
	//Remove border from last menu item:
	$(".menu li:last").css("border","0px solid");
	
	//Launch top images fading:
	startFade(myFade);
	
	//Check if current page is home page, if so, change menuContainer background:
	$pageName = "";
	$pathName = window.location.pathname;
	$pathNameExploded1 = $pathName.split("/");
	$pathNameExploded2 = $pathNameExploded1[$pathNameExploded1.length-1].split(".");
	$pageName = $pathNameExploded2[0];
	
	if($pageName == "hotel" || $pageName == "arrangementen"){
		//Change background:
		$("#menuContainer").css("background","url('../fileadmin/templates/images/menucontainer-background-hotel.png') repeat-x scroll center top");
	}
	
	if($pageName == "contact"){
		//Change background:
		$("#menuContainer").css("background","url('../fileadmin/templates/images/menucontainer-background-contact.png') repeat-x scroll center top");
	}

	
	//Make actualContentRight AND mainContent (minus Padding and minus twitterContent padding!!) exactly as long as actualContentWrapper:
	$actualContentWrapper_height = $("#actualContentWrapper").height();
	$("#actualContentRight").css("min-height",$actualContentWrapper_height + "px");
	$("#mainContent").css("min-height",$actualContentWrapper_height - 100 + "px");	//50 = padding of mainContent, 50 = padding of twitterContent
	

	//CHANGE REVIEWS PAGE BACKGROUND
	if($pageName == "reviews"){
		//Change background:
		$("#actualContentRight").css("background-image","url(\"../fileadmin/templates/images/contentiframeback.png\")");
		$("#actualContentRight").css("background-repeat","repeat");
	}
	
	//HANDLE MENU:
	$timeOutTimer = "";
	$menuTimerActive = 0;
	$menuOpen = 0;
	
	//Handle menu items:
	$("#menuContainer").find(".menu").each(function(){
		$("li").each(function(){
			
			$(this).mouseleave(function(){
				if($(this).parent().attr("class") == "menulevel2"){
					$(this).children("ul").hide();
				}
				if($(this).parent().attr("class") == "menu"){
					$menuOpen = $menuOpen - 1;
					if($menuOpen < 1){
						hideSubMenu($(this).attr("id"));
					}
					else{
						$(this).children("ul").hide();
					}
				}
				else{
					$(this).children("ul").hide();
				}
			});
			
			$(this).mouseenter(function(){
				if($menuTimerActive == 1){
					$timeOutTimer = clearTimeout($timeOutTimer);
				}
				
				if($(this).parent().attr("class") == "menu"){
					$(this).parent().children("li").children("ul").stop(true, true);	//Stop all existing animations (drop downs), clear cue..
					$(this).parent().children("li").children("ul").hide();
				}
				if($(this).parent().attr("class") == "menu" && $(this).find("a").html() == "Hotel"){
					var ua = $.browser;
					if (ua.mozilla) {
						$(this).children("ul").css("left","-3px");
					}
					else{
						$(this).children("ul").css("left","-4px");
					}
				}
				else{
					$thisMainMenu = $(this).parent().parent().find("a").html();
					$(this).parent().parent().parent().children("li").children("ul").each(function(){
						if($(this).parent().find("a").html() != $thisMainMenu){
							$(this).hide();
						}
					});
				}
				$(this).children("ul").slideDown("fast");
			});

		});
		
		//HANDLE AANBIEDING (RECHTSBOVEN) UIT/INKLAPPEN:
		$("#aanbieding-top-block").mouseenter(function(){		
			//Slidedown divs:
			$("#aanbieding-middle-block").slideDown({
				duration:500,
				easing:"easeOutExpo",
				complete:function(){
					$("#aanbieding-bottom-block").slideDown("normal", "easeOutExpo");
				}
			}); 				
		});
		$("#aanbieding-block").mouseleave(function(){
			//Next: slide divs back up
			$("#aanbieding-bottom-block").slideUp({
				duration:300,
				easing:"easeOutExpo",
				complete:function(){
					$("#aanbieding-middle-block").slideUp({
						duration:300,
						easing:"easeOutExpo",
						complete:function(){
							$("#aanbieding-middle-block").hide();
							$("#aanbieding-bottom-block").hide();
						}
					});
				}
			});
			//Backup slide up method (if some panels remain open):
			window.setTimeout("$('#aanbieding-bottom-block').slideUp(200); $('#aanbieding-middle-block').slideUp(200);",800);
		});
		
		
		
	});
	
	
	function hideSubMenu(id){
		$menuTimerActive = 1;
		//$timeOutTimer = setTimeout('$("#'+id+'").children("ul").hide(); $menuTimerActive = 0;',700);
		
		$timeOutTimer = window.setTimeout(function() {
			$("#"+id).children("ul").slideUp("fast", function(){
				$("#"+id).children("ul").hide(); $menuTimerActive = 0;
			});
		}, 200);
		
	}
	
	
	//ANDROID Menu CSS FIX:
	var ua = navigator.userAgent.toLowerCase();
	var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
	if(isAndroid) {
		$("#menuContainer ul li a").css("padding","21px 22px 31px 15px");
	}
	//#menuContainer ul li a


});


