
function getLangStr(key, target_lang) {
    if (!key) {return '';}
    if (!target_lang) {target_lang = lang;}
    key = encodeURIComponent(key);
    if (lang_dict[key] && lang_dict[key][target_lang]){
        return decodeURIComponent(lang_dict[key][target_lang]);
    }
    return key;
}

function textLimiter(field, countfield, limit) {
    if (field.val().length > limit) {
        field.val(field.val().substring(0, limit));
    } else {
        countfield.html(limit - field.val().length);
    }
}

$(document).ready(function() {
    $('button').click(function() {
        $(this).val($(this).attr('name'));
    });
});

$(document).ready(function() {
    $('legend input.activator_0').each(function() {
        var fieldset_fields = $(this).parent().parent().parent().find('.fields');
        if ($(this).is(':checked')) {
            $(fieldset_fields).hide();
        }
        $(this).click(function() {
            if ($(this).is(':checked')) {
                $(fieldset_fields).show();
            } else {
                $(fieldset_fields).hide();
            }
        });
        $(this).change(function() {
            if ($(this).is(':checked')) {
                $(fieldset_fields).hide();
            } else {
                if ($(fieldset_fields).css('display') == 'none') {
                    $(fieldset_fields).show();
                }
            }
        });
    });
    $('legend input.activator_1').each(function() {
        var fieldset_fields = $(this).parent().parent().parent().find('.fields');
        if (!$(this).is(':checked')) {
            $(fieldset_fields).hide();
        }
        $(this).click(function() {
            if ($(this).is(':checked')) {
                $(fieldset_fields).show();
            } else {
                $(fieldset_fields).hide();
            }
        });
        $(this).change(function() {
            if ($(this).is(':checked')) {
                if ($(fieldset_fields).css('display') == 'none') {
                    $(fieldset_fields).show();
                }
            } else {
                $(fieldset_fields).hide();
            }
        });
    });
});

$(document).ready(function() {
    galleries = $([]);
    $('.gallery').each(function() {
        context = $(this).metadata().context
        context = context ? context : 'nocontext'
        if ($.inArray(context, galleries) == -1) {
            galleries.push(context);
        }
    });
    $(galleries).each(function() {
        var gallery_name = this;
        var selector = '.gallery.' + gallery_name + ' a';
        $(selector).nyroModal({
            gallery: gallery_name,
            galleryLoop: $(selector).length >= 1 ? true : false,
            galleryLinks: '<a href="#" class="nyroModalPrev" title="' + getLangStr('Previous', lang) + '">' + getLangStr('Previous', lang) + '</a><a href="#"  class="nyroModalNext" title="' + getLangStr('Next', lang) + '">' + getLangStr('Next', lang) + '</a>',
            closeButton: '<a href="#" class="nyroModalClose" id="closeBut" title="' + getLangStr('Close', lang) + '">' + getLangStr('Close', lang) + '</a>'
        });
    });
});

$(function() {
    $.nyroModalSettings({
        processHandler: function(settings) {
            var from = settings.from;
            if (from && from.href && from.href.indexOf('gallery_video.html') >= 0) {
                metadata = $(from).metadata()
                $.nyroModalSettings({
                    width: 720,
                    height: 405
                });
            }
        }
    });
});


$(document).ready(function() {
    $('input, select, textarea, button, .shop_overview .shop_category, .shop_overview .shop_article, .overview .item').mouseenter(function() {
        $(this).addClass('hover');
    });
    $('input, select, textarea, button, .shop_overview .shop_category, .shop_overview .shop_article, .overview .item').mouseleave(function() {
        $(this).removeClass('hover');
    });
    $('input, select, textarea, button').focus(function() {
        $(this).addClass('focus');
    });
    $('input, select, textarea, button').blur(function() {
        $(this).removeClass('focus');
    });
});

/* quicksearch */
$(document).ready(function() {
    $('.form_quicksearch .input_field').each(function() {
        $(this).attr('standardvalue', getLangStr('search_input', lang));
        $(this).focus(function() {
            if ($(this).val() == $(this).attr('standardvalue')) {
                this.value = '';
            }
        });
        $(this).blur(function() {
            if (jQuery.trim($(this).val()) == '') {
                this.value = $(this).attr('standardvalue');
            }
        });
    });
});

$(document).ready(function() {
    $('.playvideo').flowplayer('http://www.aerobicschuhe.com/globalfiles/swf/flowplayer.swf');
});

