$(document).ready(function() {

    var colheight = 0;
    $(".sameheight").each(function(){
        if ($(this).height()>colheight) colheight=$(this).height();
    }).css({height:colheight});

    $(".sameheight-li").each(function(){
        if ($(this).height()>colheight) colheight=$(this).height();
    }).css({height:colheight});
    
    var num = $(".section .rij").length;
    var colheight2 = 0;
    for (var i = 1; i <= num; i++) {
        $(".sameheight"+i).each(function(){
            if ($(this).height()>colheight2) colheight2=$(this).height();
        }).css({height:colheight2});        
    }
    
    var colheight3 = 0;
    $(".sameheightH2").each(function(){
        if ($(this).height()>colheight3) colheight3=$(this).height();
    }).css({height:colheight3});
    
     var colheight4 = 0;
    $(".sameheightFooter").each(function(){
        if ($(this).height()>colheight4) colheight4=$(this).height();
    }).css({height:colheight4});
    

    $("select.refines").change(function () {
        document.location = $(this).val();
    });
    
    $("#btnAdd, #btnAdd2").click(function(event) {
        if ($("#aantal").val() == "" || !is_numeric($("#aantal").val())) {
            alert("U dient het aantal op te geven.");
            event.preventDefault();
        }
    });
    
    $("a.iframe").click(function() {
        if ($("#aantal")) {
            var aantal = 1;
            var webshopitem = null;
            if (isNumber($("#aantal").val())) aantal = $("#aantal").val();else aantal = 1;
            if (isNumber($("#webshopitem").val())) webshopitem = $("#webshopitem").val();
            $(this).attr("href", $(this).attr("href")+"&aantal="+aantal+(isNumber(webshopitem)?"&webshopitem="+webshopitem:""));            
        }
    });

    try{
        $("a.iframe").fancybox({
            'width': 625,
            'height': '75%',
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'autoScale': false,
            'type': 'iframe',
            'centerOnScroll': true
        });
        $("a.fancybox").fancybox({
            'hideOnContentClick': true,
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic',
            'overlayShow'	: true
        });
    }catch(e){}


    $("ul.productgroups li").hide();
    $("ul.productgroups li.parent, ul.productgroups li.hoofditem").show();    
    var selected = $("ul.productgroups li a.active").parent();
    $("li", selected).show();
    var selected = $("ul.productgroups li ul li a.active").parent().parent();
    $("li", selected).show();
    
    $("#offerteLink1").click(function(event) {
        event.preventDefault();
        
        var aantal = 1;
        var webshopitem = null;
        if (isNumber($("#aantal").val())) aantal = $("#aantal").val();else aantal = 1;
        if (isNumber($("#webshopitem").val())) webshopitem = $("#webshopitem").val();
        $(this).attr("href", $(this).attr("href")+"&aantal="+aantal+(isNumber(webshopitem)?"&webshopitem="+webshopitem:""));        
        
        $.get($(this).attr("href"), 
            function() { 
                $("#popup").click();
            });
    });
    
    $("#offerteLink").click(function() {
        var aantal = 1;
        var webshopitem = null;
        if (isNumber($("#aantal").val())) aantal = $("#aantal").val();else aantal = 1;
        if (isNumber($("#webshopitem").val())) webshopitem = $("#webshopitem").val();
        $(this).attr("href", $(this).attr("href")+"&aantal="+aantal+(isNumber(webshopitem)?"&webshopitem="+webshopitem:""));
    }); 
});

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}
