
jQuery(document).ready(function () {

//
//
    $(" body.fr #mobile-footer .nav-link ").text("English");
//
    $("a")
            .mouseenter(function () {
                var title = $(this).attr("title");
                $(this).attr("tmp_title", title);
                $(this).attr("title", "");
            })
            .mouseleave(function () {
                var title = $(this).attr("tmp_title");
                $(this).attr("title", title);
            })
            .click(function () {
                var title = $(this).attr("tmp_title");
                $(this).attr("title", title);
            });
    //
    if ($(".col-menu").length) {
        $(".container.m-t-3").addClass("zweispaltigkeit");
    }
//
    jQuery('#c2769 source').remove();
    jQuery('#c1033 source').remove();
    //
    jQuery("#c2769 .ce-textpic").hover(function () {
        var img = jQuery(this).find("img")[0];
        img.src = (img.src.indexOf("_Normal.png") > -1) ?
                img.src.replace("_Normal.png", "_Hover.png") : img.src.replace("_Hover.png", "_Normal.png");
    });
    //
    jQuery("#c1033 .ce-textpic").hover(function () {
        var img = jQuery(this).find("img")[0];
        img.src = (img.src.indexOf("_Normal.png") > -1) ?
                img.src.replace("_Normal.png", "_Hover.png") : img.src.replace("_Hover.png", "_Normal.png");
    });
    /* --------------------------------------------- products treenav ----- */
    var tdspeed = 200;
    var tdtransition = "linear";
    if ($("html").attr("lang") === "fr") {
        var plabel = 'Choisir le produit';
        var slabel = 'Sélectionnez la sous-catégorie';
        var clabel = 'Choisir une catégorie';
    } else {
        var plabel = 'Select product';
        var slabel = 'Select subcategory';
        var clabel = 'Select category';
    }

    $(document).click(function (event) {
        if (!$(event.target).closest('.tree-dropdown').length) {
            if ($('.tree-dropdown ul').is(":visible")) {
                $('.tree-dropdown ul').hide();
            }
        }
    });
    $(".tree-dropdown li").click(function () {
        $(this).parent().slideToggle(tdspeed, tdtransition);
        $(this).parent().parent().find("label").text($(this).text());
    });
    $(".tree-dropdown.lvl1 label").click(function () {
        $(this).next().slideToggle(tdspeed, tdtransition);
        $(this).text(clabel);
        $(this).parent().removeClass('selected');
        $(".tree-dropdown.lvl2").addClass('disabled').removeClass('enabled');
        $(".tree-dropdown.lvl2 ul").hide();
        $(".tree-dropdown.lvl2 label").text(slabel);
        $(".tree-dropdown.lvl3").addClass('disabled').removeClass('enabled');
        $(".tree-dropdown.lvl3 ul").hide();
        $(".tree-dropdown.lvl3 label").text(plabel);
    });
    $(".tree-dropdown.lvl1 li").click(function () {
        $(this).parent().parent().addClass('selected');
        $(".tree-dropdown.lvl2").removeClass('disabled').removeClass('selected').addClass('enabled');
        $(".tree-dropdown.lvl2 label").text(slabel);
        $(".tree-dropdown.lvl3 label").text(plabel);
        $(".tree-dropdown.lvl3").addClass('disabled').removeClass('enabled');
        id = $(this).attr("id").split("_");
        $(".tree-dropdown.lvl2 li").hide();
        $(".tree-dropdown.lvl2 li.sc_" + id[1]).show();
        $(".tree-dropdown.lvl2 ul").slideToggle(tdspeed, tdtransition);
    });
    $(".tree-dropdown.lvl2 label").click(function () {
        $(this).parent().removeClass('selected');
        if ($(this).text() !== slabel || $(this).parent().hasClass('enabled')) {
            $(this).text(slabel);
            id = $(this).attr("id").split("_");
            if (id[1] > 0) {
                $(".tree-dropdown.lvl2 li").hide();
                $(".tree-dropdown.lvl2 li.sc_" + id[1]).show();
            }
            $(this).next().slideToggle(tdspeed, tdtransition);
            $(".tree-dropdown.lvl3").addClass('disabled').removeClass('enabled');
            $(".tree-dropdown.lvl3 ul").hide();
            $(".tree-dropdown.lvl3 label").text(plabel);
        }
    });
    $(".tree-dropdown.lvl2 li").click(function () {
        $(this).parent().parent().addClass('selected');
        $(".tree-dropdown.lvl3").removeClass('disabled').addClass('enabled');
        id = $(this).attr("id").split("_");
        $(".tree-dropdown.lvl3 li").hide();
        $(".tree-dropdown.lvl3 li.p_" + id[1]).show();
        $(".tree-dropdown.lvl3 ul").slideToggle(tdspeed, tdtransition);
    });
    $(".tree-dropdown.lvl3 label").click(function () {
        if ($(this).text() !== plabel || $(this).parent().hasClass('enabled')) {
            $(this).text(plabel);
            id = $(this).attr("id").split("_");
            if (id[1] > 0) {
                $(".tree-dropdown.lvl3 li").hide();
                $(".tree-dropdown.lvl3 li.p_" + id[1]).show();
            }
            $(this).next().slideToggle(tdspeed, tdtransition);
        }
    });
    var detaildiv = $('#product-single');
    if (detaildiv.length > 0) {
        $('div.lvl1 label').html($('#c_' + detaildiv.attr('data-category')).html());
        $('div.lvl2').removeClass('disabled').addClass('enabled');
        $('div.lvl2 label').html($('#sc_' + detaildiv.attr('data-subcategory')).html());
        $('div.lvl3').removeClass('disabled').addClass('enabled');
        $('div.lvl3 label').html($('#p_' + detaildiv.attr('data-uid') + ' a').html());

        $(".tree-dropdown.lvl2 li").hide();
        $(".tree-dropdown.lvl2 li.sc_" + detaildiv.attr('data-category')).show();
        $(".tree-dropdown.lvl3 li").hide();
        $(".tree-dropdown.lvl3 li.p_" + detaildiv.attr('data-subcategory')).show();
    }
    /* --------------------------------------------- products treenav ENDE ----- */

    /* --------------------------------------------- solutions treenav ----- */
    $('#product-dropdown .dopdown > li').click(function () {
//
        var liste_drinnen = $(this).find('ul');
        $('#product-dropdown .dopdown li ul').not(liste_drinnen).slideUp(tdspeed, tdtransition);
        liste_drinnen.slideToggle(tdspeed, tdtransition);
        //
        var liste_drum = $(this).parent();
        $('#product-dropdown .dopdown').not(liste_drum).removeClass('selected');
        liste_drum.toggleClass('selected');
    });
    $(document).click(function (event) {
        if (!$(event.target).closest('.dopdown').length) {
            if ($('#product-dropdown .dopdown ul').is(":visible")) {
                $('#product-dropdown .dopdown ul').slideUp(tdspeed, tdtransition);
                $('#product-dropdown .dopdown').removeClass('selected');
            }
        }
    });
    /* --------------------------------------------- solutions treenav ENDE ----- */

    /* --------------------------------------------- Set row class in Powermail TS field ----- */
    $(".powermail_fieldwrap_typoscript").addClass("row").addClass("form-group");
    /* --------------------------------------------- downloads----- */
    lgif = '<img src="/fileadmin/img/loader.gif" alt="Loading" class="loader"/>';
    $('#eeProductsearch').click(function (e) {
        e.preventDefault();
        $('#eeProductCategory').val(0);
        $('#eeProductKeyword').val("");
        $('#results').html(lgif).fadeIn('fast');
        $.ajax({
            url: 'https://www.vitec.com/index.php?id=361&p=' + $('#eeProductProduct').val(),
            cache: false
        })
                .done(function (html) {
                    $('#results').fadeOut('fast', function () {
                        $('#results').html(html).fadeIn('fast');
                    });
                });
    });
    $('#eeCategorysearch').click(function (e) {
        e.preventDefault();
        $('#eeProductProduct').val(0);
        $('#eeProductKeyword').val("");
        $('#results').html(lgif).fadeIn('fast');
        $.ajax({
            url: 'https://www.vitec.com/index.php?id=361&dc=' + $('#eeProductCategory').val(),
            cache: false
        })
                .done(function (html) {
                    $('#results').fadeOut('fast', function () {
                        $('#results').html(html).fadeIn('fast');
                    });
                });
    });
    $('#eeKeywordsearch').click(function () {
        $('#eeProductCategory').val(0);
        $('#eeProductProduct').val(0);
        kws();
    }); 
//    $('#eeProductKeyword').keypress(function (e) {
//        e.preventDefault();
//        if (e.which === 13) {
//            kws();
//        }
//    });
    /* --------------------------------------------- downloads ENDE ----- */

//    ------------------------------------------------------------ State nur einblenden, wenn Country USA

//register your product EN & FR
    var state1 = ' #powermail_fieldwrap_112 ';
    $(state1).hide();
    $(' #powermail_field_country ').change(function () {
        if ($(this).val() === 'United States') {
            $(state1).show(100);
        } else {
            $(state1).hide(100);
        }
    });
//register your product EN & FR
    var state2 = ' #powermail_fieldwrap_101 ';
    $(state2).hide();
    $(' #powermail_field_country ').change(function () {
        if ($(this).val() === 'United States') {
            $(state2).show(100);
        } else {
            $(state2).hide(100);
        }
    });

    var state3 = ' #powermail_fieldwrap_78 ';
    $(state3).hide();
    $(' #powermail_field_country ').change(function () {
        if ($(this).val() === 'United States') {
            $(state3).show(100);
        } else {
            $(state3).hide(100);
        }
    });
//    ------------------------------------------------------------ State nur einblenden, wenn Country USA
    $('#hevc').click(function () {
        ga('send', 'event', 'PDF', 'Download', 'HEVC – PDF Whitepaper');
        window.location = 'https://www.vitec.com/fileadmin/downloads/Company_Downloads/Brochures/VITEC_WhitePaper_Gen2_HEVC_Codec.pdf';
    });

    $('#hevc2').click(function () {
        ga('send', 'event', 'PDF', 'Download', 'HEVC – PDF Whitepaper');
        window.location = 'https://www.vitec.com/fileadmin/downloads/Company_Downloads/Brochures/VITEC_WhitePaper_Gen2_HEVC_Codec.pdf';
    });

});

function kws() {
    $('#results').html(lgif).fadeIn('fast');
    $.ajax({
        url: '//www.vitec.com/support/downloads/ajax-helper/?k=' + $('#eeProductKeyword').val(), 
        cache: false
    })
            .done(function (html) {
                $('#results').fadeOut('fast', function () {
                    $('#results').html(html).fadeIn('fast');
                });
            });
}

/* SOCIAL ICONS SIDE BAR ----------------------------- */
jQuery.contactButtons({
    effect: 'slide-on-scroll',
    buttons: {
        'twitter': {class: 'twitter', use: true, link: 'https://twitter.com/Vitec_MM', extras: 'target="_blank"'},
        'linkedin': {class: 'linkedin', use: true, link: 'https://www.linkedin.com/company/65922', extras: 'target="_blank"'},
        'youtube': {class: 'youtube', use: true, link: 'https://www.youtube.com/user/vitecmm', extras: 'target="_blank"'},
        'contact': {class: 'contact separated', use: true, link: ' index.php?id=153 '}
    }
});
