
/* quicksearch */
$(document).ready(function() {
    $('#quicksearch .inputField').attr('standardValue', $('#quicksearch .inputField').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');
        }
    });
});

/* slideshow */
$(document).ready(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 = 1500;
        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, 6000);
        }
        
        $(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();
        }
        
    });
});

/* shop */
$(document).ready(function() {
    $('.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() {
    $('.shop_overview .articles .item').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);
        });
    });
});
