$(document).ready(function(){
    if($(".tabs").length) {
        $(".tabs").each( function(index) {
            var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
            var ql = $(this).parent().attr('id');
            var nav = $(this).children('ul');
            var active = nav.children('.active').length ? nav.children('.active').attr('class').match(/item\d+/) : '';

            // Internet Explorer 6 CSS background fix
            if(ie6) {
                var color = '-red';
                var color_hex = '#c5230d';

                if(nav.children('.active').attr('class').match(/orange/)) {
                    color = '-orange';
                    color_hex = '#f18b06';
                }
                if(nav.children('.active').attr('class').match(/brown/)) {
                    color = '-brown';
                    color_hex = '#b6a883';
                }

                if(nav.children('.active').attr('class').match(/dom/)) {
                    color = '-dom';
                    color_hex = '#bfad7d';
                }
                if(nav.children('.active').attr('class').match(/klucz/)) {
                    color = '-klucz';
                    color_hex = '#ee7d01';
                }
                if(nav.children('.active').attr('class').match(/komfort/)) {
                    color = '-komfort';
                    color_hex = '#895c36';
                }
                if(nav.children('.active').attr('class').match(/platinium/)) {
                    color = '-platinium';
                    color_hex = '#877b6c';
                }
                if(nav.children('.active').attr('class').match(/prestiz/)) {
                    color = '-prestiz';
                    color_hex = '#39353d';
                }

                if(ql == 'HeaderQuickLinks') {
                    if(active=='item2') {
                        color = '-orange';
                        color_hex = '#f18b06';

                    } else if(active=='item3') {
                        color = '-brown';
                        color_hex = '#b6a883';
                    }
                }

                nav.children('.'+active).css("background-color", color_hex);
                nav.children('.'+active).css("background-image", "url('/templates/default/images/tab/tab-cap-m"+color+".gif')");
                nav.children('.'+active).children("a").css("background-image", "url('/templates/default/images/tab/tab-cap-l"+color+".gif')");
                nav.children('.'+active).children("a").children("span").css("background-image", "url('/templates/default/images/tab/tab-cap-r"+color+".gif')");
            }
        });

        $(".tabs li").hover(
            function () {
                if($(this).children('a').length) {
                    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
                    var ql = $(this).parent().parent().parent().attr('id');
                    var nav = $(this).parent();
                    var cl = $(this).attr('class').match(/item\d+/);

                    $(this).addClass("hover");

                    // Internet Explorer 6 CSS background fix
                    if(ie6) {
                        var color = '-red';
                        var color_hex = '#c5230d';

                        if($(this).attr('class').match(/orange/)) {
                            color = '-orange';
                            color_hex = '#f18b06';
                        }
                        if($(this).attr('class').match(/brown/)) {
                            color = '-brown';
                            color_hex = '#b6a883';
                        }

                        if($(this).attr('class').match(/dom/)) {
                            color = '-dom';
                            color_hex = '#bfad7d';
                        }
                        if($(this).attr('class').match(/klucz/)) {
                            color = '-klucz';
                            color_hex = '#ee7d01';
                        }
                        if($(this).attr('class').match(/komfort/)) {
                            color = '-komfort';
                            color_hex = '#895c36';
                        }
                        if($(this).attr('class').match(/platinium/)) {
                            color = '-platinium';
                            color_hex = '#877b6c';
                        }
                        if($(this).attr('class').match(/prestiz/)) {
                            color = '-prestiz';
                            color_hex = '#39353d';
                        }

                        if(ql == 'HeaderQuickLinks') {
                            if(cl=='item2') {
                                color = '-orange';
                                color_hex = '#f18b06';

                            } else if(cl=='item3') {
                                color = '-brown';
                                color_hex = '#b6a883';
                            }
                        }

                        nav.children('.'+cl).css("background-color", color_hex);
                        nav.children('.'+cl).css("background-image", "url('/templates/default/images/tab/tab-cap-m"+color+".gif')");
                        nav.children('.'+cl).children("a").css("background-image", "url('/templates/default/images/tab/tab-cap-l"+color+".gif')");
                        nav.children('.'+cl).children("a").children("span").css("background-image", "url('/templates/default/images/tab/tab-cap-r"+color+".gif')");
                    }
                }
            },

            function () {
                if($(this).children('a').length) {
                    var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
                    var ql = $(this).parent().parent().parent().attr('id');
                    nav = $(this).parent();
                    var act = $(this).attr('class').match(/active/);
                    var cl = $(this).attr('class').match(/item\d+/);

                    $(this).removeClass("hover");

                    // Internet Explorer 6 CSS background fix
                    if(ie6) {
                        if(act) {
                            var color = '-red';
                            var color_hex = '#c5230d';

                            if($(this).attr('class').match(/orange/)) {
                                color = '-orange';
                                color_hex = '#f18b06';
                            }
                            if($(this).attr('class').match(/brown/)) {
                                color = '-brown';
                                color_hex = '#b6a883';
                            }
                        
                            if($(this).attr('class').match(/dom/)) {
                                color = '-dom';
                                color_hex = '#bfad7d';
                            }
                            if($(this).attr('class').match(/klucz/)) {
                                color = '-klucz';
                                color_hex = '#ee7d01';
                            }
                            if($(this).attr('class').match(/komfort/)) {
                                color = '-komfort';
                                color_hex = '#895c36';
                            }
                            if($(this).attr('class').match(/platinium/)) {
                                color = '-platinium';
                                color_hex = '#877b6c';
                            }
                            if($(this).attr('class').match(/prestiz/)) {
                                color = '-prestiz';
                                color_hex = '#39353d';
                            }

                            if(ql == 'HeaderQuickLinks') {
                                if(cl=='item2') {
                                    color = '-orange';
                                    color_hex = '#f18b06';

                                } else if(cl=='item3') {
                                    color = '-brown';
                                    color_hex = '#b6a883';
                                }
                            }
                        } else {
                            color = '-white';
                            color_hex = '#fff';
                        }

                        nav.children('.'+cl).css("background-color", color_hex);
                        nav.children('.'+cl).css("background-image", "url('/templates/default/images/tab/tab-cap-m"+color+".gif')");
                        nav.children('.'+cl).children("a").css("background-image", "url('/templates/default/images/tab/tab-cap-l"+color+".gif')");
                        nav.children('.'+cl).children("a").children("span").css("background-image", "url('/templates/default/images/tab/tab-cap-r"+color+".gif')");
                    }
                }
            });
    }

    if($("#HeaderQuickLinks").length) {
        activeItem = $("#HeaderQuickLinks .tabs li.active").attr('class').match(/item\d+/);

        $("#HeaderQuickLinks .tabs li").hover(
            function () {
                var cl = $(this).attr('class').match(/item\d+/);

                $("#HeaderQuickLinks .cont div").hide()
                $("#HeaderQuickLinks .cont .active").show()
                $("#HeaderQuickLinks .cont div").removeClass("active").css('z-index', '1').hide();
                $("#HeaderQuickLinks .cont ."+cl).addClass("active").css('z-index', '10').show();
            },

            function () {
                $("#HeaderQuickLinks .cont div").removeClass("active").css('z-index', '1').hide();
                $("#HeaderQuickLinks .cont ."+activeItem).addClass("active").css('z-index', '10').show();
            });
    }

    if($(".brown #ContentNav2").length) {
        active = $(".brown #ContentNav2 li.active").attr('class').match(/item(\d+)/);

        if(active[1] > 6) {
            $("#ContentNav2 .item2").hide()
            $("#ContentNav2 .item3").hide()
            $("#ContentNav2 .item4").hide()
            $("#ContentNav2 .item5").hide()
            $("#ContentNav2 .item6").hide()
        }
    }
});

