
/**
 * Validate search form
 */
$(function() {
    $('#headerSearchForm').submit(function() {
        if ('' == $('#headerSearchQuery').val()) {
            alert('Bitte geben Sie einen Suchbegriff ein');
            $('#headerSearchQuery').focus();
            return false;
        }

        return true;
    })
})

/**
 * Sort by filters
 */
$(function() {
    $('#filterOrderBy').change(function() {
        $('#formCategoryFilters').submit();
    })
})

/**
 * Menu filters
 */
$(function() {
    $('.filterColorMask').mouseover(function() {
        $(this).addClass('active');
    }).mouseout(function() {
        color = $(this).attr('id').split('-')[1];
        if (!$('#filterColor-' + color).attr('checked')) {
            $(this).removeClass('active');
        }
    })

    $('.filterColor').click(function() {
        color = $(this).attr('id').split('-')[1];
        if ($(this).attr('checked')) {
            //console.log('#filterColorMask-' + color);
            $('#filterColorMask-' + color).addClass('active');
        } else {
            $('#filterColorMask-' + color).removeClass('active');
        }
    })
})

/**
 * Header menu
 */
$(function() {
    $('.menu').each(function() {
        if ($(this).css('position') == 'absolute') {
            $(this).hide();
        }
    });

    $('.menuHeader').each(function() {
        if ($(this).css('position') == 'absolute') {
            $(this).mouseover(function() {
                $('.menuHeader').each(function() {
                    if ($(this).css('position') == 'absolute') {
                        $(this).removeClass('active');
                    }
                });
                $(this).addClass('active');
                num = $(this).attr('id').split('-')[1];
                $('.menu').each(function() {
                    if ($(this).css('position') == 'absolute') {
                        $(this).hide();
                    }
                });

                $('#menu-' + num + '').show();
                $('#menu-' + num + ' li').show();
            });
        }
    })

    $('.menu').each(function() {
        if ($(this).css('position') == 'absolute') {
            num = $(this).attr('id').split('-')[1];
            $(this).mouseover(function() {
                $(this).show();
                $('.menuHeader').each(function() {
                    if ($(this).css('position') == 'absolute') {
                        $(this).removeClass('active');
                    }
                });
                $('#menuHeader-' + num + '').addClass('active');
            }).mouseout(function() {
                $(this).hide();
                $('#menuHeader-' + num + '').removeClass('active');
            })
        }
    })
})

