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

$(document).ready(function() {
   $('#teaser_shopBasket_content').load(ZMS_ROOT + '/get_teaser_shopBasket_content', 'lang=' + lang);
});

/* quicksearch */
$(document).ready(function() {
    $('#quicksearch .inputField').each(function() {
        $(this).attr('standardValue', $(this).val()); 
    });
    $('#quicksearch .inputField').focus(function() {
        $(this).addClass('hover');
        if ($(this).val() == $(this).attr('standardValue')) {
            this.value = '';
        }
    });
    $('#quicksearch .inputField').blur(function() {
        $(this).removeClass('hover');
        if (jQuery.trim($(this).val()) == '') {
            this.value = $(this).attr('standardValue');
        }
    });
});

$(document).ready(function() {
    if (!(jQuery.browser.msie && jQuery.browser.version == 6)) {
        $('#navigation ul ul ul ul li').append('<span class="overlay"></span>');
        $('#navigation ul ul ul ul li>span.overlay').css('opacity', 0.2);
    }
});

$(document).ready(function() {
    $('.slideshow .navigation a.previous').addClass('inactive');
    $('.slideshow .navigation a.next').addClass('inactive');
});

/* slideshow */
$(window).load(function() {
    $('.slideshow').each(function() {
        var previousLink = $(this).find('.navigation a.previous');
        var nextLink = $(this).find('.navigation a.next');
        var wrapper = $(this).find('.items');
        var wrapper_container = $(wrapper.parent());
        var items = wrapper.children();
        var speed = 1000;
        var wrapper_container_width = wrapper_container.width();
        var items_width = $(items[items.length-1]).position().left + $(items[items.length-1]).width();
        var max_margin_left = items_width - wrapper_container_width;
        var movingForward = true;
        var currentitem = 0;
        checkNavigationLinks();
        
        if (max_margin_left > 0) {
            var auto = setInterval(move, 4000);
        }
        
        $(previousLink).click(function(e) {
            if (!$(this).hasClass('inactive')) {
                try {
                    clearInterval(auto);
                } catch(e) {}
                try {
                    animation.stop();
                } catch(e) {}
                movingForward = false;
                previousItem();
            }
        });
        $(nextLink).click(function(e) {
            if (!$(this).hasClass('inactive')) {
                try {
                    clearInterval(auto);
                } catch(e) {}
                try {
                    animation.stop();
                } catch(e) {}
                movingForward = true;
                nextItem();
            }
        });
        
        function checkNavigationLinks() {
            if ($(items[currentitem]).position().left >= max_margin_left) {
                if (!nextLink.hasClass('inactive')) {
                    nextLink.addClass('inactive');
                }
            } else {
                if (nextLink.hasClass('inactive')) {
                    nextLink.removeClass('inactive');
                }
            }
            if ($(items[currentitem]).position().left == 0) {
                if (!previousLink.hasClass('inactive')) {
                    previousLink.addClass('inactive');
                }
            } else {
                if (previousLink.hasClass('inactive')) {
                    previousLink.removeClass('inactive');
                }
            }
        }
        
        function move() {
            if (movingForward && ($(items[currentitem]).position().left >= max_margin_left)) {
                movingForward = false;
            }
            if (!movingForward && $(items[currentitem]).position().left == 0) {
                movingForward = true;
            }
            if (movingForward) {
                nextItem();
            } else {
                previousItem();
            }
        }
        
        function previousItem() {
            currentitem--;
            animation = wrapper.animate({
                marginLeft: '-' + ($(items[currentitem]).position().left)
            }, speed);
            checkNavigationLinks();
        }
        
        function nextItem() {
            currentitem++;
            var next_margin_left = $(items[currentitem]).position().left;
            if (next_margin_left > max_margin_left) {
                next_margin_left = max_margin_left;
            }
            animation = wrapper.animate({
                marginLeft: '-' + next_margin_left
            }, speed);
            checkNavigationLinks();
        }
        
    });
});

