﻿function OpenProductZoom(productId,colorIndex) {
    var win = window.open("/produkt-zoom.aspx?pid=" + productId + "&color=" + colorIndex, "ProductZoom" + productId, "height=525,width=614", "");
    if (win.focus) win.focus();
}

function OpenMeasurementTable() {
    var win = window.open("/maaleskema.aspx", "MeasurementTable", "height=525,width=614", "");
    if (win.focus) win.focus();
}

function OpenMaterialChoice() {
    var win = window.open("/materialevalg.aspx", "MaterialChoice", "height=525,width=614", "");
    if (win.focus) win.focus();
}

function OpenProductCertification(certificationUrl) {
    var win = window.open(certificationUrl, "CertificationTable", "height=525,width=614", "");
    if (win.focus) win.focus();
}


$(document).ready(function() {

    $('#product-group-1')
        .hover(
            function() {
                $(this).addClass('product-group-1-hover');
                $(this).removeClass('product-group-1');
            },
            function() {
                $(this).removeClass('product-group-1-hover');
                $(this).addClass('product-group-1');
            }
        );

    $('#product-group-2')
        .hover(
            function() {
                $(this).addClass('product-group-2-hover');
                $(this).removeClass('product-group-2');
            },
            function() {
                $(this).removeClass('product-group-2-hover');
                $(this).addClass('product-group-2');
            }
        );



    $(window).resize(function() {
        TopRightNavigation2_Resize();
    });

    SetupTopRightNavigation2();
    TopRightNavigation2_Resize();
    SetupProductSeries();

});
/*
window.onload = function() {
    SetupTopRightNavigation2();
    TopRightNavigation2_Resize();
    SetupProductSeries();
}

window.onresize = TopRightNavigation2_Resize;
*/
function SetupProductSeries() {
    var links = $("#product-group-series a");
    var thumbContainer = $("#product-serie-thumb");
    var thumbImage = $("#product-serie-thumb img");

    $("#product-group-series a").each(function() {
        var link = $(this);
        var pictureUrl = link.attr("rev");
        if (pictureUrl != '') {
            link.mouseover(function() {
                var picUrl = $(this).attr("rev");
                var offset = $(this).offset();
                var left = offset.left;
                var top = offset.top;


                thumbImage.attr("src", picUrl);
                thumbContainer.css("left", (left + 192) + "px");
                thumbContainer.css("top", (top - 75) + "px");
                thumbContainer.show();
            });

            link.mouseout(function() {
                thumbImage.attr("src", "");
                thumbContainer.hide();
            });
        }
    });
}

function SetupTopRightNavigation2() {
    var navRoot = document.getElementById("top-right-navigation-2");
    if (navRoot) {
        var ul = navRoot.childNodes[0];
        for (i = 0; i < ul.childNodes.length; i++) {
            var node = ul.childNodes[i];
            if (node.nodeName == "LI") {
                node.onmouseover = function() {
                    this.className += " hover";
                }
                node.onmouseout = function() {
                    this.className = this.className.replace(" hover", "");
                }
            }
        }
    }
}

function TopRightNavigation2_Resize() {
    var topNav2 = document.getElementById("top-right-navigation-2");
    if (!topNav2) return;
    var ulElements = topNav2.getElementsByTagName("ul");
    var ie7 = (navigator.userAgent.indexOf("MSIE 7") != -1);
    
    for (var i = 0; i < ulElements.length; i++) {
        if (ulElements[i].className == "level-3") {
            var ul = ulElements[i];
            var width = topNav2.offsetWidth;

            var left = topNav2.offsetLeft;

            var parentListItem = ul.parentNode;

            var isInTheMiddle = (parentListItem.className.indexOf("first") == -1 && parentListItem.className.indexOf("last") == -1);
            if (isInTheMiddle) {
                left = parentListItem.offsetLeft;
                width = width - parentListItem.offsetWidth - 12;
            }
            
            
            
            if (ie7) {
                left += document.getElementById("inner-box").offsetLeft;
                if (isInTheMiddle)
                    left += document.getElementById("top-right-navigation-2").offsetLeft;
            }

            

            ul.style.left = left + "px";
            ul.style.top = "66px";
            ul.style.width = width + "px";
        }
    }
}
