$(document).ready(function(){
	Number.isInteger = Number.isInteger || function(value) {
	    return typeof value === "number" && 
	           isFinite(value) && 
	           Math.floor(value) === value;
	};
})

/************************/
/*                      */
/*         MENU         */
/*                      */
/************************/
$(document).ready(function(){
	if($(window).width() < 992){
		var headerWidth = $("header").width();
		$("header").css("left",-headerWidth);
		$("#menu-icon-open").on("click",function(e){
			console.log("click open");
			e.preventDefault();
			if(!$("header").hasClass("open")){
				$("header").addClass("open");
				$("header").animate({
					left: 0
				}, 500);
			}
		});
		
		$("header #menu-icon-close").on("click",function(e){
			e.preventDefault();
			console.log("click close");
			if($("header").hasClass("open")){
				$("header").removeClass("open");
				$("header").animate({
					left: -headerWidth
				}, 500);
			}
		});
	}else{$("header").css("left",0);}
	$("body .wrapper-container").on("click",function(e){
		if($("header").hasClass("open")){
			$("header").removeClass("open");
			$("header").animate({
				left: -headerWidth
			}, 500);
		}
		return true;
	});
});


/************************/
/*                      */
/*       HOMEPAGE       */
/*                      */
/************************/
/*$(window).load(function(e){
	if($(window).width() >= 992){
		$(".productgroep-item").hover(function(){
			//console.log("hover in");
			var height = $(this).height();
			//console.log(height);
			$(this).css({"height": height + "px", "overflow": "hidden"});
			$(this).find(".productgroep-omschrijving").removeClass("hidden");
			$(this).find(".move").stop();
			$(this).find(".move").animate({
				marginTop: "-"+($(this).find(".productgroep-omschrijving").height() +5)+"px"
			},500)
		}, function(){
			//console.log("hover out");
			$(this).find(".move").stop();
			$(this).find(".move").animate({
				marginTop: 0
			},500,function(){$(this).find(".productgroep-omschrijving").addClass("hidden");})
		});
	}

	
	var percent = 0, bar = $('#slider-status'), crsl = $('#carousel-home');
	function progressBarCarousel() {bar.css({width:percent+'%'});
		percent = percent +0.75;
		if (percent>100) {
		    percent=0;
		    crsl.carousel('next');
		}      
	}
	//console.log(crsl.length);
	if(crsl.length != 0){
		crsl.carousel({
		    interval: false,
			pause: true
		}).on('slid.bs.carousel', function () {});var barInterval = setInterval(progressBarCarousel, 30);
		crsl.hover(
		    function(){clearInterval(barInterval);},
		    function(){
		        barInterval = setInterval(progressBarCarousel, 30);
		})
	}
});*/


/************************/
/*                      */
/*       OVER ONS       */
/*                      */
/************************/
$(document).ready(function(){
	//console.log("ready");
	var blokken = $(".overons-block");
	//console.log(blokken);
	if(blokken.length != 0){
		var i = 0;
		var maxHeight = 0;
		while(i < blokken.length){
			if(maxHeight < $(blokken[i]).find(".textblock").outerHeight()){
				maxHeight = $(blokken[i]).find(".textblock").outerHeight();
				//console.log(maxHeight);
			}
			i++;
		}
		$(".overons-block").find(".textblock").height(maxHeight + "px");
	}


	$("#hidden_login_btn").on("click",function(e){
		e.preventDefault();
		$('form#login').submit();
	})
	$("a #login-button").on("click", function(e){
		e.preventDefault();
		$('form#login').submit();
	});
});
$('form#login').ajaxForm({
	//beforeSubmit: beforeSubmitRegisterform,
	dataType: 'json',
	success: function(data) {
		if(data["errors"].length != 0){
		    if(data["errors"]["login"] == "Your membership account has not been activated yet."){
			    $("#login-error").html("Uw account werd nog niet geverifieerd door onze klantendienst.");
		    }else if(data["errors"]["login"] == "The existing username and/or password you submitted are not valid"){
			    $("#login-error").html("Gebruikersnaam en/of wachtwoord is verkeerd");
			}else{
				$("#login-error").html("Er is een fout opgetreden. Probeer opnieuw!");
			}
		}else if(data["success"] == 1){window.location.reload();}
	}
});





















