var val;
var curHeight;

$(document).ready(function() {
	resizepagetitle();
	var offsetContent = $(".content").offset();	
	var heightRemaining = parseInt($(window).height() - offsetContent.top - $(".footerWrapper").height());
	$(".contentWrapper").css("height", heightRemaining);
		
	$(".menu > li > a").click(function(){
					
		if($(this).parent().find("ul").is(":visible")) {		
			$(this).parent().removeClass("clickActive");
			$(this).parent().find("ul").slideUp("fast");
		} else {
			var currentLink = $(this);		
			
			if($(".menu").find("ul:visible").length > 0) {
				$(".menu").find("li.clickActive").removeClass("clickActive");	
				$(".menu").find("ul:visible").hide("fast", function(){												
					currentLink.parent().find("ul").slideDown("fast");
				});
			} else {
				$(".menu").find("li.clickActive").removeClass("clickActive");			
				currentLink.parent().find("ul").slideDown("fast");
			}
			$(this).parent().addClass("clickActive");
		}

		return false;		
	});
	
	$(".investments > li > a").click(function(){
		
		if($(this).parent().find("div.investmentContentWrapper").is(":visible")) {
			$(this).parent().find("div.investmentContentWrapper").slideUp("fast");
			$(this).removeClass("selected");
			
		} else {
			var currentLink = $(this);		
			if($(".investments").find("div.investmentContentWrapper:visible").length > 0) {
				$(".investments").find("div.investmentContentWrapper:visible").slideUp("fast", function(){					
					$(this).parent().find("a").removeClass("selected");
					currentLink.parent().find("div.investmentContentWrapper").slideDown("fast");
					var htmlcontent =  currentLink.parent().find(".imgandheadercontainer").html();
					if(htmlcontent.length < 1){
						var htmlcontent ='<img src="' + defaultcontent[0] + '" width="468" height="230" alt="" class="pageTitleImg"/>';
						htmlcontent += '<div class="pageTitleWrapper showPagetitle' + defaultcontent[2] + '"><div class="pageTitle">';
						htmlcontent += '' + unescape(defaultcontent[1]) + '';
						htmlcontent += '</div></div>';	
					}
					$(".topContent").html(htmlcontent);
					resizepagetitle();
					
				});
			} else {
				
				currentLink.parent().find("div.investmentContentWrapper").slideDown("fast");
				var htmlcontent =  currentLink.parent().find(".imgandheadercontainer").html();
				if(htmlcontent.length < 1){
						var htmlcontent ='<img src="' + defaultcontent[0] + '" width="468" height="230" alt="" class="pageTitleImg"/>';
						htmlcontent += '<div class="pageTitleWrapper showPagetitle' + defaultcontent[2] + '"><div class="pageTitle">';
						htmlcontent += '' + unescape(defaultcontent[1]) + '';
						htmlcontent += '</div></div>';	
				}
				$(".topContent").html(htmlcontent);
				resizepagetitle();
			}

			$(this).addClass("selected");
		}
		
		return false;	
		
	});
	
	$(".teamWrapper a").hover(
		function(){
			//alert($(this).attr("nr"));
			var linkHref = $(this).attr("nr");
			var parentSide = ($(this).parent().hasClass("teamLeft")) ? ".teamRight" : ".teamLeft";
			var changeLink = $(parentSide).find("a[nr="+linkHref+"]");
			
			changeLink.addClass("hover");
			
			if(parentSide == ".teamRight") {
				$(this).find(".teamOverlay").show();
			} else {
				changeLink.find(".teamOverlay").show();
			}
		},
		function() {
			$(".teamWrapper").find("a").removeClass();
			$(".teamWrapper").find(".teamOverlay").hide();
		}
	);
	

	
		$(".teamWrapper a").click(function() {
	
		var id = $(this).attr("nr");
		var x = $(this).attr("href").indexOf("cms");
		
		if (x > -1){
			
			return true;
			}else {
		$(".overlayContent").empty();
		$(".overlayContentImg").empty();
		
		var responseImg = $.ajax({
				url: "ajax/getTeamMember.php?id="+id+"&img=1",
				async: false
				}).responseText;
		
		var response = $.ajax({
				url: "ajax/getTeamMember.php?id="+id+"",
				async: false
				 }).responseText;
		
		if (responseImg!==''){
			$(".overlayContentImg").html(responseImg); 
		}
		if (response!==''){
			$(".overlayContent").html(response); 
		}

		$(".overlayBg").show();
		return false;
		}	
		
	});
		
	$(".overlayClose").click(function() {
		$(".overlayBg").hide();
		$("#overlayContent").removeClass("overlayContentBg");
		$("body").css("overflow", "auto");
		
		$("body").removeClass("overflowHidden");
		$("body").addClass("overflowAuto");		
		
		return false;
	});
	$("a.closeOverlay").click(function() {
		$(".overlayBg").hide();
		$("#overlayContent").removeClass("overlayContentBg");
		$("body").css("overflow", "auto");	
				
		$("body").removeClass("overflowHidden");
		$("body").addClass("overflowAuto");
				
		return false;
	});
	
	$(".emailField, #emailaddress").focus(		
		function() {
			val = $(this).val();
			$(this).val("");
		}
	);
	
	
	$(".emailField , #emailaddress").blur(
		function() {
			if($(this).val()=='')$(this).val("E-mail");
		}
	);
	
	$(".newsletterBoxClosed a").click(function() {
		$(".newsletterBoxOpen").slideToggle("fast");
		$(".newsletterBoxClosed").hide();
		
		return false;	
	});
	
});

function resizepagetitle(){
	if(top.location.href.match(/\/cms/)){
		return false;
		}
	else{
		pagetitlecontent=$(".topContent .pageTitleWrapper .pageTitle h1").text();
		if(pagetitlecontent.length==0){
			$("div.pageTitleWrapper").css("height","35px");
			$(".topContent .pageTitleWrapper .pageTitle").css("margin-top","10px");
		}
	}
}

$(window).resize(function(e) {

		// var offsetContent = $(".content").offset();
		// 304 = offsetContent.top
		// offsetContent.top geeft een negatieve waarde nadat er gescrolled is waardoor - en - een + wordt en div te groot wordt.
		// vandaar fixed op 304.
		
		var heightRemaining = parseInt($(window).height() - 304 - $(".footerWrapper").height());
		
		$(".contentWrapper").css("height", heightRemaining);

	
	
});



function isEmail(str) {
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function checkFormEmail () {
	
	if (document.getElementById("emailField").value == "" || !isEmail(document.getElementById("emailField").value)) {
		document.getElementById("emailFail").style.display="block";
		//alert(document.getElementById("emailField").value);
		return false;
	}else {
		return true;
	}
}


function checkFormAfmelden () {
	if (document.getElementById("emailaddress").value == "" || !isEmail(document.getElementById("emailaddress").value)) {
		document.getElementById("unemailFail").style.display="block";
		//document.getElementById("email").focus();
		return false;
	}else {
		return true;
	}
}

function checkSearchForm() {
	
	if(top.location.href.match(/\/cms/)) return false;
	
}




