﻿$(function() {

    $('#cuttingsContainer').find('.cutting_item').hide();
    $('#cuttingsContainer').find('.cutting_item:first').show();
    //$('.cuttingsPager').find('.prev').hide();
    $('.pagerInfo').find('.imagesCount').html($('#cuttingsContainer').find('.cutting_item').length);
    var currentImage = $('.pagerInfo').find('.currentImage');
    currentImage.html('1');

    $('#cuttingsContainer').show();

    $('.cuttingsPager').find('.next').click(function() {

        var current = $('#cuttingsContainer').find('.cutting_item:visible');
        var next = current.next();

        if (next.length == 0) {
            return false;
        }

        current.fadeOut('fast', function() {
            currentImage.html(parseInt(currentImage.html()) + 1);
            next.fadeIn('fast');
        });

        if (next.next().length == 0)
            $(this).addClass('next_no_hover').removeClass('next_with_hover');
        $('.cuttingsPager').find('.prev').removeClass('prev_no_hover').addClass('prev_with_hover');


        return false;
    });

    $('.cuttingsPager').find('.prev').click(function() {

        var current = $('#cuttingsContainer').find('.cutting_item:visible');
        var prev = current.prev();

        if (prev.length == 0) {
            return false;
        }

        current.fadeOut('fast', function() {
            currentImage.html(parseInt(currentImage.html()) - 1);
            prev.fadeIn('fast');
        });

        if (prev.prev().length == 0)
            $(this).addClass('prev_no_hover').removeClass('prev_with_hover');
        $('.cuttingsPager').find('.next').removeClass('next_no_hover').addClass('next_with_hover');

        return false;
    });

});