function sliderfulls() {
    var hm = $("header").height();
    console.log(hm);
    //$(".sliderfulls #fotos").css({'top':"-"+hm+'px'})
    $(".infobalkfoto .inforow").css({'margin-top':"-"+(hm + 150)+'px'})
    $(".sliderfulls .carousel-inner .item").css({'top':"-"+hm+'px'})
    
}
function mediabar() {
    if($(".mediabar .feature img").length) {
        var heimg = $(".mediabar .feature img").height();
        var wiimg = $(".mediabar .feature img").width();
    } else {
        var heimg = $(".mediabar .feature iframe").height();
        var wiimg = $(".mediabar .feature iframe").width();
    }
	var bw = $("body").width();
    
	$(".mediabar .allimages .image").css({"height":((heimg / 2))+"px"});
	$(".mediabar .allimages .morecounter").css({"margin-top":((heimg / 4) - 40)+"px", "margin-left":((wiimg / 4) - 50)+"px"});
    if(bw < 768) {
        $(".mediabar .allimages").css({"height":(heimg + 30)+"px"});
        $(".mediabar .allimages .morecounter").css({"margin-top":((heimg / 4) - 35)+"px", "margin-left":((wiimg / 4) - 40)+"px"});
    } else {
        $(".mediabar .allimages").css({"height":heimg+"px"});
    }
}
$(document).ready(function(){
    $('.carousel').carousel({
        interval: 5000
    })
    if($(".sliderfulls").length) {
        sliderfulls();
    }
    if($("input[name=aanvaarding]").length) {
        $("input[name=aanvaarding]").change(function () {
            var val = $(this).val();
            if(val == "PER_DATUM") {
                $(".per_datum").fadeIn();
            } else {
                $(".per_datum").fadeOut();
            }
        })
    }
    
    if($("input[name=bezichtigd]").length) {
        $("input[name=bezichtigd]").change(function () {
            var val = $(this).val();
            if(val == "true") {
                $(".bezichtigddatum").fadeIn();
            } else {
                $(".bezichtigddatum").fadeOut();
            }
        })
    }
    
    if($("input[name=biedersoort]").length) {
        $("input[name=biedersoort]").change(function () {
            var val = $(this).val();
            if(val == "PARTICULIER") {
                $(".particulier").fadeIn();
            } else {
                $(".particulier").hide();
            }
        })
    }
    
    if($("input[name=biedersoort]").length) {
        $("input[name=biedersoort]").change(function () {
            var val = $(this).val();
            if(val == "MAKELAAR") {
                $(".aankoopmakelaar").fadeIn();
            } else {
                $(".aankoopmakelaar").hide();
            }
        })
    }
    if($("input[name=voorbehoud]").length) {
        $("input[name=voorbehoud]").change(function () {
            var val = $(this).val();
            if(val == "FINANCIERINGS_BEDRAG") {
                $(".voorbedrag").fadeIn();
            } else {
                $(".voorbedrag").fadeOut();
            }
        })
    }
    if($("input[name=bouwvw]").length) {
        $("input[name=bouwvw]").change(function () {
            var val = $(this).val();
            if(val == "OVEREENSTEMMING_MAX_BEDRAG") {
                $(".bouwvw").fadeIn();
            } else {
                $(".bouwvw").fadeOut();
            }
        })
    }
    /*
    if($("#bag").length) {
        var src = $("#bag").html();
        $("#bag").html('<iframe src="'+src+'" width="100%" height="100%" frameborder="0"></iframe>');
        console.log("baghier");   
    }
    */
    
    if($(".mediabar").length) {
        mediabar();
        setTimeout(function() {
            mediabar();
        }, 500);
        setTimeout(function() {
            mediabar();
        }, 1500);
        if($(".popup-gallery").length) {
            $('.popup-gallery').magnificPopup({
              delegate: "a[target!='_blank']",
              type: 'image',
              tLoading: 'Loading image #%curr%...',
              mainClass: 'mfp-img-mobile',
              gallery: {
                enabled: true,
                navigateByImgClick: true,
                preload: [0,1] // Will preload 0 - before current, and 1 after the current image
              },
              image: {
                //tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
              }
            });
        }
        if($(".plattegrond-gallery").length) {
            $('.plattegrond-gallery').magnificPopup({
              delegate: 'a',
              type: 'image',
              tLoading: 'Loading image #%curr%...',
              mainClass: 'mfp-img-mobile',
              gallery: {
                enabled: true,
                navigateByImgClick: true,
                preload: [0,1] // Will preload 0 - before current, and 1 after the current image
              },
              image: {
                //tError: '<a href="%url%">The image #%curr%</a> could not be loaded.',
              }
            });
        }
        if($(".bag").length) {
            $('.bag').magnificPopup({
                type: 'inline',
                mainClass: 'popupframe'
            });
        }
        if($(".kadaster").length) {
            $('.kadaster').magnificPopup({
                type: 'inline',
                mainClass: 'popupframe'
            });
        }        
    }
    
    if($(".d3col a").length) {
        $('.d3col a').click(function() {
            var id = $(this).attr("id").replace("d3-","");            
            $('#frame360 select option').eq(id).prop('selected',true);
            console.log(id);
        });
    }
    
    if($("#frame360").length) {
        $('.link360').magnificPopup({
            type: 'inline',
            mainClass: 'popupframe'
        });
        $('#frame360 select').on('change', function() {
            var url = this.value;
            pannellum.viewer('panoramawoning_rw', {
                "type": "equirectangular",
                "panorama": url,
                "autoLoad": true,
                "autoRotate": -2
            });
        });
        $('.link360').click(function() {
            setTimeout(function() {
                var first360 = $( "#frame360 select option:selected" ).val();
                pannellum.viewer('panoramawoning_rw', {
                    "type": "equirectangular",
                    "panorama": first360,
                    "autoLoad": true,
                    "autoRotate": -2
                });
            },100);
        });
            
    }
    
    
    if($(".overzichtobject .objectitem").length) {
        $(".overzichtobject").pagify(parseFloat($("#pnr").html()), ".objectitem"); 
        $('.verglcon .setpage button').click(function() {
            var page = parseFloat($(this).text());
            $('.verglcon .setpage button').removeClass("actief");
            $(this).addClass("actief");
            $("#vergitems span").html(page);
            $("#pnr").html(page);
            $(".overzichtobject").pagify(parseFloat($("#pnr").html()), ".objectitem"); 
        });
    }
    
    if($(".tekstuitklap").length) {
        var height = $(".tekstuitklap").height();
        if(height > 150) {
            $(".tekstuitklap").addClass("inklappen");
            $(".tekstuitklap").after('<div class="leesmeerbtn"><span>Lees meer</span></div>');
            $(".leesmeerbtn").click(function() {
                $(".tekstuitklap").removeClass("inklappen");
                $(".leesmeerbtn").hide();
            });
		
	
			
        }
    }
	
	
	if($(".numericbod").length) {
		$(".numericbod").each(function() {
			new AutoNumeric(this, {
				digitGroupSeparator: '.',
				decimalCharacter: ',',
				currencySymbol: "€ ",
				currencySymbolPlacement: "p",
				
				minimumValue: '0'
			});
		});
	}	
	if($(".percentbod").length) {
		$(".percentbod").each(function() {
			new AutoNumeric(this, {
				digitGroupSeparator: '.',
				decimalCharacter: ',',
				currencySymbol: "%",
				currencySymbolPlacement: "s",
				minimumValue: '0'
				
			});
		});
	}
	
	
	if($("#hypotheekadvies").length) {
		document.getElementById("hypotheekadvies").onclick = function calculateHypotheek() {
			// HypotheekCalculator
			var hypotheekbedrag = parseFloat(document.getElementById('hypotheekbedrag').value.replaceAll(".", "").replace("€ ", ""));
			var inleg = 0;
			var rentepercentage = parseFloat(document.getElementById('rentepercentage').value.replaceAll(".", "").replace("%", "").replace(",", "."));
			if (isNaN(rentepercentage)){
				rentepercentage = 0;
			}
			if (rentepercentage > 100) {
				rentepercentage = 100;
			}
			var annuiteit = 0; // het te betalen maandbedrag
			var maandrente = 0; // de rente door 12
			var aflossing = hypotheekbedrag - inleg;
			maandrente = rentepercentage / 1200;
			// formule is maandelijks bedrag = hoofdsom * (maandrente * (1 + maandrente)^360) / ((1 + maandrente) ^ 360 - 1)
			annuiteit = aflossing * (maandrente * Math.pow((1 + maandrente), 360)) / (Math.pow((1 + maandrente), 360) - 1);
			if (isNaN(annuiteit)){
				annuiteit = aflossing / 360;
			}
			document.getElementById('annuiteit').innerHTML = ("€ " + Math.round((annuiteit + Number.EPSILON) * 100) / 100).replace(".", ",") + "  p/m";
			document.getElementById('belastingvoordeel').innerHTML = ("€ " + Math.round(((annuiteit * 0.7) + Number.EPSILON) * 100) / 100).replace(".", ",") + " p/m"; // 3-% belastingvoordeel
		}
		var acc = document.getElementsByClassName("accordion");
		var i;
		for (i = 0; i < acc.length; i++) {
		  acc[i].addEventListener("click", function() {
			this.classList.toggle("active");
			var panel = this.nextElementSibling;
			if (panel.style.display === "block") {
			  panel.style.display = "none";
			} else {
			  panel.style.display = "block";
			}
		  });
		}
		$("#hypotheekbedrag").on('keyup', function (e) {
			if (e.key === 'Enter' || e.keyCode === 13) {
				document.getElementById("hypotheekadvies").click()
			}
		});
		$("#rentepercentage").on('keyup', function (e) {
			if (e.key === 'Enter' || e.keyCode === 13) {
				document.getElementById("hypotheekadvies").click()
			}
		});
		
		setTimeout(function() {
			$("#hypotheekadvies").trigger('click');
		},1000);
	}
	
	
	$(".fullclick").click(function(){
		 window.location=$(this).find("a").attr("href");
		 return false;
	});
	$(".fullclickout").click(function(){
		var checkurl = $(this).find("a").attr("href");
		if(checkurl != "#") {
			window.open($(this).find("a").attr("href"), '_blank');
		}
		return false;
	});
});
var check = window.top === window.self
if(check == false) {
    console.log("iframe script");
	
    publishHeight(); 
    setTimeout(function() {
        publishHeight(); 
    },500);
    function publishHeight() {
        var actualHeight = getBodyHeight() + 150;
        var pass_data = {
            'action':'height',
            'id':'mww-frame-one',
            'value':actualHeight
        };
        //console.log(pass_data);
        setTimeout(function() {
            publishHeight(); 
        },500);
        window.top.postMessage(JSON.stringify(pass_data), '*');
    }
    function getBodyHeight() {
        var height,
            scrollHeight,
            offsetHeight;
        if (document.height) {
            height = document.height;
        } else if (document.body) {
            if (document.body.scrollHeight) {
                height = scrollHeight = document.body.scrollHeight;
            }
            if (document.body.offsetHeight) {
                height = offsetHeight = document.body.offsetHeight;
            }
            if (scrollHeight && offsetHeight) {
                height = Math.max(scrollHeight, offsetHeight);
            }
        }
        return height;
    }
    function getViewPortHeight() {
        var height = 0;
        if (window.innerHeight) {
            height = window.innerHeight - 18;
        } else if ((document.documentElement) && (document.documentElement.clientHeight)) {
            height = document.documentElement.clientHeight;
        } else if ((document.body) && (document.body.clientHeight)) {
            height = document.body.clientHeight;
        }
        return height;
    }
    function parseQueryString(url) {
        url = new String(url);
        var queryStringValues = new Object(),
            querystring = url.substring((url.indexOf('?') + 1), url.length),
            querystringSplit = querystring.split('&');
        for (i = 0; i < querystringSplit.length; i++) {
            var pair = querystringSplit[i].split('='),
                name = pair[0],
                value = pair[1];
            queryStringValues[name] = value;
        }
        return queryStringValues;
    }
    
    window.onload = function() {
        publishHeight();
    }
    
	
    $("a").click(function() {
        //var link = $(this).attr("href");
        //console.log("Link klik: "+link);
        var pass_data = {
            'action':'scroll',
            'id':'mww-frame-one'
        };
		parentIFrame.scrollToOffset(0,0);
        window.top.postMessage(JSON.stringify(pass_data), '*');
        publishHeight();
    });
    
    $('.btn').click(function() {
        //var link = $(this).attr("href");
        //console.log("Link klik: "+link);
        var pass_data = {
            'action':'scroll2',
            'id':'mww-frame-one'
        };
		//parentIFrame.scrollToOffset(0,0);
        window.top.postMessage(JSON.stringify(pass_data), '*');
        publishHeight();
    });
    
    $(".mtmo15revcar.fullclickout").click(function () {
        var act = "Naar review pagina";
        var objid = $("#objid").html();
        /*
		gtag('event', objid, {
            'event_category' : act,
            'value' : 1
        });
		*/
		//act = act.replace(/\ /g,"_");
		gtag('event', act, {
			'event_category' : objid,
			'value' : 1
		});
    });
	
    $(".overzichtobject .objectitem.fullclick").addClass("fullclickout").removeClass("fullclick");
	
	/*
    $(".fullclick").click(function(){
		var checkurl = $(this).find("a").attr("href");
		if(checkurl != "#") {
			window.open($(this).find("a").attr("href"), '_blank');
		}
        return false;
	});
	$(".fullclickout").click(function(){
		var checkurl = $(this).find("a").attr("href");
		if(checkurl != "#") {
			window.open($(this).find("a").attr("href"), '_blank');
		}
		return false;
	});
    */
	
    window.onload = function() {  
        // A function to process messages received by the window.
        function receiveMessage() {
            publishHeight();
        }
        // Setup an event listener that calls receiveMessage() when the window
        // receives a new MessageEvent.
        window.addEventListener('message', receiveMessage);
    }
	
}
(function($) {
	var pagify = {
		items: {},
		container: null,
		totalPages: 1,
		perPage: parseFloat($("#pnr").html()),
		currentPage: 0,
		createNavigation: function() {
            if(this.items.length > this.perPage) {
                this.totalPages = Math.ceil(this.items.length / this.perPage);
            } else {
                this.totalPages = 1;
            }
            
			$('.pagination', this.container.parent()).remove();
			var pagination = $('<div class="pagination"></div>').append('<a class="nav prev disabled" data-next="false">&laquo;</a>');
			for (var i = 0; i < this.totalPages; i++) {
				var pageElClass = "page";
				if (!i)
					pageElClass = "page current";
				var pageEl = '<a class="' + pageElClass + '" data-page="' + (
				i + 1) + '">' + (
				i + 1) + "</a>";
				pagination.append(pageEl);
			}
			pagination.append('<a class="nav next" data-next="true">&raquo;</a>');
			this.container.after(pagination);
			var that = this;
			$("body").off("click", ".pagination .nav");
			this.navigator = $("body").on("click", ".pagination .nav", function() {
				var el = $(this);
				that.navigate(el.data("next"));
			});
			$("body").off("click", ".page");
			this.pageNavigator = $("body").on("click", ".page", function() {
				var el = $(this);
				that.goToPage(el.data("page"));
			});
            if(this.totalPages == 1) {
                $('.verglcon  .pagination').hide();
            } else {
                $('.verglcon  .pagination').show();
            }
		},
		navigate: function(next) {
			// default perPage to 5
			if (isNaN(next) || next === undefined) {
				next = true;
			}
			$(".pagination .nav").removeClass("disabled");
			
			var $target = $('.overzichtobject');
			var navheight = $("header").height() + 45;
			$('html, body').stop().animate({
				'scrollTop': $target.offset().top - navheight
		  	}, 100, 'swing', function() { });
			
			if (next) {
				this.currentPage++;
				if (this.currentPage > (this.totalPages - 1))
					this.currentPage = (this.totalPages - 1);
				if (this.currentPage == (this.totalPages - 1))
					$(".pagination .nav.next").addClass("disabled");
				}
			else {
				this.currentPage--;
				if (this.currentPage < 0)
					this.currentPage = 0;
				if (this.currentPage == 0)
					$(".pagination .nav.prev").addClass("disabled");
				}
			this.showItems();
		},
		updateNavigation: function() {
			var pages = $(".pagination .page");
			pages.removeClass("current");
			$('.pagination .page[data-page="' + (
			this.currentPage + 1) + '"]').addClass("current");
		},
		goToPage: function(page) {
            var check = window.top === window.self
            if(check == false) {
                var pass_data = {
                    'action':'scroll',
                    'id':'mww-frame-one'
                };
				if (typeof parentIFrame !== 'undefined' && parentIFrame) {
					parentIFrame.scrollToOffset(0,0);
				}
                window.top.postMessage(JSON.stringify(pass_data), '*');
                publishHeight();
            }
            
			this.currentPage = page - 1;
			
			var $target = $('.overzichtobject');
			var navheight = $("header").height() + 45;
            
			$('html, body').stop().animate({
				'scrollTop': $target.offset().top - navheight
		  	}, 100, 'swing', function() { });
			
			$(".pagination .nav").removeClass("disabled");
			if (this.currentPage == (this.totalPages - 1))
				$(".pagination .nav.next").addClass("disabled");
			if (this.currentPage == 0)
				$(".pagination .nav.prev").addClass("disabled");
			this.showItems();
		},
		showItems: function() {
			this.items.hide();
			var base = this.perPage * this.currentPage;
			this.items.slice(base, base + this.perPage).show();
			this.updateNavigation();
		},
		init: function(container, items, perPage) {
			this.container = container;
			this.currentPage = 0;
			this.totalPages = 1;
			this.perPage = perPage;
			this.items = items;
			this.createNavigation();
			this.showItems();
		}
	};
	// stuff it all into a jQuery method!
	$.fn.pagify = function(perPage, itemSelector) {
		var el = $(this);
		var items = $(itemSelector, el);
		// default perPage to 5
		if (isNaN(perPage) || perPage === undefined) {
			perPage = 3;
		}
		// don't fire if fewer items than perPage
		if (items.length <= perPage) {
            perPage = items.length;
			//return true;
		}
		pagify.init(el, items, perPage);
	};
})(jQuery);