/* buttons */
$(document).ready(function() {
    $('#buttons a').bind('focus mouseenter', function() {
        $(this).children('img.normal').fadeOut(300);
        $(this).children('img.hover').fadeIn(300);
    });
    $('#buttons a').bind('blur mouseleave', function() {
        $(this).children('img.normal').fadeIn(300);
        $(this).children('img.hover').fadeOut(300);
    });
});

/* shop */
$(document).ready(function() {
    if (jQuery.browser.msie && jQuery.browser.version == 6) {
        $('.shop_overview .categories .item').click(function() {
            this.click();
        });
    } else {
        $('.shop_overview .categories .item').each(function() {
            $(this).find('.overlay').css('opacity', 0.3);
            $(this).bind('focus mouseenter', function() {
                $(this).find('.overlay').fadeTo(300, 1);
            });
            $(this).bind('blur mouseleave', function() {
                $(this).find('.overlay').fadeTo(300, 0.3);
            });
        });
    }
});

$(document).ready(function() {
    if (!(jQuery.browser.msie && jQuery.browser.version == 6)) {
        $('.shop_overview .articles .item, .shop_search_article_id .article').each(function() {
            $(this).find('.overlay').css('opacity', 0.5);
            $(this).find('.price.weight').css('opacity', 0.5);
            $(this).find('.article_id').css('opacity', 0.5);
            $(this).find('.short_description').css('opacity', 0.5);
            $(this).find('.more').css('opacity', 0.5);
            $(this).find('form').css('opacity', 0.5);
            $(this).bind('mouseenter', function() {
                $(this).find('.overlay').fadeTo(300, 1);
                $(this).find('.price.weight').fadeTo(300, 1);
                $(this).find('.article_id').fadeTo(300, 1);
                $(this).find('.short_description').fadeTo(300, 1);
                $(this).find('.more').fadeTo(300, 1);
                $(this).find('form').fadeTo(300, 1);
            })
            $(this).bind('mouseleave', function() {
                $(this).find('.overlay').fadeTo(300, 0.5);
                $(this).find('.price.weight').fadeTo(300, 0.5);
                $(this).find('.article_id').fadeTo(300, 0.5);
                $(this).find('.short_description').fadeTo(300, 0.5);
                $(this).find('.more').fadeTo(300, 0.5);
                $(this).find('form').fadeTo(300, 0.5);
            });
        });
    }
});

$(document).ready(function() {
    if ((jQuery.browser.msie && jQuery.browser.version == 7)) {
        return;
    }
    $('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).hide();
            } else {
                $(fieldset_fields).slideDown();
            }
        });
        $(this).change(function() {
            if ($(this).is(':checked')) {
                $(fieldset_fields).hide();
            } else {
                if ($(fieldset_fields).css('display') == 'none') {
                    $(fieldset_fields).slideDown();
                }
            }
        });
    });
    $('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).slideDown();
            } else {
                $(fieldset_fields).hide();
            }
        });
        $(this).change(function() {
            if ($(this).is(':checked')) {
                if ($(fieldset_fields).css('display') == 'none') {
                    $(fieldset_fields).slideDown();
                }
            } else {
                $(fieldset_fields).hide();
            }
        });
    });
});

