$(document).ready(function() {
    $(".artbasket-post .gallery").find(".navigation .prev, .navigation .next, img").click(function() {
        var gallery = $(this).parents(".gallery");
        var current = gallery.data("current");
        if ($(this).hasClass("prev")) {
            if (--current < 0) {
                current = gallery.data('gallery').length - 1;
            }
        } else if (++current > gallery.data('gallery').length - 1) {
            current = 0;
        }
        
        gallery.find('img').attr('src', gallery.data('gallery')[current][0]);
        gallery.next('.legend').find('.title').html(gallery.data('gallery')[current][1]);
        if (gallery.data('gallery')[current][1]) {
            gallery.next('.legend').find('.num').html('&mdash;');
        } else {
            gallery.next('.legend').find('.num').html('');
        }
        gallery.data('current', current);
    });
    
    $(".words .cut-link").toggle(function() {
        var self = this;
        $(this).prev(".cut").slideDown(300, function(){
            $(self).html('Show&nbsp;less');
        });
        
    }, function() {
        var self = this;
        $(this).prev(".cut").slideUp(300, function(){
           $(self).html('Show&nbsp;more'); 
        });
    });
});
