
/* 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();
        }
        
    });
});

$(document).ready(function() {
    $('.cat_search .keyword').click(function() {
        if ($(this).is(':checked')) {
            $('#keyword_content_' + $(this).attr('value')).css('display', 'block');
        } else {
            $('#keyword_content_' + $(this).attr('value')).css('display', 'none');
        }
    });
});