$(document).ready(function() {
    if ((jQuery.browser.msie && jQuery.browser.version == 7)) {
        return;
    }
    if ($('input.fld_customer_status[value=customer]').is(':checked')) {
        $('.label_customer_id').show();
        $('.label_customer_id_unknown').show();
    } else {
        $('.label_customer_id').hide();
        $('.label_customer_id_unknown').hide();
    }
    if ($('input.fld_customer_id_unknown').is(':checked')) {
        $('.label_customer_id').addClass('disabled');
        $('.fld_customer_id').attr('disabled', 'disabled');
    } else {
        $('.label_customer_id').removeClass('disabled');
        $('.fld_customer_id').removeAttr('disabled');
    }
    
    $('input.fld_customer_status').click(function() {
        if ($(this).val() == 'customer') {
            $('.label_customer_id').show();
            $('.label_customer_id_unknown').show();
        } else {
            $('.label_customer_id').hide();
            $('.label_customer_id_unknown').hide();
        }
    });
    $('input.fld_customer_id_unknown').click(function() {
        if ($(this).is(':checked')) {
            $('.label_customer_id').addClass('disabled');
            $('.fld_customer_id').attr('disabled', 'disabled');
        } else {
            $('.label_customer_id').removeClass('disabled');
            $('.fld_customer_id').removeAttr('disabled');
        }
    });
    
    $('input.fld_customer_status').change(function() {
        if ($(this).val() == 'customer') {
            $('.label_customer_id').show();
            $('.label_customer_id_unknown').show();
        } else {
            $('.label_customer_id').hide();
            $('.label_customer_id_unknown').hide();
        }
    });
    $('input.fld_customer_id_unknown').change(function() {
        if ($(this).is(':checked')) {
            $('.label_customer_id').addClass('disabled');
            $('.fld_customer_id').attr('disabled', 'disabled');
        } else {
            $('.label_customer_id').removeClass('disabled');
            $('.fld_customer_id').removeAttr('disabled');
        }
    });
});

$(document).ready(function() {
    $('.complete_order_link a').click(function() {
        $(this).parent().css('display', 'none');
        $('.complete_order_wait').css('display', 'block');
    });
});

$(document).ready(function() {
    if ($('#form_add_submission').length) {
        if ($('#form_add_submission').hasClass('active')) {
            $('#form_add_submission').show();
        } else {
            $('#form_add_submission').hide();
        }
        
        $('.add_submission_link').click(function() {
            if ($('#form_add_submission').hasClass('active')) {
                $('#form_add_submission').removeClass('active');
                (jQuery.browser.msie && jQuery.browser.version == 7) ? $('#form_add_submission').hide() : $('#form_add_submission').slideUp();
            } else {
                $('#form_add_submission').addClass('active');
                (jQuery.browser.msie && jQuery.browser.version == 7) ? $('#form_add_submission').show() : $('#form_add_submission').slideDown();
            }
            return false;
        });
    }
});

$(document).ready(function() {
    if ($('#form_vote').hasClass('active')) {
        $('#form_vote').show();
    } else {
        $('#form_vote').hide();
    }
    
    $('.vote_link').click(function() {
        if ($('#form_vote').hasClass('active')) {
            $('#form_vote').removeClass('active');
            (jQuery.browser.msie && jQuery.browser.version == 7) ? $('#form_vote').hide() : $('#form_vote').slideUp();
        } else {
            $('#form_vote').addClass('active');
            (jQuery.browser.msie && jQuery.browser.version == 7) ? $('#form_vote').show() : $('#form_vote').slideDown();
        }
        return false;
    });
});

$(document).ready(function() {
    $('.submissions .item a.photo, .submissions a.item').tooltip({
        delay: 0,
        fade: 250,
        track: true,
        showURL: false,
        extraClass: 'submission',
        bodyHandler: function() { 
            my_content = $($(this).attr('rel') + ' .tooltipcontent');
            my_photo = $($(this).attr('rel') + ' .tooltipphoto');
            return my_content.html() + '<div class="photo"><img src="' + my_photo.attr('href') + '" alt="" /></div>';
        }
    });
});

