var old = null;
function goToHome(){
    window.location = "/";
}
function mouseOverWithDisplayNone(id){
    if(old){
        document.getElementById(old).style.display = "none";
    }
    document.getElementById(id).style.display = "block";
    old = id;
}
function mouseOutWithDisplayNone(id){
    document.getElementById(id).style.display = "none";
}

function layerOpen(layer){
    var oldStyle = document.getElementById(layer).style.display.toString();

    if(old!=null){
        document.getElementById(old).style.display = "none";
        document.getElementById("link"+old).className = "";
    }

    if(old==null || (document.getElementById(layer) && oldStyle != "block")){
        document.getElementById(layer).style.display = "block";
        document.getElementById("link"+layer).className = "active";
        old=layer;
    }
}
function loadPhotos(){
    var images = document.getElementsByTagName("img");
    for(var index = 0; index <= images.length; index++){
        if(images[index] && images[index].name && images[index].name!="" && images[index].name.toString().substr(0,11) == "/userfiles/"){
            images[index].src = images[index].name;
        }
    }
}
function __sameHeight(layer_id){
    var hoogte  = null;
    var ul      = document.getElementById(layer_id);
    var lis     = ul.getElementsByTagName("li");

    ul.style.display = "block";
    for(var i=0;i<=lis.length;i=i+3){
        if(lis[i] && lis[i].className.toString().search(/isSameHeight/)<0){
            hoogte  = lis[i].clientHeight;
            hoogte  = (lis[i+1] && lis[i+1].clientHeight>hoogte)?lis[i+1].clientHeight:hoogte;
            hoogte  = (lis[i+2] && lis[i+2].clientHeight>hoogte)?lis[i+2].clientHeight:hoogte;

            lis[i].style.height = hoogte+"px";
            lis[i].className += " isSameHeight";
            if(lis[i+1]){ // Er zijn 2 kolommen
                lis[i+1].style.height = hoogte+"px";
                lis[i+1].className += " isSameHeight";
            }
            if(lis[i+2]){ // Er zijn 3 kolommen
                lis[i+2].style.height = hoogte+"px";
                lis[i+2].className += " isSameHeight";
            }
        }
    }

}
function sameHeight(className){
    var colheight = 0;
    $(className).each(function(){
        if ($(this).height()>colheight) colheight=$(this).height();
    }).css({height:colheight});
}
function checkPhoto(id,width){
    var photo   = document.getElementById(id);
    var height  = photo.clientHeight;
    if(photo.clientWidth > width){
        photo.height = height / (photo.clientWidth/width);
        photo.width  = width;
    }
}

document.getElementsByClassName = function (c) {
    var r = new Array()
    var j = 0
    var o = document.getElementsByTagName("*")
    for(i=0;i<o.length;i++)
    {
        if(o[i].className == c) {
            r[j]=o[i];
            j++;
        }
    }
    return r;
}

$(document).ready(function() {
    $.ajaxSetup({
       contentType: "application/json; charset=utf-8",
       dataType: "json"
    });
    
   $(".kleur").change(function() {
//       $.ajax({
//           url: '/custom/variant.php?kleur='+$(this).val()+"&productid="+$("#productid").val(),
//           success: function(data) {
//               data = data.results;
//               for (index in data) {
//                   var dataItem = {};
//                   dataItem = data[index];
//                   $("#varianten").html($("#varianten").html()+"<input type='text' name='maten["+dataItem.maat+"]' onkeyup='updateOverview' />");
//               }
//           }
//       });
       $(".colors").hide();
       //console.log($(".colors input").attr("name"));
       var color = $(".colors input").attr("name").replace("temp", "");
       //console.log(color);
       $(".colors input").attr("name", "temp"+color);
       $("#color-"+$(this).val()).show();
       $("#color-"+$(this).val()+" input").attr("name", color);
       
       $.each(varianten[$(this).val()], function(key, value) {
           //$(".varianten").append("<div><input type=\"text\" name=\"maten["+key+"]\">&nbsp;stuks"+key+"&nbsp;"+value+"</div>");
       })
   });
});