$(document).ready(function() {
    $('.winners .item').tooltip({
        delay: 0,
        fade: 250,
        track: true,
        showURL: false,
        extraClass: 'winner',
        bodyHandler: function() { 
            my_content = $($(this).attr('rel') + ' .tooltipcontent');
            my_photo = $($(this).attr('rel') + ' .tooltipphoto');
            return '<div class="' + $(this).attr('class') + '">' + my_content.html() + '<div class="photo"><img src="' + my_photo.attr('href') + '" alt="" /></div></div>';
        }
    });
    $('.winners a.item').lightBox({
        imageLoading:           'img/jquery.lightbox-0.5/lightbox-ico-loading.gif',
        imageBtnPrev:           'img/jquery.lightbox-0.5/lightbox-btn-prev.gif',
        imageBtnNext:           'img/jquery.lightbox-0.5/lightbox-btn-next.gif',
        imageBtnClose:          'img/jquery.lightbox-0.5/lightbox-btn-close.gif',
        imageBlank:             'img/jquery.lightbox-0.5/lightbox-blank.gif',
        txtImage:               lang == 'ger' ? 'Bild' : 'Image',
        txtOf:                  lang == 'ger' ? 'von' : 'de'
    });
});

$(document).ready(function() {
    $('.locationimages .images a.item').tooltip({
        delay: 0,
        fade: 250,
        track: true,
        showURL: false,
        extraClass: 'locationimage',
        bodyHandler: function() {
            my_photo = $($(this).attr('rel') + ' .tooltipphoto');
            return '<img src="' + my_photo.attr('href') + '" alt="" />';
        }
    });
    $('.locationimages .images a.item').lightBox({
        imageLoading:           'img/jquery.lightbox-0.5/lightbox-ico-loading.gif',
        imageBtnPrev:           'img/jquery.lightbox-0.5/lightbox-btn-prev.gif',
        imageBtnNext:           'img/jquery.lightbox-0.5/lightbox-btn-next.gif',
        imageBtnClose:          'img/jquery.lightbox-0.5/lightbox-btn-close.gif',
        imageBlank:             'img/jquery.lightbox-0.5/lightbox-blank.gif',
        txtImage:               lang == 'ger' ? 'Bild' : 'Image',
        txtOf:                  lang == 'ger' ? 'von' : 'de'
    });
});

$(document).ready(function() {
    $('.overview_map .help_link').click(function() {
        if ($('.overview_map .help').css('display') == 'block') {
            $('.overview_map .help_link').html(getLangStr('show_help', lang));
            $('.overview_map .help').css('display', 'none');
        } else {
            $('.overview_map .help').css('display', 'block');
            $('.overview_map .help_link').html(getLangStr('hide_help', lang));
        }
        return false;
    });
});

$(document).ready(function() {
    $.fn.qtip.styles.blank = {
        border: {
            width: 0
        },
        padding: '5px',
        background: '#fff',
        color: '#000',
        textAlign: 'left',
        title: false
    };
});

$(document).ready(function() {
    $('form .fieldinfo').each(function() {
        $(this).qtip({
            content: {
                prerender: true,
                text: $($(this).attr('rel') + ' .tooltipcontent').html(),
                title: {
                    text: $($(this).attr('rel') + ' .tooltiptitle').html(),
                    button: 'x'
                }
            },
            position: {
                adjust: {
                    screen: true
                }
            },
            hide: {
                fixed: true,
                when: {
                    event: 'click'
                }
            },
            show: {
                solo: true,
                delay: 0,
                when: {
                    event: 'click'
                }
            },
            style: {
                name: 'blank',
                width: {
                    min: 400
                },
                classes: {
                    tooltip: 'fieldinfo'
                }
            }
        });
        
        $(this).click(function() {
            return false;
        });
    });
});

$(document).ready(function() {
    if ($('select.fld_Breed').val() == 'Other Breed') {
        $('.label_Other_Breed').css('visibility', 'visible');
    } else {
        $('.label_Other_Breed').css('visibility', 'hidden');
    }
    
    $('select.fld_Breed').change(function() {
        if ($(this).val() == 'Other Breed') {
            $('.label_Other_Breed').css('visibility', 'visible');
        } else {
            $('.label_Other_Breed').css('visibility', 'hidden');
        }
    });
    
    $('.fld_ExistingDisease[value=Yes]').change(function() {
        if ($(this).is(':checked')) {
            $('.fieldinfo_ExistingDisease').qtip('show');
        }
    });
});